@@ -1283,4 +1283,112 @@ where
1283
1283
)
1284
1284
. await
1285
1285
}
1286
+
1287
+ /// Withdraw withheld confidential tokens from mint
1288
+ pub async fn confidential_transfer_withdraw_withheld_tokens_from_mint < S2 : Signer > (
1289
+ & self ,
1290
+ withdraw_withheld_authority : & S2 ,
1291
+ withdraw_withheld_authority_elgamal_keypair : & ElGamalKeypair ,
1292
+ destination_token_account : & Pubkey ,
1293
+ amount : u64 ,
1294
+ ) -> TokenResult < T :: Output > {
1295
+ let mint_state = self . get_mint_info ( ) . await . unwrap ( ) ;
1296
+
1297
+ let ct_mint = mint_state
1298
+ . get_extension :: < confidential_transfer:: ConfidentialTransferMint > ( )
1299
+ . unwrap ( ) ;
1300
+
1301
+ let destination_state = self
1302
+ . get_account_info ( destination_token_account)
1303
+ . await
1304
+ . unwrap ( ) ;
1305
+ let destination_extension = destination_state
1306
+ . get_extension :: < confidential_transfer:: ConfidentialTransferAccount > (
1307
+ ) ?;
1308
+
1309
+ let proof_data = confidential_transfer:: instruction:: WithdrawWithheldTokensData :: new (
1310
+ withdraw_withheld_authority_elgamal_keypair,
1311
+ & destination_extension. encryption_pubkey . try_into ( ) . unwrap ( ) ,
1312
+ & ct_mint. withheld_amount . try_into ( ) . unwrap ( ) ,
1313
+ amount,
1314
+ )
1315
+ . map_err ( TokenError :: Proof ) ?;
1316
+
1317
+ self . process_ixs (
1318
+ & confidential_transfer:: instruction:: withdraw_withheld_tokens_from_mint (
1319
+ & self . program_id ,
1320
+ & self . pubkey ,
1321
+ destination_token_account,
1322
+ & withdraw_withheld_authority. pubkey ( ) ,
1323
+ & [ ] ,
1324
+ & proof_data,
1325
+ ) ?,
1326
+ & [ withdraw_withheld_authority] ,
1327
+ )
1328
+ . await
1329
+ }
1330
+
1331
+ /// Withdraw withheld confidential tokens from accounts
1332
+ pub async fn confidential_transfer_withdraw_withheld_tokens_from_accounts < S2 : Signer > (
1333
+ & self ,
1334
+ withdraw_withheld_authority : & S2 ,
1335
+ withdraw_withheld_authority_elgamal_keypair : & ElGamalKeypair ,
1336
+ destination_token_account : & Pubkey ,
1337
+ amount : u64 ,
1338
+ sources : & [ & Pubkey ] ,
1339
+ ) -> TokenResult < T :: Output > {
1340
+ let mint_state = self . get_mint_info ( ) . await . unwrap ( ) ;
1341
+
1342
+ let ct_mint = mint_state
1343
+ . get_extension :: < confidential_transfer:: ConfidentialTransferMint > ( )
1344
+ . unwrap ( ) ;
1345
+
1346
+ let destination_state = self
1347
+ . get_account_info ( destination_token_account)
1348
+ . await
1349
+ . unwrap ( ) ;
1350
+ let destination_extension = destination_state
1351
+ . get_extension :: < confidential_transfer:: ConfidentialTransferAccount > (
1352
+ ) ?;
1353
+
1354
+ let proof_data = confidential_transfer:: instruction:: WithdrawWithheldTokensData :: new (
1355
+ withdraw_withheld_authority_elgamal_keypair,
1356
+ & destination_extension. encryption_pubkey . try_into ( ) . unwrap ( ) ,
1357
+ & ct_mint. withheld_amount . try_into ( ) . unwrap ( ) ,
1358
+ amount,
1359
+ )
1360
+ . map_err ( TokenError :: Proof ) ?;
1361
+
1362
+ self . process_ixs (
1363
+ & confidential_transfer:: instruction:: withdraw_withheld_tokens_from_accounts (
1364
+ & self . program_id ,
1365
+ & self . pubkey ,
1366
+ destination_token_account,
1367
+ & withdraw_withheld_authority. pubkey ( ) ,
1368
+ & [ ] ,
1369
+ sources,
1370
+ & proof_data,
1371
+ ) ?,
1372
+ & [ withdraw_withheld_authority] ,
1373
+ )
1374
+ . await
1375
+ }
1376
+
1377
+ /// Harvest withheld confidential tokens to mint
1378
+ pub async fn confidential_transfer_harvest_withheld_tokens_to_mint < S2 : Signer > (
1379
+ & self ,
1380
+ sources : & [ & Pubkey ] ,
1381
+ ) -> TokenResult < T :: Output > {
1382
+ self . process_ixs :: < [ & dyn Signer ; 0 ] > (
1383
+ & [
1384
+ confidential_transfer:: instruction:: harvest_withheld_tokens_to_mint (
1385
+ & self . program_id ,
1386
+ & self . pubkey ,
1387
+ sources,
1388
+ ) ?,
1389
+ ] ,
1390
+ & [ ] ,
1391
+ )
1392
+ . await
1393
+ }
1286
1394
}
0 commit comments