@shunt-network/sdk 1.0.0

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 (96) hide show
  1. package/dist/clients/typescript/src/__tests__/instruction-parsers.test.d.ts +1 -0
  2. package/dist/clients/typescript/src/__tests__/voucher-numeric-safety.test.d.ts +1 -0
  3. package/dist/clients/typescript/src/__tests__/voucher-types.test-d.d.ts +1 -0
  4. package/dist/clients/typescript/src/generated/accounts/channel.d.ts +59 -0
  5. package/dist/clients/typescript/src/generated/accounts/index.d.ts +8 -0
  6. package/dist/clients/typescript/src/generated/errors/index.d.ts +8 -0
  7. package/dist/clients/typescript/src/generated/errors/paymentChannels.d.ts +84 -0
  8. package/dist/clients/typescript/src/generated/index.d.ts +13 -0
  9. package/dist/clients/typescript/src/generated/instructions/distribute.d.ts +90 -0
  10. package/dist/clients/typescript/src/generated/instructions/emitEvent.d.ts +42 -0
  11. package/dist/clients/typescript/src/generated/instructions/index.d.ts +17 -0
  12. package/dist/clients/typescript/src/generated/instructions/open.d.ts +100 -0
  13. package/dist/clients/typescript/src/generated/instructions/reclaim.d.ts +39 -0
  14. package/dist/clients/typescript/src/generated/instructions/requestClose.d.ts +39 -0
  15. package/dist/clients/typescript/src/generated/instructions/seal.d.ts +36 -0
  16. package/dist/clients/typescript/src/generated/instructions/settle.d.ts +39 -0
  17. package/dist/clients/typescript/src/generated/instructions/settleAndSeal.d.ts +47 -0
  18. package/dist/clients/typescript/src/generated/instructions/topUp.d.ts +56 -0
  19. package/dist/clients/typescript/src/generated/instructions/withdrawPayer.d.ts +51 -0
  20. package/dist/clients/typescript/src/generated/pdas/eventAuthority.d.ts +11 -0
  21. package/dist/clients/typescript/src/generated/pdas/index.d.ts +8 -0
  22. package/dist/clients/typescript/src/generated/programs/index.d.ts +8 -0
  23. package/dist/clients/typescript/src/generated/programs/paymentChannels.d.ts +80 -0
  24. package/dist/clients/typescript/src/generated/types/accountDiscriminator.d.ts +16 -0
  25. package/dist/clients/typescript/src/generated/types/channelStatus.d.ts +18 -0
  26. package/dist/clients/typescript/src/generated/types/distributeArgs.d.ts +18 -0
  27. package/dist/clients/typescript/src/generated/types/distributionEntry.d.ts +16 -0
  28. package/dist/clients/typescript/src/generated/types/index.d.ts +20 -0
  29. package/dist/clients/typescript/src/generated/types/openArgs.d.ts +26 -0
  30. package/dist/clients/typescript/src/generated/types/opened.d.ts +19 -0
  31. package/dist/clients/typescript/src/generated/types/payoutBeneficiary.d.ts +17 -0
  32. package/dist/clients/typescript/src/generated/types/payoutRedirected.d.ts +26 -0
  33. package/dist/clients/typescript/src/generated/types/redirectReason.d.ts +18 -0
  34. package/dist/clients/typescript/src/generated/types/settleAndSealArgs.d.ts +15 -0
  35. package/dist/clients/typescript/src/generated/types/settlementWatermarks.d.ts +19 -0
  36. package/dist/clients/typescript/src/generated/types/topUpArgs.d.ts +17 -0
  37. package/dist/clients/typescript/src/generated/types/voucherArgs.d.ts +23 -0
  38. package/dist/clients/typescript/src/index.d.ts +1 -0
  39. package/dist/clients/typescript/src/safe-codecs.d.ts +6 -0
  40. package/dist/clients/typescript/tsup.config.d.ts +2 -0
  41. package/dist/index.cjs +1399 -0
  42. package/dist/index.d.ts +4 -0
  43. package/dist/index.js +1549 -0
  44. package/dist/sdk/channel.d.ts +10 -0
  45. package/dist/sdk/client.d.ts +31 -0
  46. package/dist/sdk/utils.d.ts +3 -0
  47. package/dist/sdk/voucher.d.ts +14 -0
  48. package/package.json +36 -0
  49. package/src/clients/typescript/package.json +32 -0
  50. package/src/clients/typescript/src/__tests__/instruction-parsers.test.ts +81 -0
  51. package/src/clients/typescript/src/__tests__/voucher-numeric-safety.test.ts +176 -0
  52. package/src/clients/typescript/src/__tests__/voucher-types.test-d.ts +8 -0
  53. package/src/clients/typescript/src/generated/accounts/channel.ts +192 -0
  54. package/src/clients/typescript/src/generated/accounts/index.ts +9 -0
  55. package/src/clients/typescript/src/generated/errors/index.ts +9 -0
  56. package/src/clients/typescript/src/generated/errors/paymentChannels.ts +251 -0
  57. package/src/clients/typescript/src/generated/index.ts +14 -0
  58. package/src/clients/typescript/src/generated/instructions/distribute.ts +517 -0
  59. package/src/clients/typescript/src/generated/instructions/emitEvent.ts +194 -0
  60. package/src/clients/typescript/src/generated/instructions/index.ts +18 -0
  61. package/src/clients/typescript/src/generated/instructions/open.ts +577 -0
  62. package/src/clients/typescript/src/generated/instructions/reclaim.ts +165 -0
  63. package/src/clients/typescript/src/generated/instructions/requestClose.ts +173 -0
  64. package/src/clients/typescript/src/generated/instructions/seal.ts +151 -0
  65. package/src/clients/typescript/src/generated/instructions/settle.ts +180 -0
  66. package/src/clients/typescript/src/generated/instructions/settleAndSeal.ts +224 -0
  67. package/src/clients/typescript/src/generated/instructions/topUp.ts +267 -0
  68. package/src/clients/typescript/src/generated/instructions/withdrawPayer.ts +246 -0
  69. package/src/clients/typescript/src/generated/pdas/eventAuthority.ts +26 -0
  70. package/src/clients/typescript/src/generated/pdas/index.ts +9 -0
  71. package/src/clients/typescript/src/generated/programs/index.ts +9 -0
  72. package/src/clients/typescript/src/generated/programs/paymentChannels.ts +366 -0
  73. package/src/clients/typescript/src/generated/types/accountDiscriminator.ts +41 -0
  74. package/src/clients/typescript/src/generated/types/channelStatus.ts +40 -0
  75. package/src/clients/typescript/src/generated/types/distributeArgs.ts +47 -0
  76. package/src/clients/typescript/src/generated/types/distributionEntry.ts +48 -0
  77. package/src/clients/typescript/src/generated/types/index.ts +21 -0
  78. package/src/clients/typescript/src/generated/types/openArgs.ts +70 -0
  79. package/src/clients/typescript/src/generated/types/opened.ts +42 -0
  80. package/src/clients/typescript/src/generated/types/payoutBeneficiary.ts +42 -0
  81. package/src/clients/typescript/src/generated/types/payoutRedirected.ts +76 -0
  82. package/src/clients/typescript/src/generated/types/redirectReason.ts +40 -0
  83. package/src/clients/typescript/src/generated/types/settleAndSealArgs.ts +39 -0
  84. package/src/clients/typescript/src/generated/types/settlementWatermarks.ts +48 -0
  85. package/src/clients/typescript/src/generated/types/topUpArgs.ts +33 -0
  86. package/src/clients/typescript/src/generated/types/voucherArgs.ts +68 -0
  87. package/src/clients/typescript/src/index.ts +1 -0
  88. package/src/clients/typescript/src/safe-codecs.ts +82 -0
  89. package/src/clients/typescript/tsconfig.json +11 -0
  90. package/src/clients/typescript/tsup.config.ts +9 -0
  91. package/src/index.ts +4 -0
  92. package/src/sdk/channel.ts +128 -0
  93. package/src/sdk/client.ts +22 -0
  94. package/src/sdk/utils.ts +29 -0
  95. package/src/sdk/voucher.ts +50 -0
  96. package/tsconfig.json +15 -0
