@@ -6,9 +6,11 @@ import {
66 BN ,
77 ExchangeStatus ,
88 getPythLazerOraclePublicKey ,
9+ getTokenAmount ,
910 loadKeypair ,
1011 OracleGuardRails ,
1112 OracleSource ,
13+ SpotBalanceType ,
1214 TestClient ,
1315 Wallet ,
1416} from '../sdk/src' ;
@@ -19,13 +21,15 @@ import {
1921 initializeQuoteSpotMarket ,
2022 mockOracleNoProgram ,
2123 mockUSDCMint ,
24+ mockUserUSDCAccount ,
2225} from './testHelpers' ;
2326import { PublicKey } from '@solana/web3.js' ;
2427import {
2528 BankrunContextWrapper ,
2629 Connection ,
2730} from '../sdk/src/bankrun/bankrunConnection' ;
2831import { TestBulkAccountLoader } from '../sdk/src/accounts/testBulkAccountLoader' ;
32+ import { createTransferCheckedInstruction } from '@solana/spl-token' ;
2933
3034describe ( 'admin' , ( ) => {
3135 const chProgram = anchor . workspace . Drift as Program ;
@@ -36,6 +40,10 @@ describe('admin', () => {
3640
3741 let usdcMint ;
3842
43+ let userUSDCAccount ;
44+
45+ const usdcAmount = new BN ( 10 * 10 ** 6 ) ;
46+
3947 let bankrunContextWrapper : BankrunContextWrapper ;
4048
4149 before ( async ( ) => {
@@ -72,6 +80,13 @@ describe('admin', () => {
7280 } ,
7381 } ) ;
7482
83+ userUSDCAccount = await mockUserUSDCAccount (
84+ usdcMint ,
85+ usdcAmount ,
86+ bankrunContextWrapper ,
87+ driftClient . wallet . publicKey
88+ ) ;
89+
7590 await driftClient . initialize ( usdcMint . publicKey , true ) ;
7691 await driftClient . subscribe ( ) ;
7792 await driftClient . initializeUserAccount ( 0 ) ;
@@ -457,6 +472,38 @@ describe('admin', () => {
457472 assert ( perpMarket . amm . ammSpreadAdjustment == ammSpreadAdjustment ) ;
458473 } ) ;
459474
475+ it ( 'update pnl pool' , async ( ) => {
476+ const quoteVault = driftClient . getSpotMarketAccount ( 0 ) . vault ;
477+
478+ const splTransferIx = createTransferCheckedInstruction (
479+ userUSDCAccount . publicKey ,
480+ usdcMint . publicKey ,
481+ quoteVault ,
482+ driftClient . wallet . publicKey ,
483+ usdcAmount . toNumber ( ) ,
484+ 6
485+ ) ;
486+
487+ const tx = await driftClient . buildTransaction ( splTransferIx ) ;
488+ // @ts -ignore
489+ await driftClient . sendTransaction ( tx ) ;
490+
491+ await driftClient . updatePerpMarketPnlPool ( 0 , usdcAmount ) ;
492+
493+ await driftClient . fetchAccounts ( ) ;
494+
495+ const perpMarket = driftClient . getPerpMarketAccount ( 0 ) ;
496+ const spotMarket = driftClient . getSpotMarketAccount ( 0 ) ;
497+
498+ const tokenAmount = getTokenAmount (
499+ perpMarket . pnlPool . scaledBalance ,
500+ spotMarket ,
501+ SpotBalanceType . DEPOSIT
502+ ) ;
503+
504+ assert ( tokenAmount . eq ( usdcAmount ) ) ;
505+ } ) ;
506+
460507 it ( 'Update admin' , async ( ) => {
461508 const newAdminKey = PublicKey . default ;
462509
0 commit comments