@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,246 @@
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
+
38
+ export const WITHDRAW_PAYER_DISCRIMINATOR = 8;
39
+
40
+ export function getWithdrawPayerDiscriminatorBytes(): ReadonlyUint8Array {
41
+ return getU8Encoder().encode(WITHDRAW_PAYER_DISCRIMINATOR);
42
+ }
43
+
44
+ export type WithdrawPayerInstruction<
45
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
46
+ TAccountPayer extends string | AccountMeta<string> = string,
47
+ TAccountChannel extends string | AccountMeta<string> = string,
48
+ TAccountChannelTokenAccount extends string | AccountMeta<string> = string,
49
+ TAccountPayerTokenAccount extends string | AccountMeta<string> = string,
50
+ TAccountMint extends string | AccountMeta<string> = string,
51
+ TAccountTokenProgram extends string | AccountMeta<string> = string,
52
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
53
+ > = Instruction<TProgram> &
54
+ InstructionWithData<ReadonlyUint8Array> &
55
+ InstructionWithAccounts<
56
+ [
57
+ TAccountPayer extends string
58
+ ? ReadonlySignerAccount<TAccountPayer> &
59
+ AccountSignerMeta<TAccountPayer>
60
+ : TAccountPayer,
61
+ TAccountChannel extends string
62
+ ? WritableAccount<TAccountChannel>
63
+ : TAccountChannel,
64
+ TAccountChannelTokenAccount extends string
65
+ ? WritableAccount<TAccountChannelTokenAccount>
66
+ : TAccountChannelTokenAccount,
67
+ TAccountPayerTokenAccount extends string
68
+ ? WritableAccount<TAccountPayerTokenAccount>
69
+ : TAccountPayerTokenAccount,
70
+ TAccountMint extends string
71
+ ? ReadonlyAccount<TAccountMint>
72
+ : TAccountMint,
73
+ TAccountTokenProgram extends string
74
+ ? ReadonlyAccount<TAccountTokenProgram>
75
+ : TAccountTokenProgram,
76
+ ...TRemainingAccounts,
77
+ ]
78
+ >;
79
+
80
+ export type WithdrawPayerInstructionData = { discriminator: number };
81
+
82
+ export type WithdrawPayerInstructionDataArgs = {};
83
+
84
+ export function getWithdrawPayerInstructionDataEncoder(): FixedSizeEncoder<WithdrawPayerInstructionDataArgs> {
85
+ return transformEncoder(
86
+ getStructEncoder([["discriminator", getU8Encoder()]]),
87
+ (value) => ({ ...value, discriminator: WITHDRAW_PAYER_DISCRIMINATOR }),
88
+ );
89
+ }
90
+
91
+ export function getWithdrawPayerInstructionDataDecoder(): FixedSizeDecoder<WithdrawPayerInstructionData> {
92
+ return getStructDecoder([["discriminator", getU8Decoder()]]);
93
+ }
94
+
95
+ export function getWithdrawPayerInstructionDataCodec(): FixedSizeCodec<
96
+ WithdrawPayerInstructionDataArgs,
97
+ WithdrawPayerInstructionData
98
+ > {
99
+ return combineCodec(
100
+ getWithdrawPayerInstructionDataEncoder(),
101
+ getWithdrawPayerInstructionDataDecoder(),
102
+ );
103
+ }
104
+
105
+ export type WithdrawPayerInput<
106
+ TAccountPayer extends string = string,
107
+ TAccountChannel extends string = string,
108
+ TAccountChannelTokenAccount extends string = string,
109
+ TAccountPayerTokenAccount extends string = string,
110
+ TAccountMint extends string = string,
111
+ TAccountTokenProgram extends string = string,
112
+ > = {
113
+ payer: TransactionSigner<TAccountPayer>;
114
+ channel: Address<TAccountChannel>;
115
+ channelTokenAccount: Address<TAccountChannelTokenAccount>;
116
+ payerTokenAccount: Address<TAccountPayerTokenAccount>;
117
+ mint: Address<TAccountMint>;
118
+ tokenProgram: Address<TAccountTokenProgram>;
119
+ };
120
+
121
+ export function getWithdrawPayerInstruction<
122
+ TAccountPayer extends string,
123
+ TAccountChannel extends string,
124
+ TAccountChannelTokenAccount extends string,
125
+ TAccountPayerTokenAccount extends string,
126
+ TAccountMint extends string,
127
+ TAccountTokenProgram extends string,
128
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
129
+ >(
130
+ input: WithdrawPayerInput<
131
+ TAccountPayer,
132
+ TAccountChannel,
133
+ TAccountChannelTokenAccount,
134
+ TAccountPayerTokenAccount,
135
+ TAccountMint,
136
+ TAccountTokenProgram
137
+ >,
138
+ config?: { programAddress?: TProgramAddress },
139
+ ): WithdrawPayerInstruction<
140
+ TProgramAddress,
141
+ TAccountPayer,
142
+ TAccountChannel,
143
+ TAccountChannelTokenAccount,
144
+ TAccountPayerTokenAccount,
145
+ TAccountMint,
146
+ TAccountTokenProgram
147
+ > {
148
+ // Program address.
149
+ const programAddress =
150
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
151
+
152
+ // Original accounts.
153
+ const originalAccounts = {
154
+ payer: { value: input.payer ?? null, isWritable: false },
155
+ channel: { value: input.channel ?? null, isWritable: true },
156
+ channelTokenAccount: {
157
+ value: input.channelTokenAccount ?? null,
158
+ isWritable: true,
159
+ },
160
+ payerTokenAccount: {
161
+ value: input.payerTokenAccount ?? null,
162
+ isWritable: true,
163
+ },
164
+ mint: { value: input.mint ?? null, isWritable: false },
165
+ tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
166
+ };
167
+ const accounts = originalAccounts as Record<
168
+ keyof typeof originalAccounts,
169
+ ResolvedInstructionAccount
170
+ >;
171
+
172
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
173
+ return Object.freeze({
174
+ accounts: [
175
+ getAccountMeta("payer", accounts.payer),
176
+ getAccountMeta("channel", accounts.channel),
177
+ getAccountMeta("channelTokenAccount", accounts.channelTokenAccount),
178
+ getAccountMeta("payerTokenAccount", accounts.payerTokenAccount),
179
+ getAccountMeta("mint", accounts.mint),
180
+ getAccountMeta("tokenProgram", accounts.tokenProgram),
181
+ ],
182
+ data: getWithdrawPayerInstructionDataEncoder().encode({}),
183
+ programAddress,
184
+ } as WithdrawPayerInstruction<
185
+ TProgramAddress,
186
+ TAccountPayer,
187
+ TAccountChannel,
188
+ TAccountChannelTokenAccount,
189
+ TAccountPayerTokenAccount,
190
+ TAccountMint,
191
+ TAccountTokenProgram
192
+ >);
193
+ }
194
+
195
+ export type ParsedWithdrawPayerInstruction<
196
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
197
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
198
+ > = {
199
+ programAddress: Address<TProgram>;
200
+ accounts: {
201
+ payer: TAccountMetas[0];
202
+ channel: TAccountMetas[1];
203
+ channelTokenAccount: TAccountMetas[2];
204
+ payerTokenAccount: TAccountMetas[3];
205
+ mint: TAccountMetas[4];
206
+ tokenProgram: TAccountMetas[5];
207
+ };
208
+ data: WithdrawPayerInstructionData;
209
+ };
210
+
211
+ export function parseWithdrawPayerInstruction<
212
+ TProgram extends string,
213
+ TAccountMetas extends readonly AccountMeta[],
214
+ >(
215
+ instruction: Instruction<TProgram> &
216
+ InstructionWithAccounts<TAccountMetas> &
217
+ InstructionWithData<ReadonlyUint8Array>,
218
+ ): ParsedWithdrawPayerInstruction<TProgram, TAccountMetas> {
219
+ if (instruction.accounts.length !== 6) {
220
+ throw new SolanaError(
221
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
222
+ {
223
+ actualAccountMetas: instruction.accounts.length,
224
+ expectedAccountMetas: 6,
225
+ },
226
+ );
227
+ }
228
+ let accountIndex = 0;
229
+ const getNextAccount = () => {
230
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
231
+ accountIndex += 1;
232
+ return accountMeta;
233
+ };
234
+ return {
235
+ programAddress: instruction.programAddress,
236
+ accounts: {
237
+ payer: getNextAccount(),
238
+ channel: getNextAccount(),
239
+ channelTokenAccount: getNextAccount(),
240
+ payerTokenAccount: getNextAccount(),
241
+ mint: getNextAccount(),
242
+ tokenProgram: getNextAccount(),
243
+ },
244
+ data: getWithdrawPayerInstructionDataDecoder().decode(instruction.data),
245
+ };
246
+ }
@@ -0,0 +1,26 @@
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
+ getProgramDerivedAddress,
11
+ getUtf8Encoder,
12
+ type Address,
13
+ type ProgramDerivedAddress,
14
+ } from "@solana/kit";
15
+
16
+ export async function findEventAuthorityPda(
17
+ config: { programAddress?: Address | undefined } = {},
18
+ ): Promise<ProgramDerivedAddress> {
19
+ const {
20
+ programAddress = "CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX" as Address<"CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX">,
21
+ } = config;
22
+ return await getProgramDerivedAddress({
23
+ programAddress,
24
+ seeds: [getUtf8Encoder().encode("event_authority")],
25
+ });
26
+ }
@@ -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 "./eventAuthority";
@@ -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 "./paymentChannels";
@@ -0,0 +1,366 @@
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
+ assertIsInstructionWithAccounts,
11
+ containsBytes,
12
+ extendClient,
13
+ SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
14
+ SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
15
+ SolanaError,
16
+ type Address,
17
+ type ClientWithRpc,
18
+ type ClientWithTransactionPlanning,
19
+ type ClientWithTransactionSending,
20
+ type GetAccountInfoApi,
21
+ type GetMultipleAccountsApi,
22
+ type Instruction,
23
+ type InstructionWithData,
24
+ type ReadonlyUint8Array,
25
+ } from "@solana/kit";
26
+ import {
27
+ addSelfFetchFunctions,
28
+ addSelfPlanAndSendFunctions,
29
+ type SelfFetchFunctions,
30
+ type SelfPlanAndSendFunctions,
31
+ } from "@solana/program-client-core";
32
+ import { getU8Encoder } from "../../safe-codecs.js";
33
+ import { getChannelCodec, type Channel, type ChannelArgs } from "../accounts";
34
+ import {
35
+ getDistributeInstructionAsync,
36
+ getEmitEventInstructionAsync,
37
+ getOpenInstructionAsync,
38
+ getReclaimInstruction,
39
+ getRequestCloseInstruction,
40
+ getSealInstruction,
41
+ getSettleAndSealInstruction,
42
+ getSettleInstruction,
43
+ getTopUpInstruction,
44
+ getWithdrawPayerInstruction,
45
+ parseDistributeInstruction,
46
+ parseEmitEventInstruction,
47
+ parseOpenInstruction,
48
+ parseReclaimInstruction,
49
+ parseRequestCloseInstruction,
50
+ parseSealInstruction,
51
+ parseSettleAndSealInstruction,
52
+ parseSettleInstruction,
53
+ parseTopUpInstruction,
54
+ parseWithdrawPayerInstruction,
55
+ type DistributeAsyncInput,
56
+ type EmitEventAsyncInput,
57
+ type OpenAsyncInput,
58
+ type ParsedDistributeInstruction,
59
+ type ParsedEmitEventInstruction,
60
+ type ParsedOpenInstruction,
61
+ type ParsedReclaimInstruction,
62
+ type ParsedRequestCloseInstruction,
63
+ type ParsedSealInstruction,
64
+ type ParsedSettleAndSealInstruction,
65
+ type ParsedSettleInstruction,
66
+ type ParsedTopUpInstruction,
67
+ type ParsedWithdrawPayerInstruction,
68
+ type ReclaimInput,
69
+ type RequestCloseInput,
70
+ type SealInput,
71
+ type SettleAndSealInput,
72
+ type SettleInput,
73
+ type TopUpInput,
74
+ type WithdrawPayerInput,
75
+ } from "../instructions";
76
+ import { findEventAuthorityPda } from "../pdas";
77
+
78
+ export const PAYMENT_CHANNELS_PROGRAM_ADDRESS =
79
+ "CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX" as Address<"CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX">;
80
+
81
+ export enum PaymentChannelsAccount {
82
+ Channel,
83
+ }
84
+
85
+ export enum PaymentChannelsInstruction {
86
+ Open,
87
+ Settle,
88
+ TopUp,
89
+ SettleAndSeal,
90
+ RequestClose,
91
+ Seal,
92
+ Distribute,
93
+ WithdrawPayer,
94
+ Reclaim,
95
+ EmitEvent,
96
+ }
97
+
98
+ export function identifyPaymentChannelsInstruction(
99
+ instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array,
100
+ ): PaymentChannelsInstruction {
101
+ const data = "data" in instruction ? instruction.data : instruction;
102
+ if (containsBytes(data, getU8Encoder().encode(1), 0)) {
103
+ return PaymentChannelsInstruction.Open;
104
+ }
105
+ if (containsBytes(data, getU8Encoder().encode(2), 0)) {
106
+ return PaymentChannelsInstruction.Settle;
107
+ }
108
+ if (containsBytes(data, getU8Encoder().encode(3), 0)) {
109
+ return PaymentChannelsInstruction.TopUp;
110
+ }
111
+ if (containsBytes(data, getU8Encoder().encode(4), 0)) {
112
+ return PaymentChannelsInstruction.SettleAndSeal;
113
+ }
114
+ if (containsBytes(data, getU8Encoder().encode(5), 0)) {
115
+ return PaymentChannelsInstruction.RequestClose;
116
+ }
117
+ if (containsBytes(data, getU8Encoder().encode(6), 0)) {
118
+ return PaymentChannelsInstruction.Seal;
119
+ }
120
+ if (containsBytes(data, getU8Encoder().encode(7), 0)) {
121
+ return PaymentChannelsInstruction.Distribute;
122
+ }
123
+ if (containsBytes(data, getU8Encoder().encode(8), 0)) {
124
+ return PaymentChannelsInstruction.WithdrawPayer;
125
+ }
126
+ if (containsBytes(data, getU8Encoder().encode(9), 0)) {
127
+ return PaymentChannelsInstruction.Reclaim;
128
+ }
129
+ if (containsBytes(data, getU8Encoder().encode(228), 0)) {
130
+ return PaymentChannelsInstruction.EmitEvent;
131
+ }
132
+ throw new SolanaError(
133
+ SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION,
134
+ { instructionData: data, programName: "paymentChannels" },
135
+ );
136
+ }
137
+
138
+ export type ParsedPaymentChannelsInstruction<
139
+ TProgram extends string = "CHNLxYvVA28MJP9PrFuDXccuoGXAx7jBacfLEkahyGsX",
140
+ > =
141
+ | ({
142
+ instructionType: PaymentChannelsInstruction.Open;
143
+ } & ParsedOpenInstruction<TProgram>)
144
+ | ({
145
+ instructionType: PaymentChannelsInstruction.Settle;
146
+ } & ParsedSettleInstruction<TProgram>)
147
+ | ({
148
+ instructionType: PaymentChannelsInstruction.TopUp;
149
+ } & ParsedTopUpInstruction<TProgram>)
150
+ | ({
151
+ instructionType: PaymentChannelsInstruction.SettleAndSeal;
152
+ } & ParsedSettleAndSealInstruction<TProgram>)
153
+ | ({
154
+ instructionType: PaymentChannelsInstruction.RequestClose;
155
+ } & ParsedRequestCloseInstruction<TProgram>)
156
+ | ({
157
+ instructionType: PaymentChannelsInstruction.Seal;
158
+ } & ParsedSealInstruction<TProgram>)
159
+ | ({
160
+ instructionType: PaymentChannelsInstruction.Distribute;
161
+ } & ParsedDistributeInstruction<TProgram>)
162
+ | ({
163
+ instructionType: PaymentChannelsInstruction.WithdrawPayer;
164
+ } & ParsedWithdrawPayerInstruction<TProgram>)
165
+ | ({
166
+ instructionType: PaymentChannelsInstruction.Reclaim;
167
+ } & ParsedReclaimInstruction<TProgram>)
168
+ | ({
169
+ instructionType: PaymentChannelsInstruction.EmitEvent;
170
+ } & ParsedEmitEventInstruction<TProgram>);
171
+
172
+ export function parsePaymentChannelsInstruction<TProgram extends string>(
173
+ instruction: Instruction<TProgram> & InstructionWithData<ReadonlyUint8Array>,
174
+ ): ParsedPaymentChannelsInstruction<TProgram> {
175
+ const instructionType = identifyPaymentChannelsInstruction(instruction);
176
+ switch (instructionType) {
177
+ case PaymentChannelsInstruction.Open: {
178
+ assertIsInstructionWithAccounts(instruction);
179
+ return {
180
+ instructionType: PaymentChannelsInstruction.Open,
181
+ ...parseOpenInstruction(instruction),
182
+ };
183
+ }
184
+ case PaymentChannelsInstruction.Settle: {
185
+ assertIsInstructionWithAccounts(instruction);
186
+ return {
187
+ instructionType: PaymentChannelsInstruction.Settle,
188
+ ...parseSettleInstruction(instruction),
189
+ };
190
+ }
191
+ case PaymentChannelsInstruction.TopUp: {
192
+ assertIsInstructionWithAccounts(instruction);
193
+ return {
194
+ instructionType: PaymentChannelsInstruction.TopUp,
195
+ ...parseTopUpInstruction(instruction),
196
+ };
197
+ }
198
+ case PaymentChannelsInstruction.SettleAndSeal: {
199
+ assertIsInstructionWithAccounts(instruction);
200
+ return {
201
+ instructionType: PaymentChannelsInstruction.SettleAndSeal,
202
+ ...parseSettleAndSealInstruction(instruction),
203
+ };
204
+ }
205
+ case PaymentChannelsInstruction.RequestClose: {
206
+ assertIsInstructionWithAccounts(instruction);
207
+ return {
208
+ instructionType: PaymentChannelsInstruction.RequestClose,
209
+ ...parseRequestCloseInstruction(instruction),
210
+ };
211
+ }
212
+ case PaymentChannelsInstruction.Seal: {
213
+ assertIsInstructionWithAccounts(instruction);
214
+ return {
215
+ instructionType: PaymentChannelsInstruction.Seal,
216
+ ...parseSealInstruction(instruction),
217
+ };
218
+ }
219
+ case PaymentChannelsInstruction.Distribute: {
220
+ assertIsInstructionWithAccounts(instruction);
221
+ return {
222
+ instructionType: PaymentChannelsInstruction.Distribute,
223
+ ...parseDistributeInstruction(instruction),
224
+ };
225
+ }
226
+ case PaymentChannelsInstruction.WithdrawPayer: {
227
+ assertIsInstructionWithAccounts(instruction);
228
+ return {
229
+ instructionType: PaymentChannelsInstruction.WithdrawPayer,
230
+ ...parseWithdrawPayerInstruction(instruction),
231
+ };
232
+ }
233
+ case PaymentChannelsInstruction.Reclaim: {
234
+ assertIsInstructionWithAccounts(instruction);
235
+ return {
236
+ instructionType: PaymentChannelsInstruction.Reclaim,
237
+ ...parseReclaimInstruction(instruction),
238
+ };
239
+ }
240
+ case PaymentChannelsInstruction.EmitEvent: {
241
+ assertIsInstructionWithAccounts(instruction);
242
+ return {
243
+ instructionType: PaymentChannelsInstruction.EmitEvent,
244
+ ...parseEmitEventInstruction(instruction),
245
+ };
246
+ }
247
+ default:
248
+ throw new SolanaError(
249
+ SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE,
250
+ {
251
+ instructionType: instructionType as string,
252
+ programName: "paymentChannels",
253
+ },
254
+ );
255
+ }
256
+ }
257
+
258
+ export type PaymentChannelsPlugin = {
259
+ accounts: PaymentChannelsPluginAccounts;
260
+ instructions: PaymentChannelsPluginInstructions;
261
+ pdas: PaymentChannelsPluginPdas;
262
+ };
263
+
264
+ export type PaymentChannelsPluginAccounts = {
265
+ channel: ReturnType<typeof getChannelCodec> &
266
+ SelfFetchFunctions<ChannelArgs, Channel>;
267
+ };
268
+
269
+ export type PaymentChannelsPluginInstructions = {
270
+ open: (
271
+ input: OpenAsyncInput,
272
+ ) => ReturnType<typeof getOpenInstructionAsync> & SelfPlanAndSendFunctions;
273
+ settle: (
274
+ input: SettleInput,
275
+ ) => ReturnType<typeof getSettleInstruction> & SelfPlanAndSendFunctions;
276
+ topUp: (
277
+ input: TopUpInput,
278
+ ) => ReturnType<typeof getTopUpInstruction> & SelfPlanAndSendFunctions;
279
+ settleAndSeal: (
280
+ input: SettleAndSealInput,
281
+ ) => ReturnType<typeof getSettleAndSealInstruction> &
282
+ SelfPlanAndSendFunctions;
283
+ requestClose: (
284
+ input: RequestCloseInput,
285
+ ) => ReturnType<typeof getRequestCloseInstruction> & SelfPlanAndSendFunctions;
286
+ seal: (
287
+ input: SealInput,
288
+ ) => ReturnType<typeof getSealInstruction> & SelfPlanAndSendFunctions;
289
+ distribute: (
290
+ input: DistributeAsyncInput,
291
+ ) => ReturnType<typeof getDistributeInstructionAsync> &
292
+ SelfPlanAndSendFunctions;
293
+ withdrawPayer: (
294
+ input: WithdrawPayerInput,
295
+ ) => ReturnType<typeof getWithdrawPayerInstruction> &
296
+ SelfPlanAndSendFunctions;
297
+ reclaim: (
298
+ input: ReclaimInput,
299
+ ) => ReturnType<typeof getReclaimInstruction> & SelfPlanAndSendFunctions;
300
+ emitEvent: (
301
+ input: EmitEventAsyncInput,
302
+ ) => ReturnType<typeof getEmitEventInstructionAsync> &
303
+ SelfPlanAndSendFunctions;
304
+ };
305
+
306
+ export type PaymentChannelsPluginPdas = {
307
+ eventAuthority: typeof findEventAuthorityPda;
308
+ };
309
+
310
+ export type PaymentChannelsPluginRequirements = ClientWithRpc<
311
+ GetAccountInfoApi & GetMultipleAccountsApi
312
+ > &
313
+ ClientWithTransactionPlanning &
314
+ ClientWithTransactionSending;
315
+
316
+ export function paymentChannelsProgram() {
317
+ return <T extends PaymentChannelsPluginRequirements>(
318
+ client: T,
319
+ ): Omit<T, "paymentChannels"> & {
320
+ paymentChannels: PaymentChannelsPlugin;
321
+ } => {
322
+ return extendClient(client, {
323
+ paymentChannels: <PaymentChannelsPlugin>{
324
+ accounts: { channel: addSelfFetchFunctions(client, getChannelCodec()) },
325
+ instructions: {
326
+ open: (input) =>
327
+ addSelfPlanAndSendFunctions(client, getOpenInstructionAsync(input)),
328
+ settle: (input) =>
329
+ addSelfPlanAndSendFunctions(client, getSettleInstruction(input)),
330
+ topUp: (input) =>
331
+ addSelfPlanAndSendFunctions(client, getTopUpInstruction(input)),
332
+ settleAndSeal: (input) =>
333
+ addSelfPlanAndSendFunctions(
334
+ client,
335
+ getSettleAndSealInstruction(input),
336
+ ),
337
+ requestClose: (input) =>
338
+ addSelfPlanAndSendFunctions(
339
+ client,
340
+ getRequestCloseInstruction(input),
341
+ ),
342
+ seal: (input) =>
343
+ addSelfPlanAndSendFunctions(client, getSealInstruction(input)),
344
+ distribute: (input) =>
345
+ addSelfPlanAndSendFunctions(
346
+ client,
347
+ getDistributeInstructionAsync(input),
348
+ ),
349
+ withdrawPayer: (input) =>
350
+ addSelfPlanAndSendFunctions(
351
+ client,
352
+ getWithdrawPayerInstruction(input),
353
+ ),
354
+ reclaim: (input) =>
355
+ addSelfPlanAndSendFunctions(client, getReclaimInstruction(input)),
356
+ emitEvent: (input) =>
357
+ addSelfPlanAndSendFunctions(
358
+ client,
359
+ getEmitEventInstructionAsync(input),
360
+ ),
361
+ },
362
+ pdas: { eventAuthority: findEventAuthorityPda },
363
+ },
364
+ }) as any;
365
+ };
366
+ }
@@ -0,0 +1,41 @@
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
+ getEnumDecoder,
12
+ getEnumEncoder,
13
+ type FixedSizeCodec,
14
+ type FixedSizeDecoder,
15
+ type FixedSizeEncoder,
16
+ } from "@solana/kit";
17
+
18
+ export enum AccountDiscriminator {
19
+ Channel,
20
+ ClosedChannel,
21
+ }
22
+
23
+ export type AccountDiscriminatorArgs = AccountDiscriminator;
24
+
25
+ export function getAccountDiscriminatorEncoder(): FixedSizeEncoder<AccountDiscriminatorArgs> {
26
+ return getEnumEncoder(AccountDiscriminator);
27
+ }
28
+
29
+ export function getAccountDiscriminatorDecoder(): FixedSizeDecoder<AccountDiscriminator> {
30
+ return getEnumDecoder(AccountDiscriminator);
31
+ }
32
+
33
+ export function getAccountDiscriminatorCodec(): FixedSizeCodec<
34
+ AccountDiscriminatorArgs,
35
+ AccountDiscriminator
36
+ > {
37
+ return combineCodec(
38
+ getAccountDiscriminatorEncoder(),
39
+ getAccountDiscriminatorDecoder(),
40
+ );
41
+ }