-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: WIP spark protocol data * feat: implement spark protocol data layer * feat: finish implementing spark view layer * feat: fix op resolver and implement aave-like payback-withdraw * fix: aave strategy exports * feat: add payback-withdraw strategy into aave/spark * chore: fix linting issues
- Loading branch information
Showing
31 changed files
with
549 additions
and
246 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import BigNumber from 'bignumber.js' | ||
|
||
export type PriceResult = BigNumber | undefined | ||
export type ReserveDataResult = any |
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,73 @@ | ||
import { Address } from '@deploy-configurations/types/address' | ||
import { AaveLikeProtocol as AaveLikeProtocolContracts } from '@deploy-configurations/types/deployment-config' | ||
import { amountFromWei } from '@dma-common/utils/common' | ||
import { AaveLikeStrategyAddresses } from '@dma-library/operations/aave-like' | ||
import { PriceResult, ReserveDataResult } from '@dma-library/protocols/aave-like/types' | ||
import { AaveLikeProtocol } from '@dma-library/types/protocol' | ||
import { getAbiForContract } from '@dma-library/utils/abis/get-abi-for-contract' | ||
import BigNumber from 'bignumber.js' | ||
import { Contract, ethers, providers } from 'ethers' | ||
|
||
export function determineReserveEModeCategory( | ||
collateralEModeCategoryResult: number, | ||
debtEModeCategoryResult: number, | ||
): number { | ||
const collateralEModeCategory = Number(collateralEModeCategoryResult.toString()) | ||
const debtEModeCategory = Number(debtEModeCategoryResult.toString()) | ||
|
||
if (collateralEModeCategory === debtEModeCategory) { | ||
return collateralEModeCategory | ||
} | ||
return 0 | ||
} | ||
|
||
export async function getContract( | ||
address: Address, | ||
contractName: AaveLikeProtocolContracts, | ||
provider: providers.Provider, | ||
protocol: AaveLikeProtocol, | ||
): Promise<Contract> { | ||
const abi = await getAbiForContract(contractName, provider, protocol) | ||
return new ethers.Contract(address, abi, provider) | ||
} | ||
|
||
export async function fetchAssetPrice( | ||
priceOracle: Contract, | ||
tokenAddress?: string, | ||
): Promise<PriceResult> { | ||
if (!tokenAddress) return undefined | ||
const amount: ethers.BigNumberish = await priceOracle.getAssetPrice(tokenAddress) | ||
return amountFromWei(new BigNumber(amount.toString())) | ||
} | ||
|
||
export async function fetchReserveData( | ||
dataProvider: Contract, | ||
tokenAddress?: string, | ||
): Promise<ReserveDataResult> { | ||
if (!tokenAddress) return undefined | ||
return dataProvider.getReserveConfigurationData(tokenAddress) | ||
} | ||
|
||
export async function fetchUserReserveData( | ||
dataProvider: Contract, | ||
tokenAddress: string, | ||
proxy: string, | ||
): Promise<ReserveDataResult> { | ||
return dataProvider.getUserReserveData(tokenAddress, proxy) | ||
} | ||
|
||
export async function getAaveLikeSystemContracts( | ||
addresses: AaveLikeStrategyAddresses, | ||
provider: providers.Provider, | ||
protocol: AaveLikeProtocol, | ||
) { | ||
const oracle = await getContract(addresses.oracle, 'Oracle', provider, protocol) | ||
const poolDataProvider = await getContract( | ||
addresses.poolDataProvider, | ||
'PoolDataProvider', | ||
provider, | ||
protocol, | ||
) | ||
const pool = await getContract(addresses.lendingPool, 'LendingPool', provider, protocol) | ||
return { oracle, poolDataProvider, pool } | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { | ||
AaveProtocolData, | ||
AaveProtocolDataArgs, | ||
GetAaveProtocolData, | ||
getAaveProtocolData, | ||
} from './get-aave-protocol-data' |
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 |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import { AaveProtocolData, AaveProtocolDataArgs, getAaveProtocolData } from './aave' | ||
import { | ||
AaveProtocolData, | ||
AaveProtocolDataArgs, | ||
GetAaveProtocolData, | ||
getAaveProtocolData, | ||
} from './aave' | ||
import { calculateAjnaApyPerDays } from './ajna' | ||
import { | ||
GetSparkProtocolData, | ||
getSparkProtocolData, | ||
SparkProtocolData, | ||
SparkProtocolDataArgs, | ||
} from './spark' | ||
|
||
const aave: { | ||
getAaveProtocolData: typeof getAaveProtocolData | ||
getAaveProtocolData: GetAaveProtocolData | ||
} = { | ||
getAaveProtocolData, | ||
} | ||
|
||
export { AaveProtocolData, AaveProtocolDataArgs } | ||
const spark: { | ||
getSparkProtocolData: GetSparkProtocolData | ||
} = { | ||
getSparkProtocolData, | ||
} | ||
|
||
export const protocols = { | ||
aave, | ||
spark, | ||
} | ||
|
||
export { AaveProtocolData, AaveProtocolDataArgs } | ||
export { SparkProtocolData, SparkProtocolDataArgs } | ||
|
||
export { calculateAjnaApyPerDays } | ||
export { calculateAjnaMaxLiquidityWithdraw, getAjnaLiquidationPrice } from './ajna/index' |
Oops, something went wrong.