-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pw/refinance-portfolio-support-fix (#3941)
* removed LUSD from emode stablecoin tokens list * wip * Added Morpho support * Debug cleanup * wip * cleanup * Fixed review comments * Fixed
- Loading branch information
1 parent
12334c4
commit 7c109f3
Showing
18 changed files
with
290 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
features/refinance/ethCorrelatedUpperCase.ts → ...res/refinance/emodeEthCorrelatedTokens.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const emodeStablecoinTokensUpperCase = [ | ||
'ADAI', | ||
'AETHDAI', | ||
'AETHLUSD', | ||
'AETHPYUSD', | ||
'AETHSDAI', | ||
'AETHUSDC', | ||
'AETHUSDT', | ||
'AUSDC', | ||
'AUSDT', | ||
'CDAI', | ||
'CRVUSD', | ||
'CUSDC', | ||
'CUSDCV3', | ||
'DAI', | ||
'FRAX', | ||
'GHO', | ||
'GUSD', | ||
'PYUSD', | ||
'SDAI', | ||
'SUSD', | ||
'SUSDE', | ||
'USDC.E', | ||
'USDC', | ||
'USDE', | ||
'USDT', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
103 changes: 103 additions & 0 deletions
103
handlers/portfolio/positions/handlers/aave-like/getRawPositionDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { RiskRatio } from '@oasisdex/dma-library' | ||
import { getChainInfoByChainId } from '@summer_fi/summerfi-sdk-common' | ||
import BigNumber from 'bignumber.js' | ||
import { NetworkIds, type NetworkNames } from 'blockchain/networks' | ||
import type { OmniProductType } from 'features/omni-kit/types' | ||
import { getAaveLikePoolId, getAaveLikePositionId } from 'features/refinance/helpers' | ||
import { getEmode } from 'features/refinance/helpers/getEmode' | ||
import { mapTokenToSdkToken } from 'features/refinance/helpers/mapTokenToSdkToken' | ||
import type { TokensPricesList } from 'handlers/portfolio/positions/helpers' | ||
import type { DpmSubgraphData } from 'handlers/portfolio/positions/helpers/getAllDpmsForWallet' | ||
import type { PortfolioPosition } from 'handlers/portfolio/types' | ||
import { zero } from 'helpers/zero' | ||
import type { LendingProtocol } from 'lendingProtocols' | ||
|
||
export function getRawPositionDetails( | ||
dpm: DpmSubgraphData, | ||
calculations: { | ||
collateral: BigNumber | ||
debt: BigNumber | ||
buyingPower: BigNumber | ||
netValue: BigNumber | ||
netValueInCollateralToken: BigNumber | ||
netValueInDebtToken: BigNumber | ||
totalExposure: BigNumber | ||
netBorrowCostPercentage: BigNumber | ||
collateralLiquidityRate: BigNumber | ||
debtVariableBorrowRate: BigNumber | ||
}, | ||
liquidationPrice: string, | ||
primaryTokenPrice: BigNumber, | ||
secondaryTokenPrice: BigNumber, | ||
onChainPositionData: any, | ||
commonData: { | ||
positionId: string | number | ||
type: OmniProductType | ||
network: NetworkNames | ||
protocol: LendingProtocol | ||
primaryToken: string | ||
secondaryToken: string | ||
url: string | ||
automations: { | ||
autoBuy?: { enabled: boolean; price?: number | undefined } | undefined | ||
autoSell?: { enabled: boolean; price?: number | undefined } | undefined | ||
constantMultiple?: { enabled: boolean; price?: number | undefined } | undefined | ||
stopLoss?: { enabled: boolean; price?: number | undefined } | undefined | ||
takeProfit?: { enabled: boolean; price?: number | undefined } | undefined | ||
} | ||
availableToRefinance: boolean | ||
}, | ||
lendingProtocol: LendingProtocol, | ||
prices: TokensPricesList, | ||
) { | ||
const chainFamily = getChainInfoByChainId(dpm.networkId) | ||
if (!chainFamily) { | ||
throw new Error(`ChainId ${NetworkIds.MAINNET} is not supported`) | ||
} | ||
const collateral = calculations.collateral | ||
const debt = calculations.debt | ||
const collateralPrice = primaryTokenPrice.toString() | ||
const debtPrice = secondaryTokenPrice.toString() | ||
|
||
const riskRatio = new RiskRatio( | ||
Number(collateral) > 0 | ||
? new BigNumber(debt).times(debtPrice).div(new BigNumber(collateral).times(collateralPrice)) | ||
: zero, | ||
RiskRatio.TYPE.LTV, | ||
) | ||
|
||
const borrowRate = calculations.netBorrowCostPercentage | ||
const maxRiskRatio = new RiskRatio( | ||
onChainPositionData.category.maxLoanToValue, | ||
RiskRatio.TYPE.LTV, | ||
) | ||
|
||
const collateralToken = mapTokenToSdkToken(chainFamily.chainInfo, commonData.primaryToken) | ||
const debtToken = mapTokenToSdkToken(chainFamily.chainInfo, commonData.secondaryToken) | ||
const emodeType = getEmode(collateralToken, debtToken) | ||
|
||
const poolId = getAaveLikePoolId( | ||
lendingProtocol, | ||
chainFamily.chainInfo, | ||
collateralToken, | ||
debtToken, | ||
emodeType, | ||
) | ||
const positionId = getAaveLikePositionId(lendingProtocol, dpm.vaultId) | ||
|
||
const rawPositionDetails: PortfolioPosition['rawPositionDetails'] = { | ||
collateralAmount: collateral.toString(), | ||
debtAmount: debt.toString(), | ||
collateralPrice, | ||
debtPrice, | ||
ethPrice: prices['ETH'].toString(), | ||
liquidationPrice: liquidationPrice, | ||
ltv: riskRatio.loanToValue.toString(), | ||
maxLtv: maxRiskRatio.loanToValue.toString(), | ||
borrowRate: borrowRate.toString(), | ||
positionId, | ||
poolId, | ||
pairId: 1, // TODO: investigate what used for | ||
} | ||
return rawPositionDetails | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.