@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,165 @@
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 Address,
18
+ type FixedSizeCodec,
19
+ type FixedSizeDecoder,
20
+ type FixedSizeEncoder,
21
+ type Instruction,
22
+ type InstructionWithAccounts,
23
+ type InstructionWithData,
24
+ type ReadonlyUint8Array,
25
+ type WritableAccount,
26
+ } from "@solana/kit";
27
+ import {
28
+ getAccountMetaFactory,
29
+ type ResolvedInstructionAccount,
30
+ } from "@solana/program-client-core";
31
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
32
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
33
+
34
+ export const RECLAIM_DISCRIMINATOR = 9;
35
+
36
+ export function getReclaimDiscriminatorBytes(): ReadonlyUint8Array {
37
+ return getU8Encoder().encode(RECLAIM_DISCRIMINATOR);
38
+ }
39
+
40
+ export type ReclaimInstruction<
41
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
42
+ TAccountChannel extends string | AccountMeta<string> = string,
43
+ TAccountRentPayer extends string | AccountMeta<string> = string,
44
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
45
+ > = Instruction<TProgram> &
46
+ InstructionWithData<ReadonlyUint8Array> &
47
+ InstructionWithAccounts<
48
+ [
49
+ TAccountChannel extends string
50
+ ? WritableAccount<TAccountChannel>
51
+ : TAccountChannel,
52
+ TAccountRentPayer extends string
53
+ ? WritableAccount<TAccountRentPayer>
54
+ : TAccountRentPayer,
55
+ ...TRemainingAccounts,
56
+ ]
57
+ >;
58
+
59
+ export type ReclaimInstructionData = { discriminator: number };
60
+
61
+ export type ReclaimInstructionDataArgs = {};
62
+
63
+ export function getReclaimInstructionDataEncoder(): FixedSizeEncoder<ReclaimInstructionDataArgs> {
64
+ return transformEncoder(
65
+ getStructEncoder([["discriminator", getU8Encoder()]]),
66
+ (value) => ({ ...value, discriminator: RECLAIM_DISCRIMINATOR }),
67
+ );
68
+ }
69
+
70
+ export function getReclaimInstructionDataDecoder(): FixedSizeDecoder<ReclaimInstructionData> {
71
+ return getStructDecoder([["discriminator", getU8Decoder()]]);
72
+ }
73
+
74
+ export function getReclaimInstructionDataCodec(): FixedSizeCodec<
75
+ ReclaimInstructionDataArgs,
76
+ ReclaimInstructionData
77
+ > {
78
+ return combineCodec(
79
+ getReclaimInstructionDataEncoder(),
80
+ getReclaimInstructionDataDecoder(),
81
+ );
82
+ }
83
+
84
+ export type ReclaimInput<
85
+ TAccountChannel extends string = string,
86
+ TAccountRentPayer extends string = string,
87
+ > = {
88
+ channel: Address<TAccountChannel>;
89
+ rentPayer: Address<TAccountRentPayer>;
90
+ };
91
+
92
+ export function getReclaimInstruction<
93
+ TAccountChannel extends string,
94
+ TAccountRentPayer extends string,
95
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
96
+ >(
97
+ input: ReclaimInput<TAccountChannel, TAccountRentPayer>,
98
+ config?: { programAddress?: TProgramAddress },
99
+ ): ReclaimInstruction<TProgramAddress, TAccountChannel, TAccountRentPayer> {
100
+ // Program address.
101
+ const programAddress =
102
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
103
+
104
+ // Original accounts.
105
+ const originalAccounts = {
106
+ channel: { value: input.channel ?? null, isWritable: true },
107
+ rentPayer: { value: input.rentPayer ?? null, isWritable: true },
108
+ };
109
+ const accounts = originalAccounts as Record<
110
+ keyof typeof originalAccounts,
111
+ ResolvedInstructionAccount
112
+ >;
113
+
114
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
115
+ return Object.freeze({
116
+ accounts: [
117
+ getAccountMeta("channel", accounts.channel),
118
+ getAccountMeta("rentPayer", accounts.rentPayer),
119
+ ],
120
+ data: getReclaimInstructionDataEncoder().encode({}),
121
+ programAddress,
122
+ } as ReclaimInstruction<TProgramAddress, TAccountChannel, TAccountRentPayer>);
123
+ }
124
+
125
+ export type ParsedReclaimInstruction<
126
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
127
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
128
+ > = {
129
+ programAddress: Address<TProgram>;
130
+ accounts: {
131
+ channel: TAccountMetas[0];
132
+ rentPayer: TAccountMetas[1];
133
+ };
134
+ data: ReclaimInstructionData;
135
+ };
136
+
137
+ export function parseReclaimInstruction<
138
+ TProgram extends string,
139
+ TAccountMetas extends readonly AccountMeta[],
140
+ >(
141
+ instruction: Instruction<TProgram> &
142
+ InstructionWithAccounts<TAccountMetas> &
143
+ InstructionWithData<ReadonlyUint8Array>,
144
+ ): ParsedReclaimInstruction<TProgram, TAccountMetas> {
145
+ if (instruction.accounts.length !== 2) {
146
+ throw new SolanaError(
147
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
148
+ {
149
+ actualAccountMetas: instruction.accounts.length,
150
+ expectedAccountMetas: 2,
151
+ },
152
+ );
153
+ }
154
+ let accountIndex = 0;
155
+ const getNextAccount = () => {
156
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
157
+ accountIndex += 1;
158
+ return accountMeta;
159
+ };
160
+ return {
161
+ programAddress: instruction.programAddress,
162
+ accounts: { channel: getNextAccount(), rentPayer: getNextAccount() },
163
+ data: getReclaimInstructionDataDecoder().decode(instruction.data),
164
+ };
165
+ }
@@ -0,0 +1,173 @@
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 ReadonlySignerAccount,
26
+ type ReadonlyUint8Array,
27
+ type TransactionSigner,
28
+ type WritableAccount,
29
+ } from "@solana/kit";
30
+ import {
31
+ getAccountMetaFactory,
32
+ type ResolvedInstructionAccount,
33
+ } from "@solana/program-client-core";
34
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
35
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
36
+
37
+ export const REQUEST_CLOSE_DISCRIMINATOR = 5;
38
+
39
+ export function getRequestCloseDiscriminatorBytes(): ReadonlyUint8Array {
40
+ return getU8Encoder().encode(REQUEST_CLOSE_DISCRIMINATOR);
41
+ }
42
+
43
+ export type RequestCloseInstruction<
44
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
45
+ TAccountPayer extends string | AccountMeta<string> = string,
46
+ TAccountChannel extends string | AccountMeta<string> = string,
47
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
48
+ > = Instruction<TProgram> &
49
+ InstructionWithData<ReadonlyUint8Array> &
50
+ InstructionWithAccounts<
51
+ [
52
+ TAccountPayer extends string
53
+ ? ReadonlySignerAccount<TAccountPayer> &
54
+ AccountSignerMeta<TAccountPayer>
55
+ : TAccountPayer,
56
+ TAccountChannel extends string
57
+ ? WritableAccount<TAccountChannel>
58
+ : TAccountChannel,
59
+ ...TRemainingAccounts,
60
+ ]
61
+ >;
62
+
63
+ export type RequestCloseInstructionData = { discriminator: number };
64
+
65
+ export type RequestCloseInstructionDataArgs = {};
66
+
67
+ export function getRequestCloseInstructionDataEncoder(): FixedSizeEncoder<RequestCloseInstructionDataArgs> {
68
+ return transformEncoder(
69
+ getStructEncoder([["discriminator", getU8Encoder()]]),
70
+ (value) => ({ ...value, discriminator: REQUEST_CLOSE_DISCRIMINATOR }),
71
+ );
72
+ }
73
+
74
+ export function getRequestCloseInstructionDataDecoder(): FixedSizeDecoder<RequestCloseInstructionData> {
75
+ return getStructDecoder([["discriminator", getU8Decoder()]]);
76
+ }
77
+
78
+ export function getRequestCloseInstructionDataCodec(): FixedSizeCodec<
79
+ RequestCloseInstructionDataArgs,
80
+ RequestCloseInstructionData
81
+ > {
82
+ return combineCodec(
83
+ getRequestCloseInstructionDataEncoder(),
84
+ getRequestCloseInstructionDataDecoder(),
85
+ );
86
+ }
87
+
88
+ export type RequestCloseInput<
89
+ TAccountPayer extends string = string,
90
+ TAccountChannel extends string = string,
91
+ > = {
92
+ payer: TransactionSigner<TAccountPayer>;
93
+ channel: Address<TAccountChannel>;
94
+ };
95
+
96
+ export function getRequestCloseInstruction<
97
+ TAccountPayer extends string,
98
+ TAccountChannel extends string,
99
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
100
+ >(
101
+ input: RequestCloseInput<TAccountPayer, TAccountChannel>,
102
+ config?: { programAddress?: TProgramAddress },
103
+ ): RequestCloseInstruction<TProgramAddress, TAccountPayer, TAccountChannel> {
104
+ // Program address.
105
+ const programAddress =
106
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
107
+
108
+ // Original accounts.
109
+ const originalAccounts = {
110
+ payer: { value: input.payer ?? null, isWritable: false },
111
+ channel: { value: input.channel ?? null, isWritable: true },
112
+ };
113
+ const accounts = originalAccounts as Record<
114
+ keyof typeof originalAccounts,
115
+ ResolvedInstructionAccount
116
+ >;
117
+
118
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
119
+ return Object.freeze({
120
+ accounts: [
121
+ getAccountMeta("payer", accounts.payer),
122
+ getAccountMeta("channel", accounts.channel),
123
+ ],
124
+ data: getRequestCloseInstructionDataEncoder().encode({}),
125
+ programAddress,
126
+ } as RequestCloseInstruction<
127
+ TProgramAddress,
128
+ TAccountPayer,
129
+ TAccountChannel
130
+ >);
131
+ }
132
+
133
+ export type ParsedRequestCloseInstruction<
134
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
135
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
136
+ > = {
137
+ programAddress: Address<TProgram>;
138
+ accounts: {
139
+ payer: TAccountMetas[0];
140
+ channel: TAccountMetas[1];
141
+ };
142
+ data: RequestCloseInstructionData;
143
+ };
144
+
145
+ export function parseRequestCloseInstruction<
146
+ TProgram extends string,
147
+ TAccountMetas extends readonly AccountMeta[],
148
+ >(
149
+ instruction: Instruction<TProgram> &
150
+ InstructionWithAccounts<TAccountMetas> &
151
+ InstructionWithData<ReadonlyUint8Array>,
152
+ ): ParsedRequestCloseInstruction<TProgram, TAccountMetas> {
153
+ if (instruction.accounts.length !== 2) {
154
+ throw new SolanaError(
155
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
156
+ {
157
+ actualAccountMetas: instruction.accounts.length,
158
+ expectedAccountMetas: 2,
159
+ },
160
+ );
161
+ }
162
+ let accountIndex = 0;
163
+ const getNextAccount = () => {
164
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
165
+ accountIndex += 1;
166
+ return accountMeta;
167
+ };
168
+ return {
169
+ programAddress: instruction.programAddress,
170
+ accounts: { payer: getNextAccount(), channel: getNextAccount() },
171
+ data: getRequestCloseInstructionDataDecoder().decode(instruction.data),
172
+ };
173
+ }
@@ -0,0 +1,151 @@
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 Address,
18
+ type FixedSizeCodec,
19
+ type FixedSizeDecoder,
20
+ type FixedSizeEncoder,
21
+ type Instruction,
22
+ type InstructionWithAccounts,
23
+ type InstructionWithData,
24
+ type ReadonlyUint8Array,
25
+ type WritableAccount,
26
+ } from "@solana/kit";
27
+ import {
28
+ getAccountMetaFactory,
29
+ type ResolvedInstructionAccount,
30
+ } from "@solana/program-client-core";
31
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
32
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
33
+
34
+ export const SEAL_DISCRIMINATOR = 6;
35
+
36
+ export function getSealDiscriminatorBytes(): ReadonlyUint8Array {
37
+ return getU8Encoder().encode(SEAL_DISCRIMINATOR);
38
+ }
39
+
40
+ export type SealInstruction<
41
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
42
+ TAccountChannel extends string | AccountMeta<string> = string,
43
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
44
+ > = Instruction<TProgram> &
45
+ InstructionWithData<ReadonlyUint8Array> &
46
+ InstructionWithAccounts<
47
+ [
48
+ TAccountChannel extends string
49
+ ? WritableAccount<TAccountChannel>
50
+ : TAccountChannel,
51
+ ...TRemainingAccounts,
52
+ ]
53
+ >;
54
+
55
+ export type SealInstructionData = { discriminator: number };
56
+
57
+ export type SealInstructionDataArgs = {};
58
+
59
+ export function getSealInstructionDataEncoder(): FixedSizeEncoder<SealInstructionDataArgs> {
60
+ return transformEncoder(
61
+ getStructEncoder([["discriminator", getU8Encoder()]]),
62
+ (value) => ({ ...value, discriminator: SEAL_DISCRIMINATOR }),
63
+ );
64
+ }
65
+
66
+ export function getSealInstructionDataDecoder(): FixedSizeDecoder<SealInstructionData> {
67
+ return getStructDecoder([["discriminator", getU8Decoder()]]);
68
+ }
69
+
70
+ export function getSealInstructionDataCodec(): FixedSizeCodec<
71
+ SealInstructionDataArgs,
72
+ SealInstructionData
73
+ > {
74
+ return combineCodec(
75
+ getSealInstructionDataEncoder(),
76
+ getSealInstructionDataDecoder(),
77
+ );
78
+ }
79
+
80
+ export type SealInput<TAccountChannel extends string = string> = {
81
+ channel: Address<TAccountChannel>;
82
+ };
83
+
84
+ export function getSealInstruction<
85
+ TAccountChannel extends string,
86
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
87
+ >(
88
+ input: SealInput<TAccountChannel>,
89
+ config?: { programAddress?: TProgramAddress },
90
+ ): SealInstruction<TProgramAddress, TAccountChannel> {
91
+ // Program address.
92
+ const programAddress =
93
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
94
+
95
+ // Original accounts.
96
+ const originalAccounts = {
97
+ channel: { value: input.channel ?? null, isWritable: true },
98
+ };
99
+ const accounts = originalAccounts as Record<
100
+ keyof typeof originalAccounts,
101
+ ResolvedInstructionAccount
102
+ >;
103
+
104
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
105
+ return Object.freeze({
106
+ accounts: [getAccountMeta("channel", accounts.channel)],
107
+ data: getSealInstructionDataEncoder().encode({}),
108
+ programAddress,
109
+ } as SealInstruction<TProgramAddress, TAccountChannel>);
110
+ }
111
+
112
+ export type ParsedSealInstruction<
113
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
114
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
115
+ > = {
116
+ programAddress: Address<TProgram>;
117
+ accounts: {
118
+ channel: TAccountMetas[0];
119
+ };
120
+ data: SealInstructionData;
121
+ };
122
+
123
+ export function parseSealInstruction<
124
+ TProgram extends string,
125
+ TAccountMetas extends readonly AccountMeta[],
126
+ >(
127
+ instruction: Instruction<TProgram> &
128
+ InstructionWithAccounts<TAccountMetas> &
129
+ InstructionWithData<ReadonlyUint8Array>,
130
+ ): ParsedSealInstruction<TProgram, TAccountMetas> {
131
+ if (instruction.accounts.length !== 1) {
132
+ throw new SolanaError(
133
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
134
+ {
135
+ actualAccountMetas: instruction.accounts.length,
136
+ expectedAccountMetas: 1,
137
+ },
138
+ );
139
+ }
140
+ let accountIndex = 0;
141
+ const getNextAccount = () => {
142
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
143
+ accountIndex += 1;
144
+ return accountMeta;
145
+ };
146
+ return {
147
+ programAddress: instruction.programAddress,
148
+ accounts: { channel: getNextAccount() },
149
+ data: getSealInstructionDataDecoder().decode(instruction.data),
150
+ };
151
+ }
@@ -0,0 +1,180 @@
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 Address,
18
+ type FixedSizeCodec,
19
+ type FixedSizeDecoder,
20
+ type FixedSizeEncoder,
21
+ type Instruction,
22
+ type InstructionWithAccounts,
23
+ type InstructionWithData,
24
+ type ReadonlyAccount,
25
+ type ReadonlyUint8Array,
26
+ type WritableAccount,
27
+ } from "@solana/kit";
28
+ import {
29
+ getAccountMetaFactory,
30
+ type ResolvedInstructionAccount,
31
+ } from "@solana/program-client-core";
32
+ import { getU8Decoder, getU8Encoder } from "../../safe-codecs.js";
33
+ import { PAYMENT_CHANNELS_PROGRAM_ADDRESS } from "../programs";
34
+
35
+ export const SETTLE_DISCRIMINATOR = 2;
36
+
37
+ export function getSettleDiscriminatorBytes(): ReadonlyUint8Array {
38
+ return getU8Encoder().encode(SETTLE_DISCRIMINATOR);
39
+ }
40
+
41
+ export type SettleInstruction<
42
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
43
+ TAccountChannel extends string | AccountMeta<string> = string,
44
+ TAccountInstructionsSysvar extends string | AccountMeta<string> = string,
45
+ TRemainingAccounts extends readonly AccountMeta<string>[] = [],
46
+ > = Instruction<TProgram> &
47
+ InstructionWithData<ReadonlyUint8Array> &
48
+ InstructionWithAccounts<
49
+ [
50
+ TAccountChannel extends string
51
+ ? WritableAccount<TAccountChannel>
52
+ : TAccountChannel,
53
+ TAccountInstructionsSysvar extends string
54
+ ? ReadonlyAccount<TAccountInstructionsSysvar>
55
+ : TAccountInstructionsSysvar,
56
+ ...TRemainingAccounts,
57
+ ]
58
+ >;
59
+
60
+ export type SettleInstructionData = { discriminator: number };
61
+
62
+ export type SettleInstructionDataArgs = {};
63
+
64
+ export function getSettleInstructionDataEncoder(): FixedSizeEncoder<SettleInstructionDataArgs> {
65
+ return transformEncoder(
66
+ getStructEncoder([["discriminator", getU8Encoder()]]),
67
+ (value) => ({ ...value, discriminator: SETTLE_DISCRIMINATOR }),
68
+ );
69
+ }
70
+
71
+ export function getSettleInstructionDataDecoder(): FixedSizeDecoder<SettleInstructionData> {
72
+ return getStructDecoder([["discriminator", getU8Decoder()]]);
73
+ }
74
+
75
+ export function getSettleInstructionDataCodec(): FixedSizeCodec<
76
+ SettleInstructionDataArgs,
77
+ SettleInstructionData
78
+ > {
79
+ return combineCodec(
80
+ getSettleInstructionDataEncoder(),
81
+ getSettleInstructionDataDecoder(),
82
+ );
83
+ }
84
+
85
+ export type SettleInput<
86
+ TAccountChannel extends string = string,
87
+ TAccountInstructionsSysvar extends string = string,
88
+ > = {
89
+ channel: Address<TAccountChannel>;
90
+ instructionsSysvar: Address<TAccountInstructionsSysvar>;
91
+ };
92
+
93
+ export function getSettleInstruction<
94
+ TAccountChannel extends string,
95
+ TAccountInstructionsSysvar extends string,
96
+ TProgramAddress extends Address = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
97
+ >(
98
+ input: SettleInput<TAccountChannel, TAccountInstructionsSysvar>,
99
+ config?: { programAddress?: TProgramAddress },
100
+ ): SettleInstruction<
101
+ TProgramAddress,
102
+ TAccountChannel,
103
+ TAccountInstructionsSysvar
104
+ > {
105
+ // Program address.
106
+ const programAddress =
107
+ config?.programAddress ?? PAYMENT_CHANNELS_PROGRAM_ADDRESS;
108
+
109
+ // Original accounts.
110
+ const originalAccounts = {
111
+ channel: { value: input.channel ?? null, isWritable: true },
112
+ instructionsSysvar: {
113
+ value: input.instructionsSysvar ?? null,
114
+ isWritable: false,
115
+ },
116
+ };
117
+ const accounts = originalAccounts as Record<
118
+ keyof typeof originalAccounts,
119
+ ResolvedInstructionAccount
120
+ >;
121
+
122
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
123
+ return Object.freeze({
124
+ accounts: [
125
+ getAccountMeta("channel", accounts.channel),
126
+ getAccountMeta("instructionsSysvar", accounts.instructionsSysvar),
127
+ ],
128
+ data: getSettleInstructionDataEncoder().encode({}),
129
+ programAddress,
130
+ } as SettleInstruction<
131
+ TProgramAddress,
132
+ TAccountChannel,
133
+ TAccountInstructionsSysvar
134
+ >);
135
+ }
136
+
137
+ export type ParsedSettleInstruction<
138
+ TProgram extends string = typeof PAYMENT_CHANNELS_PROGRAM_ADDRESS,
139
+ TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
140
+ > = {
141
+ programAddress: Address<TProgram>;
142
+ accounts: {
143
+ channel: TAccountMetas[0];
144
+ instructionsSysvar: TAccountMetas[1];
145
+ };
146
+ data: SettleInstructionData;
147
+ };
148
+
149
+ export function parseSettleInstruction<
150
+ TProgram extends string,
151
+ TAccountMetas extends readonly AccountMeta[],
152
+ >(
153
+ instruction: Instruction<TProgram> &
154
+ InstructionWithAccounts<TAccountMetas> &
155
+ InstructionWithData<ReadonlyUint8Array>,
156
+ ): ParsedSettleInstruction<TProgram, TAccountMetas> {
157
+ if (instruction.accounts.length !== 2) {
158
+ throw new SolanaError(
159
+ SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS,
160
+ {
161
+ actualAccountMetas: instruction.accounts.length,
162
+ expectedAccountMetas: 2,
163
+ },
164
+ );
165
+ }
166
+ let accountIndex = 0;
167
+ const getNextAccount = () => {
168
+ const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
169
+ accountIndex += 1;
170
+ return accountMeta;
171
+ };
172
+ return {
173
+ programAddress: instruction.programAddress,
174
+ accounts: {
175
+ channel: getNextAccount(),
176
+ instructionsSysvar: getNextAccount(),
177
+ },
178
+ data: getSettleInstructionDataDecoder().decode(instruction.data),
179
+ };
180
+ }