Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aave isolated collateral #693

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/dma-library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/dma-library",
"version": "0.6.59",
"version": "0.6.60",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,12 @@ export async function buildAdjustFlashloan(
dependencies: AaveLikeAdjustDependencies,
) {
const lendingProtocol = dependencies.protocolType
const flashloanProvider = resolveFlashloanProvider(
await getForkedNetwork(dependencies.provider),
const flashloanProvider = resolveFlashloanProvider({
network: await getForkedNetwork(dependencies.provider),
lendingProtocol,
args.debtToken.symbol,
)
debtToken: args.debtToken.symbol,
collateralToken: args.collateralToken.symbol,
})

if (dependencies.protocolType === 'Spark') {
// Need to add fees to the swap amount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ export async function buildCloseFlashloan(
dependencies: AaveLikeCloseDependencies,
): Promise<CloseFlashloanArgs> {
const lendingProtocol = dependencies.protocolType
const flashloanProvider = resolveFlashloanProvider(
await getForkedNetwork(dependencies.provider),
const flashloanProvider = resolveFlashloanProvider({
network: await getForkedNetwork(dependencies.provider),
lendingProtocol,
args.debtToken.symbol,
)
debtToken: args.debtToken.symbol,
collateralToken: args.collateralToken.symbol,
})

if (dependencies.protocolType === 'Spark') {
// This covers off the situation where debt balances accrue interest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ export async function buildOpenFlashloan(
dependencies: AaveLikeOpenDependencies,
) {
const lendingProtocol = dependencies.protocolType
const flashloanProvider = resolveFlashloanProvider(
await getForkedNetwork(dependencies.provider),
const flashloanProvider = resolveFlashloanProvider({
network: await getForkedNetwork(dependencies.provider),
lendingProtocol,
args.debtToken.symbol,
)
debtToken: args.debtToken.symbol,
collateralToken: args.collateralToken.symbol,
})

if (dependencies.protocolType === 'Spark') {
const swapAmountBeforeFees = simulation.swap.fromTokenAmount
Expand Down
29 changes: 24 additions & 5 deletions packages/dma-library/src/utils/flashloan/resolve-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import { Network } from '@deploy-configurations/types/network'
import { Protocol } from '@deploy-configurations/types/protocol'
import { FlashloanProvider } from '@dma-library/types/common'

export function resolveFlashloanProvider(
network: Network,
lendingProtocol?: Protocol,
debtToken?: string,
): FlashloanProvider {
// isolated collaterals does not allow to deposit other tokens (from FL) as collateral
// therefore we need to use isolated collateral as FL token
const aaveIsolatedCollateralTokens = ['LDO', 'FRAX', 'MKR', 'SUSDE']

export function resolveFlashloanProvider({
network,
lendingProtocol,
collateralToken,
debtToken,
}: {
network: Network
lendingProtocol: Protocol
debtToken: string
collateralToken: string
}): FlashloanProvider {
switch (network) {
case Network.MAINNET:
if (lendingProtocol === 'Ajna') {
Expand All @@ -15,6 +25,15 @@ export function resolveFlashloanProvider(
if (lendingProtocol === 'Spark' && debtToken !== 'DAI') {
return FlashloanProvider.Balancer
}

if (
lendingProtocol === 'AAVE_V3' &&
collateralToken &&
aaveIsolatedCollateralTokens.includes(collateralToken.toUpperCase())
) {
return FlashloanProvider.Balancer
}

return FlashloanProvider.DssFlash
case Network.GOERLI:
return FlashloanProvider.DssFlash
Expand Down
1 change: 1 addition & 0 deletions packages/dma-library/src/utils/swap/fee-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function isCorrelatedPosition(symbolA: string, symbolB: string) {
'CWETHV3',
'WOETH',
'BSDETH',
'RSETH',
], // ETH correlated assets
['WBTC', 'TBTC'], // BTC correlated assets
['USDC', 'DAI', 'GHO', 'SDAI', 'USDT', 'CDAI', 'AUSDC', 'PYUSD'], // USDC correlated assets
Expand Down
Loading