@@ -0,0 +1,224 @@
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 {
10
+ combineCodec,
11
+ getStructDecoder,
12
+ getStructEncoder,
13
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
14
+ SolanaError,
15
+ transformEncoder,
16
+ type AccountMeta,
17
+ type AccountSignerMeta,
18
+ type Address,
19
+ type FixedSizeCodec,
20
+ type FixedSizeDecoder,
21
+ type FixedSizeEncoder,
22
+ type Instruction,
23
+ type InstructionWithAccounts,
24
+ type InstructionWithData,
25
+ type ReadonlyAccount,
26
+ type ReadonlySignerAccount,
27
+ type ReadonlyUint8Array,
28
+ type TransactionSigner,
29
+ type WritableAccount,
30
+ } from "@solana/kit";
31
+ import {
32
+ getAccountMetaFactory,
33
+ type ResolvedInstructionAccount,
34
+ } from "@solana/program-client-core";
35
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
36
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
37
+ import {
38
+ getSettleAndSealArgsDecoder,
39
+ getSettleAndSealArgsEncoder,
40
+ type SettleAndSealArgs,
41
+ type SettleAndSealArgsArgs,
42
+ } from "../types";
43
+
44
+ export const SETTLE_AND_SEAL_DISCRIMINATOR = 4;
45
+
46
+ export function getSettleAndSealDiscriminatorBytes(): ReadonlyUint8Array {
47
+ return getU8Encoder().encode(SETTLE_AND_SEAL_DISCRIMINATOR);
48
+ }
49
+
50
+ export type SettleAndSealInstruction<
51
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
52
+ TAccountPayee extends string | AccountMeta<string> = string,
53
+ TAccountChannel extends string | AccountMeta<string> = string,
54
+ TAccountInstructionsSysvar extends string | AccountMeta<string> = string,
55
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
56
+ > = Instruction<TProgram> &
57
+ InstructionWithData<ReadonlyUint8Array> &
58
+ InstructionWithAccounts<
59
+ [
60
+ TAccountPayee extends string
61
+ ? ReadonlySignerAccount<TAccountPayee> &
62
+ AccountSignerMeta<TAccountPayee>
63
+ : TAccountPayee,
64
+ TAccountChannel extends string
65
+ ? WritableAccount<TAccountChannel>
66
+ : TAccountChannel,
67
+ TAccountInstructionsSysvar extends string
68
+ ? ReadonlyAccount<TAccountInstructionsSysvar>
69
+ : TAccountInstructionsSysvar,
70
+ ...TRemainingAccounts,
71
+ ]
72
+ >;
73
+
74
+ export type SettleAndSealInstructionData = {
75
+ discriminator: number;
76
+ settleAndSealArgs: SettleAndSealArgs;
77
+ };
78
+
79
+ export type SettleAndSealInstructionDataArgs = {
80
+ settleAndSealArgs: SettleAndSealArgsArgs;
81
+ };
82
+
83
+ export function getSettleAndSealInstructionDataEncoder(): FixedSizeEncoder<SettleAndSealInstructionDataArgs> {
84
+ return transformEncoder(
85
+ getStructEncoder([
86
+ ["discriminator", getU8Encoder()],
87
+ ["settleAndSealArgs", getSettleAndSealArgsEncoder()],
88
+ ]),
89
+ (value) => ({ ...value, discriminator: SETTLE_AND_SEAL_DISCRIMINATOR }),
90
+ );
91
+ }
92
+
93
+ export function getSettleAndSealInstructionDataDecoder(): FixedSizeDecoder<SettleAndSealInstructionData> {
94
+ return getStructDecoder([
95
+ ["discriminator", getU8Decoder()],
96
+ ["settleAndSealArgs", getSettleAndSealArgsDecoder()],
97
+ ]);
98
+ }
99
+
100
+ export function getSettleAndSealInstructionDataCodec(): FixedSizeCodec<
101
+ SettleAndSealInstructionDataArgs,
102
+ SettleAndSealInstructionData
103
+ > {
104
+ return combineCodec(
105
+ getSettleAndSealInstructionDataEncoder(),
106
+ getSettleAndSealInstructionDataDecoder(),
107
+ );
108
+ }
109
+
110
+ export type SettleAndSealInput<
111
+ TAccountPayee extends string = string,
112
+ TAccountChannel extends string = string,
113
+ TAccountInstructionsSysvar extends string = string,
114
+ > = {
115
+ payee: TransactionSigner<TAccountPayee>;
116
+ channel: Address<TAccountChannel>;
117
+ instructionsSysvar: Address<TAccountInstructionsSysvar>;
118
+ settleAndSealArgs: SettleAndSealInstructionDataArgs["settleAndSealArgs"];
119
+ };
120
+
121
+ export function getSettleAndSealInstruction<
122
+ TAccountPayee extends string,
123
+ TAccountChannel extends string,
124
+ TAccountInstructionsSysvar extends string,
125
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
126
+ >(
127
+ input: SettleAndSealInput<
128
+ TAccountPayee,
129
+ TAccountChannel,
130
+ TAccountInstructionsSysvar
131
+ >,
132
+ config?: { programAddress?: TProgramAddress },
133
+ ): SettleAndSealInstruction<
134
+ TProgramAddress,
135
+ TAccountPayee,
136
+ TAccountChannel,
137
+ TAccountInstructionsSysvar
138
+ > {
139
+ // Program address.
140
+ const programAddress =
141
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
142
+
143
+ // Original accounts.
144
+ const originalAccounts = {
145
+ payee: { value: input.payee ?? null, isWritable: false },
146
+ channel: { value: input.channel ?? null, isWritable: true },
147
+ instructionsSysvar: {
148
+ value: input.instructionsSysvar ?? null,
149
+ isWritable: false,
150
+ },
151
+ };
152
+ const accounts = originalAccounts as Record<
153
+ keyof typeof originalAccounts,
154
+ ResolvedInstructionAccount
155
+ >;
156
+
157
+ // Original args.
158
+ const args = { ...input };
159
+
160
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
161
+ return Object.freeze({
162
+ accounts: [
163
+ getAccountMeta("payee", accounts.payee),
164
+ getAccountMeta("channel", accounts.channel),
165
+ getAccountMeta("instructionsSysvar", accounts.instructionsSysvar),
166
+ ],
167
+ data: getSettleAndSealInstructionDataEncoder().encode(
168
+ args as SettleAndSealInstructionDataArgs,
169
+ ),
170
+ programAddress,
171
+ } as SettleAndSealInstruction<
172
+ TProgramAddress,
173
+ TAccountPayee,
174
+ TAccountChannel,
175
+ TAccountInstructionsSysvar
176
+ >);
177
+ }
178
+
179
+ export type ParsedSettleAndSealInstruction<
180
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
181
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
182
+ > = {
183
+ programAddress: Address<TProgram>;
184
+ accounts: {
185
+ payee: TAccountMetas[0];
186
+ channel: TAccountMetas[1];
187
+ instructionsSysvar: TAccountMetas[2];
188
+ };
189
+ data: SettleAndSealInstructionData;
190
+ };
191
+
192
+ export function parseSettleAndSealInstruction<
193
+ TProgram extends string,
194
+ TAccountMetas extends readonly AccountMeta[],
195
+ >(
196
+ instruction: Instruction<TProgram> &
197
+ InstructionWithAccounts<TAccountMetas> &
198
+ InstructionWithData<ReadonlyUint8Array>,
199
+ ): ParsedSettleAndSealInstruction<TProgram, TAccountMetas> {
200
+ if (instruction.accounts.length !== 3) {
201
+ throw new SolanaError(
202
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
203
+ {
204
+ actualAccountMetas: instruction.accounts.length,
205
+ expectedAccountMetas: 3,
206
+ },
207
+ );
208
+ }
209
+ let accountIndex = 0;
210
+ const getNextAccount = () => {
211
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
212
+ accountIndex += 1;
213
+ return accountMeta;
214
+ };
215
+ return {
216
+ programAddress: instruction.programAddress,
217
+ accounts: {
218
+ payee: getNextAccount(),
219
+ channel: getNextAccount(),
220
+ instructionsSysvar: getNextAccount(),
221
+ },
222
+ data: getSettleAndSealInstructionDataDecoder().decode(instruction.data),
223
+ };
224
+ }
@@ -0,0 +1,267 @@
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 {
10
+ combineCodec,
11
+ getStructDecoder,
12
+ getStructEncoder,
13
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
14
+ SolanaError,
15
+ transformEncoder,
16
+ type AccountMeta,
17
+ type AccountSignerMeta,
18
+ type Address,
19
+ type FixedSizeCodec,
20
+ type FixedSizeDecoder,
21
+ type FixedSizeEncoder,
22
+ type Instruction,
23
+ type InstructionWithAccounts,
24
+ type InstructionWithData,
25
+ type ReadonlyAccount,
26
+ type ReadonlyUint8Array,
27
+ type TransactionSigner,
28
+ type WritableAccount,
29
+ type WritableSignerAccount,
30
+ } from "@solana/kit";
31
+ import {
32
+ getAccountMetaFactory,
33
+ type ResolvedInstructionAccount,
34
+ } from "@solana/program-client-core";
35
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
36
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
37
+ import {
38
+ getTopUpArgsDecoder,
39
+ getTopUpArgsEncoder,
40
+ type TopUpArgs,
41
+ type TopUpArgsArgs,
42
+ } from "../types";
43
+
44
+ export const TOP_UP_DISCRIMINATOR = 3;
45
+
46
+ export function getTopUpDiscriminatorBytes(): ReadonlyUint8Array {
47
+ return getU8Encoder().encode(TOP_UP_DISCRIMINATOR);
48
+ }
49
+
50
+ export type TopUpInstruction<
51
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
52
+ TAccountPayer extends string | AccountMeta<string> = string,
53
+ TAccountChannel extends string | AccountMeta<string> = string,
54
+ TAccountPayerTokenAccount extends string | AccountMeta<string> = string,
55
+ TAccountChannelTokenAccount extends string | AccountMeta<string> = string,
56
+ TAccountMint extends string | AccountMeta<string> = string,
57
+ TAccountTokenProgram extends string | AccountMeta<string> = string,
58
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
59
+ > = Instruction<TProgram> &
60
+ InstructionWithData<ReadonlyUint8Array> &
61
+ InstructionWithAccounts<
62
+ [
63
+ TAccountPayer extends string
64
+ ? WritableSignerAccount<TAccountPayer> &
65
+ AccountSignerMeta<TAccountPayer>
66
+ : TAccountPayer,
67
+ TAccountChannel extends string
68
+ ? WritableAccount<TAccountChannel>
69
+ : TAccountChannel,
70
+ TAccountPayerTokenAccount extends string
71
+ ? WritableAccount<TAccountPayerTokenAccount>
72
+ : TAccountPayerTokenAccount,
73
+ TAccountChannelTokenAccount extends string
74
+ ? WritableAccount<TAccountChannelTokenAccount>
75
+ : TAccountChannelTokenAccount,
76
+ TAccountMint extends string
77
+ ? ReadonlyAccount<TAccountMint>
78
+ : TAccountMint,
79
+ TAccountTokenProgram extends string
80
+ ? ReadonlyAccount<TAccountTokenProgram>
81
+ : TAccountTokenProgram,
82
+ ...TRemainingAccounts,
83
+ ]
84
+ >;
85
+
86
+ export type TopUpInstructionData = {
87
+ discriminator: number;
88
+ topUpArgs: TopUpArgs;
89
+ };
90
+
91
+ export type TopUpInstructionDataArgs = { topUpArgs: TopUpArgsArgs };
92
+
93
+ export function getTopUpInstructionDataEncoder(): FixedSizeEncoder<TopUpInstructionDataArgs> {
94
+ return transformEncoder(
95
+ getStructEncoder([
96
+ ["discriminator", getU8Encoder()],
97
+ ["topUpArgs", getTopUpArgsEncoder()],
98
+ ]),
99
+ (value) => ({ ...value, discriminator: TOP_UP_DISCRIMINATOR }),
100
+ );
101
+ }
102
+
103
+ export function getTopUpInstructionDataDecoder(): FixedSizeDecoder<TopUpInstructionData> {
104
+ return getStructDecoder([
105
+ ["discriminator", getU8Decoder()],
106
+ ["topUpArgs", getTopUpArgsDecoder()],
107
+ ]);
108
+ }
109
+
110
+ export function getTopUpInstructionDataCodec(): FixedSizeCodec<
111
+ TopUpInstructionDataArgs,
112
+ TopUpInstructionData
113
+ > {
114
+ return combineCodec(
115
+ getTopUpInstructionDataEncoder(),
116
+ getTopUpInstructionDataDecoder(),
117
+ );
118
+ }
119
+
120
+ export type TopUpInput<
121
+ TAccountPayer extends string = string,
122
+ TAccountChannel extends string = string,
123
+ TAccountPayerTokenAccount extends string = string,
124
+ TAccountChannelTokenAccount extends string = string,
125
+ TAccountMint extends string = string,
126
+ TAccountTokenProgram extends string = string,
127
+ > = {
128
+ payer: TransactionSigner<TAccountPayer>;
129
+ channel: Address<TAccountChannel>;
130
+ payerTokenAccount: Address<TAccountPayerTokenAccount>;
131
+ channelTokenAccount: Address<TAccountChannelTokenAccount>;
132
+ mint: Address<TAccountMint>;
133
+ tokenProgram: Address<TAccountTokenProgram>;
134
+ topUpArgs: TopUpInstructionDataArgs["topUpArgs"];
135
+ };
136
+
137
+ export function getTopUpInstruction<
138
+ TAccountPayer extends string,
139
+ TAccountChannel extends string,
140
+ TAccountPayerTokenAccount extends string,
141
+ TAccountChannelTokenAccount extends string,
142
+ TAccountMint extends string,
143
+ TAccountTokenProgram extends string,
144
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
145
+ >(
146
+ input: TopUpInput<
147
+ TAccountPayer,
148
+ TAccountChannel,
149
+ TAccountPayerTokenAccount,
150
+ TAccountChannelTokenAccount,
151
+ TAccountMint,
152
+ TAccountTokenProgram
153
+ >,
154
+ config?: { programAddress?: TProgramAddress },
155
+ ): TopUpInstruction<
156
+ TProgramAddress,
157
+ TAccountPayer,
158
+ TAccountChannel,
159
+ TAccountPayerTokenAccount,
160
+ TAccountChannelTokenAccount,
161
+ TAccountMint,
162
+ TAccountTokenProgram
163
+ > {
164
+ // Program address.
165
+ const programAddress =
166
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
167
+
168
+ // Original accounts.
169
+ const originalAccounts = {
170
+ payer: { value: input.payer ?? null, isWritable: true },
171
+ channel: { value: input.channel ?? null, isWritable: true },
172
+ payerTokenAccount: {
173
+ value: input.payerTokenAccount ?? null,
174
+ isWritable: true,
175
+ },
176
+ channelTokenAccount: {
177
+ value: input.channelTokenAccount ?? null,
178
+ isWritable: true,
179
+ },
180
+ mint: { value: input.mint ?? null, isWritable: false },
181
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
182
+ };
183
+ const accounts = originalAccounts as Record<
184
+ keyof typeof originalAccounts,
185
+ ResolvedInstructionAccount
186
+ >;
187
+
188
+ // Original args.
189
+ const args = { ...input };
190
+
191
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
192
+ return Object.freeze({
193
+ accounts: [
194
+ getAccountMeta("payer", accounts.payer),
195
+ getAccountMeta("channel", accounts.channel),
196
+ getAccountMeta("payerTokenAccount", accounts.payerTokenAccount),
197
+ getAccountMeta("channelTokenAccount", accounts.channelTokenAccount),
198
+ getAccountMeta("mint", accounts.mint),
199
+ getAccountMeta("tokenProgram", accounts.tokenProgram),
200
+ ],
201
+ data: getTopUpInstructionDataEncoder().encode(
202
+ args as TopUpInstructionDataArgs,
203
+ ),
204
+ programAddress,
205
+ } as TopUpInstruction<
206
+ TProgramAddress,
207
+ TAccountPayer,
208
+ TAccountChannel,
209
+ TAccountPayerTokenAccount,
210
+ TAccountChannelTokenAccount,
211
+ TAccountMint,
212
+ TAccountTokenProgram
213
+ >);
214
+ }
215
+
216
+ export type ParsedTopUpInstruction<
217
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
218
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
219
+ > = {
220
+ programAddress: Address<TProgram>;
221
+ accounts: {
222
+ payer: TAccountMetas[0];
223
+ channel: TAccountMetas[1];
224
+ payerTokenAccount: TAccountMetas[2];
225
+ channelTokenAccount: TAccountMetas[3];
226
+ mint: TAccountMetas[4];
227
+ tokenProgram: TAccountMetas[5];
228
+ };
229
+ data: TopUpInstructionData;
230
+ };
231
+
232
+ export function parseTopUpInstruction<
233
+ TProgram extends string,
234
+ TAccountMetas extends readonly AccountMeta[],
235
+ >(
236
+ instruction: Instruction<TProgram> &
237
+ InstructionWithAccounts<TAccountMetas> &
238
+ InstructionWithData<ReadonlyUint8Array>,
239
+ ): ParsedTopUpInstruction<TProgram, TAccountMetas> {
240
+ if (instruction.accounts.length !== 6) {
241
+ throw new SolanaError(
242
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
243
+ {
244
+ actualAccountMetas: instruction.accounts.length,
245
+ expectedAccountMetas: 6,
246
+ },
247
+ );
248
+ }
249
+ let accountIndex = 0;
250
+ const getNextAccount = () => {
251
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
252
+ accountIndex += 1;
253
+ return accountMeta;
254
+ };
255
+ return {
256
+ programAddress: instruction.programAddress,
257
+ accounts: {
258
+ payer: getNextAccount(),
259
+ channel: getNextAccount(),
260
+ payerTokenAccount: getNextAccount(),
261
+ channelTokenAccount: getNextAccount(),
262
+ mint: getNextAccount(),
263
+ tokenProgram: getNextAccount(),
264
+ },
265
+ data: getTopUpInstructionDataDecoder().decode(instruction.data),
266
+ };
267
+ }