@@ -221,49 +221,42 @@ export async function redeemDrt(
221
221
userDrtTokenAccount : PublicKey ,
222
222
userOwnershipTokenAccount : PublicKey ,
223
223
drtType : string ,
224
- wallet : any // Wallet from useWallet
224
+ wallet : any
225
225
) : Promise < string > {
226
226
const provider = program . provider as AnchorProvider ;
227
- const user = provider . wallet . publicKey ;
227
+ const user = wallet . publicKey ;
228
228
const connection = provider . connection ;
229
229
230
- // Compute vault PDA
231
230
const [ vaultPda ] = await PublicKey . findProgramAddress (
232
231
[ Buffer . from ( "vault" ) , pool . toBuffer ( ) ] ,
233
232
program . programId
234
233
) ;
235
234
236
- // Check if userDrtTokenAccount exists
237
235
const userDrtAccountInfo = await connection . getAccountInfo ( userDrtTokenAccount ) ;
238
236
const userOwnershipAccountInfo = await connection . getAccountInfo ( userOwnershipTokenAccount ) ;
239
237
240
238
const instructions : anchor . web3 . TransactionInstruction [ ] = [ ] ;
241
-
242
- // Create userDrtTokenAccount if it doesn’t exist
243
239
if ( ! userDrtAccountInfo ) {
244
240
console . log ( "Creating user DRT token account..." ) ;
245
241
const createDrtTokenAccountIx = createAssociatedTokenAccountInstruction (
246
- wallet . publicKey , // payer
247
- userDrtTokenAccount , // associated token account address
248
- wallet . publicKey , // owner
249
- drtMint // mint
242
+ wallet . publicKey ,
243
+ userDrtTokenAccount ,
244
+ wallet . publicKey ,
245
+ drtMint
250
246
) ;
251
247
instructions . push ( createDrtTokenAccountIx ) ;
252
248
}
253
-
254
- // Create userOwnershipTokenAccount if it doesn’t exist
255
249
if ( ! userOwnershipAccountInfo ) {
256
250
console . log ( "Creating user ownership token account..." ) ;
257
251
const createOwnershipTokenAccountIx = createAssociatedTokenAccountInstruction (
258
- wallet . publicKey , // payer
259
- userOwnershipTokenAccount , // associated token account address
260
- wallet . publicKey , // owner
261
- ownershipMint // mint
252
+ wallet . publicKey ,
253
+ userOwnershipTokenAccount ,
254
+ wallet . publicKey ,
255
+ ownershipMint
262
256
) ;
263
257
instructions . push ( createOwnershipTokenAccountIx ) ;
264
258
}
265
259
266
- // Execute the redeem_drt instruction with pre-instructions if needed
267
260
const tx = await program . methods
268
261
. redeemDrt ( drtType )
269
262
. accounts ( {
@@ -273,8 +266,7 @@ export async function redeemDrt(
273
266
userDrtTokenAccount,
274
267
userOwnershipTokenAccount,
275
268
vault : vaultPda ,
276
- owner : user , // Assuming user is the owner for simplicity; adjust if pool owner differs
277
- user,
269
+ user, // Only user signs
278
270
tokenProgram : TOKEN_PROGRAM_ID ,
279
271
} )
280
272
. preInstructions ( instructions )
0 commit comments