@@ -10,7 +10,11 @@ import type {
10
10
SmartWalletTransactionData ,
11
11
} from "../../programs" ;
12
12
import type { GokiSDK } from "../../sdk" ;
13
- import { findTransactionAddress , findWalletDerivedAddress } from "./pda" ;
13
+ import {
14
+ findOwnerInvokerAddress ,
15
+ findTransactionAddress ,
16
+ findWalletDerivedAddress ,
17
+ } from "./pda" ;
14
18
import type {
15
19
InitSmartWalletWrapperArgs ,
16
20
NewTransactionArgs ,
@@ -173,6 +177,15 @@ export class SmartWalletWrapper {
173
177
return await findWalletDerivedAddress ( this . key , index ) ;
174
178
}
175
179
180
+ /**
181
+ * Finds the owner invoker address and bump of a given index.
182
+ * @param index
183
+ * @returns
184
+ */
185
+ async findOwnerInvokerAddress ( index : number ) : Promise < [ PublicKey , number ] > {
186
+ return await findOwnerInvokerAddress ( this . key , index ) ;
187
+ }
188
+
176
189
private async _fetchExecuteTransactionContext ( {
177
190
transactionKey,
178
191
owner = this . provider . wallet . publicKey ,
@@ -238,6 +251,51 @@ export class SmartWalletWrapper {
238
251
return new TransactionEnvelope ( this . provider , [ ix ] ) ;
239
252
}
240
253
254
+ /**
255
+ * Executes a transaction using an owner invoker address.
256
+ */
257
+ async ownerInvokeInstruction ( {
258
+ instruction,
259
+ index,
260
+ owner = this . provider . wallet . publicKey ,
261
+ } : {
262
+ instruction : TransactionInstruction ;
263
+ index : number ;
264
+ owner ?: PublicKey ;
265
+ } ) : Promise < TransactionEnvelope > {
266
+ const [ invokerAddress , invokerBump ] = await this . findOwnerInvokerAddress (
267
+ index
268
+ ) ;
269
+ const ix = this . program . instruction . ownerInvokeInstruction (
270
+ new BN ( index ) ,
271
+ invokerBump ,
272
+ instruction ,
273
+ {
274
+ accounts : {
275
+ smartWallet : this . key ,
276
+ owner,
277
+ } ,
278
+ remainingAccounts : [
279
+ {
280
+ pubkey : instruction . programId ,
281
+ isSigner : false ,
282
+ isWritable : false ,
283
+ } ,
284
+ ...instruction . keys . map ( ( k ) => {
285
+ if ( k . isSigner && invokerAddress . equals ( k . pubkey ) ) {
286
+ return {
287
+ ...k ,
288
+ isSigner : false ,
289
+ } ;
290
+ }
291
+ return k ;
292
+ } ) ,
293
+ ] ,
294
+ }
295
+ ) ;
296
+ return new TransactionEnvelope ( this . provider , [ ix ] ) ;
297
+ }
298
+
241
299
/**
242
300
* setOwners
243
301
*/
0 commit comments