@@ -41,6 +41,12 @@ import {
41
41
type ResolvedAccount ,
42
42
} from '../shared' ;
43
43
44
+ export const INCREMENT_DISCRIMINATOR = 1 ;
45
+
46
+ export function getIncrementDiscriminatorBytes ( ) {
47
+ return getU8Encoder ( ) . encode ( INCREMENT_DISCRIMINATOR ) ;
48
+ }
49
+
44
50
export type IncrementInstruction <
45
51
TProgram extends string = typeof COUNTER_PROGRAM_ADDRESS ,
46
52
TAccountCounter extends string | IAccountMeta < string > = string ,
@@ -76,7 +82,11 @@ export function getIncrementInstructionDataEncoder(): Encoder<IncrementInstructi
76
82
[ 'discriminator' , getU8Encoder ( ) ] ,
77
83
[ 'amount' , getOptionEncoder ( getU32Encoder ( ) ) ] ,
78
84
] ) ,
79
- ( value ) => ( { ...value , discriminator : 1 , amount : value . amount ?? none ( ) } )
85
+ ( value ) => ( {
86
+ ...value ,
87
+ discriminator : INCREMENT_DISCRIMINATOR ,
88
+ amount : value . amount ?? none ( ) ,
89
+ } )
80
90
) ;
81
91
}
82
92
@@ -111,17 +121,15 @@ export type IncrementAsyncInput<
111
121
export async function getIncrementInstructionAsync <
112
122
TAccountCounter extends string ,
113
123
TAccountAuthority extends string ,
124
+ TProgramAddress extends Address = typeof COUNTER_PROGRAM_ADDRESS ,
114
125
> (
115
- input : IncrementAsyncInput < TAccountCounter , TAccountAuthority >
126
+ input : IncrementAsyncInput < TAccountCounter , TAccountAuthority > ,
127
+ config ?: { programAddress ?: TProgramAddress }
116
128
) : Promise <
117
- IncrementInstruction <
118
- typeof COUNTER_PROGRAM_ADDRESS ,
119
- TAccountCounter ,
120
- TAccountAuthority
121
- >
129
+ IncrementInstruction < TProgramAddress , TAccountCounter , TAccountAuthority >
122
130
> {
123
131
// Program address.
124
- const programAddress = COUNTER_PROGRAM_ADDRESS ;
132
+ const programAddress = config ?. programAddress ?? COUNTER_PROGRAM_ADDRESS ;
125
133
126
134
// Original accounts.
127
135
const originalAccounts = {
@@ -154,7 +162,7 @@ export async function getIncrementInstructionAsync<
154
162
args as IncrementInstructionDataArgs
155
163
) ,
156
164
} as IncrementInstruction <
157
- typeof COUNTER_PROGRAM_ADDRESS ,
165
+ TProgramAddress ,
158
166
TAccountCounter ,
159
167
TAccountAuthority
160
168
> ;
@@ -176,15 +184,13 @@ export type IncrementInput<
176
184
export function getIncrementInstruction <
177
185
TAccountCounter extends string ,
178
186
TAccountAuthority extends string ,
187
+ TProgramAddress extends Address = typeof COUNTER_PROGRAM_ADDRESS ,
179
188
> (
180
- input : IncrementInput < TAccountCounter , TAccountAuthority >
181
- ) : IncrementInstruction <
182
- typeof COUNTER_PROGRAM_ADDRESS ,
183
- TAccountCounter ,
184
- TAccountAuthority
185
- > {
189
+ input : IncrementInput < TAccountCounter , TAccountAuthority > ,
190
+ config ?: { programAddress ?: TProgramAddress }
191
+ ) : IncrementInstruction < TProgramAddress , TAccountCounter , TAccountAuthority > {
186
192
// Program address.
187
- const programAddress = COUNTER_PROGRAM_ADDRESS ;
193
+ const programAddress = config ?. programAddress ?? COUNTER_PROGRAM_ADDRESS ;
188
194
189
195
// Original accounts.
190
196
const originalAccounts = {
@@ -210,7 +216,7 @@ export function getIncrementInstruction<
210
216
args as IncrementInstructionDataArgs
211
217
) ,
212
218
} as IncrementInstruction <
213
- typeof COUNTER_PROGRAM_ADDRESS ,
219
+ TProgramAddress ,
214
220
TAccountCounter ,
215
221
TAccountAuthority
216
222
> ;
0 commit comments