@@ -1075,7 +1075,10 @@ export class DriftClient {
1075
1075
async getInitializeUserStatsIx ( ) : Promise < TransactionInstruction > {
1076
1076
return await this . program . instruction . initializeUserStats ( {
1077
1077
accounts : {
1078
- userStats : this . getUserStatsAccountPublicKey ( ) ,
1078
+ userStats : getUserStatsAccountPublicKey (
1079
+ this . program . programId ,
1080
+ this . wallet . publicKey // only allow payer to initialize own user stats account
1081
+ ) ,
1079
1082
authority : this . wallet . publicKey ,
1080
1083
payer : this . wallet . publicKey ,
1081
1084
rent : anchor . web3 . SYSVAR_RENT_PUBKEY ,
@@ -8377,19 +8380,24 @@ export class DriftClient {
8377
8380
marketIndex
8378
8381
) ;
8379
8382
8383
+ const accounts = {
8384
+ insuranceFundStake : ifStakeAccountPublicKey ,
8385
+ spotMarket : this . getSpotMarketAccount ( marketIndex ) . pubkey ,
8386
+ userStats : getUserStatsAccountPublicKey (
8387
+ this . program . programId ,
8388
+ this . wallet . publicKey // only allow payer to initialize own insurance fund stake account
8389
+ ) ,
8390
+ authority : this . wallet . publicKey ,
8391
+ payer : this . wallet . publicKey ,
8392
+ rent : anchor . web3 . SYSVAR_RENT_PUBKEY ,
8393
+ systemProgram : anchor . web3 . SystemProgram . programId ,
8394
+ state : await this . getStatePublicKey ( ) ,
8395
+ } ;
8396
+
8380
8397
return await this . program . instruction . initializeInsuranceFundStake (
8381
8398
marketIndex ,
8382
8399
{
8383
- accounts : {
8384
- insuranceFundStake : ifStakeAccountPublicKey ,
8385
- spotMarket : this . getSpotMarketAccount ( marketIndex ) . pubkey ,
8386
- userStats : this . getUserStatsAccountPublicKey ( ) ,
8387
- authority : this . wallet . publicKey ,
8388
- payer : this . wallet . publicKey ,
8389
- rent : anchor . web3 . SYSVAR_RENT_PUBKEY ,
8390
- systemProgram : anchor . web3 . SystemProgram . programId ,
8391
- state : await this . getStatePublicKey ( ) ,
8392
- } ,
8400
+ accounts,
8393
8401
}
8394
8402
) ;
8395
8403
}
@@ -8417,7 +8425,10 @@ export class DriftClient {
8417
8425
state : await this . getStatePublicKey ( ) ,
8418
8426
spotMarket : spotMarket . pubkey ,
8419
8427
insuranceFundStake : ifStakeAccountPublicKey ,
8420
- userStats : this . getUserStatsAccountPublicKey ( ) ,
8428
+ userStats : getUserStatsAccountPublicKey (
8429
+ this . program . programId ,
8430
+ this . wallet . publicKey // only allow payer to add to own insurance fund stake account
8431
+ ) ,
8421
8432
authority : this . wallet . publicKey ,
8422
8433
spotMarketVault : spotMarket . vault ,
8423
8434
insuranceFundVault : spotMarket . insuranceFund . vault ,
@@ -8539,7 +8550,12 @@ export class DriftClient {
8539
8550
let tokenAccount ;
8540
8551
8541
8552
if (
8542
- ! ( await this . checkIfAccountExists ( this . getUserStatsAccountPublicKey ( ) ) )
8553
+ ! ( await this . checkIfAccountExists (
8554
+ getUserStatsAccountPublicKey (
8555
+ this . program . programId ,
8556
+ this . wallet . publicKey // only allow payer to initialize own user stats account
8557
+ )
8558
+ ) )
8543
8559
) {
8544
8560
addIfStakeIxs . push ( await this . getInitializeUserStatsIx ( ) ) ;
8545
8561
}
0 commit comments