import { MarketsAccount , StateAccount } from '../types' ; import BN from 'bn.js' ; import { Connection } from '@solana/web3.js' ; param connection param state param marketsAccount returns export async function calculateInsuranceFundSize ( connection , state , marketsAccount ) { const insuranceVaultPublicKey = state . insuranceVault ; const insuranceVaultAmount = new BN ( ( await connection . getTokenAccountBalance ( insuranceVaultPublicKey ) ) . value . amount ) ; return marketsAccount . markets . reduce ( ( insuranceVaultAmount , market ) => { return insuranceVaultAmount . add ( market . amm . totalFee . div ( new BN ( 2 ) ) ) ; } , insuranceVaultAmount ) ; }