Skip to content

Commit

Permalink
Aave isolated collateral support (#3985)
Browse files Browse the repository at this point in the history
  • Loading branch information
piekczyk authored Jul 10, 2024
1 parent 94963df commit 09c7e39
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion actions/aave-like/adjust/get-adjust-position-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getAdjustPositionParameters({
multiple: riskRatio,
debtToken: debtToken,
collateralToken: collateralToken,
flashloan: getAaveV3FlashLoanToken(networkId, protocol),
flashloan: getAaveV3FlashLoanToken(networkId, protocol, collateralToken.symbol),
}

const stratDeps: Omit<AaveLikeAdjustStrategyDeps, 'addresses' | 'getSwapData'> = {
Expand Down
2 changes: 1 addition & 1 deletion actions/aave-like/close/get-close-aave-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function getCloseAaveParameters({
debtToken,
collateralToken,
shouldCloseToCollateral,
flashloan: getAaveV3FlashLoanToken(networkId, protocol),
flashloan: getAaveV3FlashLoanToken(networkId, protocol, collateralToken.symbol),
}

const stratDeps: Omit<AaveLikeCloseStrategyDeps, 'addresses' | 'getSwapData'> = {
Expand Down
33 changes: 19 additions & 14 deletions actions/aave-like/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ import { getLocalAppConfig } from 'helpers/config'
import { getOneInchCall } from 'helpers/swap'
import { LendingProtocol } from 'lendingProtocols'

// enum Network {
// MAINNET = "mainnet",
// GOERLI = "goerli",
// HARDHAT = "hardhat",
// OPTIMISM = "optimism",
// ARBITRUM = "arbitrum",
// LOCAL = "local"
// }

export function networkIdToLibraryNetwork(networkId: NetworkIds): Network {
switch (networkId) {
case NetworkIds.MAINNET:
Expand Down Expand Up @@ -90,27 +81,41 @@ export const getCurrentPositionLibCallData = (currentPosition: IPosition) => [
export const getAaveV3FlashLoanToken = (
networkId: NetworkIds,
lendingProtocol: LendingProtocol,
collateralToken: string,
) => {
if (lendingProtocol !== LendingProtocol.AaveV3) {
return undefined
}
const flashloanTokensConfig = getLocalAppConfig('parameters').aaveLike.flashLoanTokens
const isolatedCollateralTokensConfig =
getLocalAppConfig('parameters').aaveLike.isolatedCollateralTokens
const aaveV3FlashLoanTokenMap = {
[NetworkIds.OPTIMISMMAINNET]: flashloanTokensConfig.OPTIMISMMAINNET,
[NetworkIds.BASEMAINNET]: flashloanTokensConfig.BASEMAINNET,
} as Record<Partial<NetworkIds>, keyof AaveLikeStrategyAddresses['tokens']>
const flashloanToken = aaveV3FlashLoanTokenMap[networkId]
const addressesV3 = getAddresses(networkId, LendingProtocol.AaveV3)

if (flashloanToken) {
const tokenAddress = addressesV3.tokens[flashloanToken]
// isolated collaterals does not allow to deposit other tokens (from FL) as collateral
// therefore we need to use isolated collateral as FL token
const isIsolatedCollateral = isolatedCollateralTokensConfig.includes(
collateralToken.toUpperCase(),
)

const resolvedFlashLoanToken = (
isIsolatedCollateral ? collateralToken.toUpperCase() : flashloanToken
) as keyof AaveLikeStrategyAddresses['tokens']

if (resolvedFlashLoanToken) {
const tokenAddress = addressesV3.tokens[resolvedFlashLoanToken]
if (tokenAddress === undefined)
throw new Error(`Flashloan Token ${flashloanToken} address is undefined`)
throw new Error(`Flashloan Token ${resolvedFlashLoanToken} address is undefined`)

return {
token: {
symbol: flashloanToken,
symbol: resolvedFlashLoanToken,
address: tokenAddress,
precision: getToken(flashloanToken).precision,
precision: getToken(resolvedFlashLoanToken).precision,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion actions/aave-like/open/get-open-position-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function openPosition(
multiple: riskRatio,
debtToken: debtToken,
collateralToken: collateralToken,
flashloan: getAaveV3FlashLoanToken(networkId, protocol),
flashloan: getAaveV3FlashLoanToken(networkId, protocol, collateralToken.symbol),
depositedByUser: {
collateralInWei: depositedByUser.collateralToken?.amountInBaseUnit,
debtInWei: depositedByUser.debtToken?.amountInBaseUnit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const getAaveLikeParameters = async ({
symbol: collateralToken as AaveLikeTokens,
precision: collateralPrecision,
},
flashloan: getAaveV3FlashLoanToken(networkId, protocol),
flashloan: getAaveV3FlashLoanToken(networkId, protocol, collateralToken),
}

switch (action) {
Expand Down
1 change: 1 addition & 0 deletions features/omni-kit/protocols/aave/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const settingsV3: OmniProtocolSettings = {
'SDAI',
'GHO',
'WBTC',
'MKR',
'LDO',
'USDT',
'LINK',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,18 @@ export const aaveV3EthereumMainnetProductHubProducts: ProductHubItemWithoutAddre
network: NetworkNames.ethereumMainnet,
protocol: LendingProtocol.AaveV3,
},
{
product: [OmniProductType.Multiply],
primaryToken: 'MKR',
primaryTokenGroup: getTokenGroup('MKR'),
secondaryToken: 'DAI',
depositToken: 'MKR',
label: 'MKR/DAI',
multiplyStrategyType: 'long',
multiplyStrategy: 'Long MKR',
network: NetworkNames.ethereumMainnet,
protocol: LendingProtocol.AaveV3,
},
{
product: [OmniProductType.Borrow],
primaryToken: 'MKR',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@metamask/eth-sig-util": "^5.0.2",
"@oasisdex/addresses": "0.1.75",
"@oasisdex/automation": "1.6.5-morpho.6",
"@oasisdex/dma-library": "0.6.59",
"@oasisdex/dma-library": "0.6.60",
"@oasisdex/multiply": "^0.2.11",
"@oasisdex/transactions": "0.1.4-alpha.0",
"@oasisdex/utils": "^0.0.8",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2514,10 +2514,10 @@
dependencies:
ethers "^5.6.2"

"@oasisdex/dma-library@0.6.59":
version "0.6.59"
resolved "https://registry.yarnpkg.com/@oasisdex/dma-library/-/dma-library-0.6.59.tgz#994c85b4b472a9895244a9b5624d15275add2c4a"
integrity sha512-sJMJcC3la/KQepvYj3T4jCssoxD8fWJxdQQi5E+W0xx+ImMLIl43XwdSxVcFI9iXji1mHkYjvMtGG2OGEJBDHA==
"@oasisdex/dma-library@0.6.60":
version "0.6.60"
resolved "https://registry.yarnpkg.com/@oasisdex/dma-library/-/dma-library-0.6.60.tgz#db4ab89d2e695eabda30bf8865b5e94af95c44ee"
integrity sha512-xmlBXvV4v3gCGvPzoCHzjDkszkuEWvDrCUZCYiKbDFeJeYNrdAk2v6qlqL33MpQTwbqej2Y3lYUQrCy5Wc1D3A==
dependencies:
bignumber.js "9.0.1"
ethers "^5.7.2"
Expand Down

0 comments on commit 09c7e39

Please sign in to comment.