@@ -52,6 +52,7 @@ import {
5252 mockOracleNoProgram ,
5353 mockUSDCMint ,
5454 mockUserUSDCAccountWithAuthority ,
55+ overWriteMintAccount ,
5556 overWritePerpMarket ,
5657 overWriteSpotMarket ,
5758} from './testHelpers' ;
@@ -924,14 +925,69 @@ describe('LP Pool', () => {
924925 getConstituentPublicKey ( program . programId , lpPoolKey , 0 )
925926 ) ) as ConstituentAccount ;
926927
928+ let lpPool = ( await adminClient . program . account . lpPool . fetch (
929+ lpPoolKey
930+ ) ) as LPPoolAccount ;
931+
927932 assert ( ammCache . cache [ 0 ] . quoteOwedFromLp . eq ( owedAmount . divn ( 2 ) ) ) ;
928933 assert ( constituent . tokenBalance . eq ( ZERO ) ) ;
934+ assert ( lpPool . lastAum . eq ( ZERO ) ) ;
935+
936+ // Deposit here to DLP to make sure aum calc work with perp market debt
937+ await overWriteMintAccount (
938+ bankrunContextWrapper ,
939+ lpPool . mint ,
940+ BigInt ( lpPool . lastAum . toNumber ( ) )
941+ ) ;
942+ await adminClient . lpPoolAddLiquidity ( {
943+ lpPool,
944+ inAmount : new BN ( 1000 ) . mul ( QUOTE_PRECISION ) ,
945+ minMintAmount : new BN ( 1 ) ,
946+ inMarketIndex : 0 ,
947+ } ) ;
948+
949+ await adminClient . updateLpPoolAum ( lpPool , [ 0 , 1 , 2 ] ) ;
950+
951+ lpPool = ( await adminClient . program . account . lpPool . fetch (
952+ lpPoolKey
953+ ) ) as LPPoolAccount ;
954+
955+ let aum = new BN ( 0 ) ;
956+ for ( let i = 0 ; i <= 2 ; i ++ ) {
957+ const constituent = ( await adminClient . program . account . constituent . fetch (
958+ getConstituentPublicKey ( program . programId , lpPoolKey , i )
959+ ) ) as ConstituentAccount ;
960+ aum = aum . add (
961+ constituent . tokenBalance
962+ . mul ( constituent . lastOraclePrice )
963+ . div ( QUOTE_PRECISION )
964+ ) ;
965+ }
966+
967+ // Overwrite the amm cache with amount owed
968+ ammCache = ( await adminClient . program . account . ammCache . fetch (
969+ getAmmCachePublicKey ( program . programId )
970+ ) ) as AmmCache ;
971+ for ( let i = 0 ; i <= ammCache . cache . length - 1 ; i ++ ) {
972+ aum = aum . sub ( ammCache . cache [ i ] . quoteOwedFromLp ) ;
973+ }
974+ assert ( lpPool . lastAum . eq ( aum ) ) ;
929975 } ) ;
930976
931977 it ( 'perp market will transfer with the constituent vault if it should send more than its owed' , async ( ) => {
978+ let lpPool = ( await adminClient . program . account . lpPool . fetch (
979+ lpPoolKey
980+ ) ) as LPPoolAccount ;
981+ const aumBefore = lpPool . lastAum ;
982+ let constituent = ( await adminClient . program . account . constituent . fetch (
983+ getConstituentPublicKey ( program . programId , lpPoolKey , 0 )
984+ ) ) as ConstituentAccount ;
985+
932986 let ammCache = ( await adminClient . program . account . ammCache . fetch (
933987 getAmmCachePublicKey ( program . programId )
934988 ) ) as AmmCache ;
989+
990+ const balanceBefore = constituent . tokenBalance ;
935991 const owedAmount = ammCache . cache [ 0 ] . quoteOwedFromLp ;
936992
937993 // Give the perp market half of its owed amount
@@ -954,11 +1010,16 @@ describe('LP Pool', () => {
9541010 ammCache = ( await adminClient . program . account . ammCache . fetch (
9551011 getAmmCachePublicKey ( program . programId )
9561012 ) ) as AmmCache ;
957- const constituent = ( await adminClient . program . account . constituent . fetch (
1013+ constituent = ( await adminClient . program . account . constituent . fetch (
9581014 getConstituentPublicKey ( program . programId , lpPoolKey , 0 )
9591015 ) ) as ConstituentAccount ;
9601016
1017+ lpPool = ( await adminClient . program . account . lpPool . fetch (
1018+ lpPoolKey
1019+ ) ) as LPPoolAccount ;
1020+
9611021 assert ( ammCache . cache [ 0 ] . quoteOwedFromLp . eq ( ZERO ) ) ;
962- assert ( constituent . tokenBalance . eq ( owedAmount ) ) ;
1022+ assert ( constituent . tokenBalance . eq ( balanceBefore . add ( owedAmount ) ) ) ;
1023+ assert ( lpPool . lastAum . eq ( aumBefore . add ( owedAmount ) ) ) ;
9631024 } ) ;
9641025} ) ;
0 commit comments