Skip to content

Commit

Permalink
unify get pool apy
Browse files Browse the repository at this point in the history
  • Loading branch information
shan57blocks committed Oct 30, 2024
1 parent 01e4ebd commit 62a734b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
6 changes: 1 addition & 5 deletions packages/huma-shared/src/solana/utils/poolUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ export const getSolanaPoolApy = (
defaultMaxSeniorJuniorRatio: number,
fixedSeniorYieldInBps: number,
tranchesRiskAdjustmentInBps: number,
): {
blendedApy: number
seniorTrancheApy: number
juniorTrancheApy: number
} =>
) =>
getPoolApyV2(
protocolFeeInBps,
yieldInBps,
Expand Down
56 changes: 55 additions & 1 deletion packages/huma-shared/src/utils/apy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getFlcTotalAssetsAfterRisk = (
return flcTotalAssetsAfterRisk
}

export const getPoolApyV2 = (
const getPoolApyV2Base = (
protocolFeeInBps: number,
yieldInBps: number,
rewardRateInBpsForPoolOwner: number,
Expand Down Expand Up @@ -153,3 +153,57 @@ export const getPoolApyV2 = (
juniorTrancheApy,
}
}

export const getPoolApyV2 = (
protocolFeeInBps: number,
yieldInBps: number,
rewardRateInBpsForPoolOwner: number,
rewardRateInBpsForEA: number,
liquidityCap: string,
seniorDeployedAssets: string,
juniorDeployedAssets: string,
maxSeniorJuniorRatio: number,
fixedSeniorYieldInBps: number,
tranchesRiskAdjustmentInBps: number,
BP_FACTOR: number,
FirstLossCoverIndexes: string[] = [],
flcConfigs: FclConfig[] = [],
): PoolApy & { maxJuniorTrancheApy: number } => {
const realApyResult = getPoolApyV2Base(
protocolFeeInBps,
yieldInBps,
rewardRateInBpsForPoolOwner,
rewardRateInBpsForEA,
liquidityCap,
seniorDeployedAssets,
juniorDeployedAssets,
maxSeniorJuniorRatio,
fixedSeniorYieldInBps,
tranchesRiskAdjustmentInBps,
BP_FACTOR,
FirstLossCoverIndexes,
flcConfigs,
)

const liquidityCapBN = BigNumber.from(liquidityCap)
const juniorAssetsBN = liquidityCapBN.div(maxSeniorJuniorRatio + 1)
const seniorAssetsBN = liquidityCapBN.sub(juniorAssetsBN)
const maxJuniorApyResult = getPoolApyV2Base(
protocolFeeInBps,
yieldInBps,
rewardRateInBpsForPoolOwner,
rewardRateInBpsForEA,
liquidityCap,
seniorAssetsBN.toString(),
juniorAssetsBN.toString(),
maxSeniorJuniorRatio,
fixedSeniorYieldInBps,
tranchesRiskAdjustmentInBps,
BP_FACTOR,
)

return {
...realApyResult,
maxJuniorTrancheApy: maxJuniorApyResult.juniorTrancheApy,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type SolanaPoolState = {
rangeApy?: string
seniorTrancheApy?: number
juniorTrancheApy?: number
maxJuniorTrancheApy?: number
amountDefaulted?: number
amountOriginated?: number
amountRepaid?: number
Expand Down

0 comments on commit 62a734b

Please sign in to comment.