Skip to content

Commit

Permalink
fix: exclude Morphoblue from flashloan aggregator when flashloan toke…
Browse files Browse the repository at this point in the history
…n length > 1
  • Loading branch information
Jeff-CCH committed Jan 9, 2024
1 parent d8fa010 commit ba9bebd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-islands-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': patch
---

exclude Morphoblue from flashloan aggregator when flashloan token length > 1
7 changes: 6 additions & 1 deletion src/logics/utility/logic.flash-loan-aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ export class FlashLoanAggregatorLogic

async quote(params: FlashLoanAggregatorLogicParams) {
const { protocolId, ...others } = params;
const flashLoanLength = core.isFlashLoanLoanParams(others) ? others.loans.length : others.repays.length;

const flashLoanLogics = supportedFlashLoanLogics.filter((FlashLoanLogic) =>
protocolId ? FlashLoanLogic.protocolId === protocolId : FlashLoanLogic.supportedChainIds.includes(this.chainId)
protocolId
? FlashLoanLogic.protocolId === protocolId
: flashLoanLength > 1
? FlashLoanLogic.supportedChainIds.includes(this.chainId) && FlashLoanLogic.protocolId !== 'morphoblue'
: FlashLoanLogic.supportedChainIds.includes(this.chainId)
);

const quotations: FlashLoanAggregatorLogicQuotation[] = [];
Expand Down
15 changes: 10 additions & 5 deletions test/logics/utility/flash-loan-aggregrator.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import * as aavev3 from 'src/logics/aave-v3';
import { aavev3, morphoblue } from 'src/logics';
import { claimToken, getChainId, mainnetTokens, snapshotAndRevertEach } from '@protocolink/test-helpers';
import * as common from '@protocolink/common';
import * as core from '@protocolink/core';
Expand All @@ -18,18 +18,20 @@ describe('mainnet: Test Utility FlashLoanAggregator Logic', function () {
await claimToken(chainId, user.address, aavev3.mainnetTokens['1INCH'], '2');
await claimToken(chainId, user.address, mainnetTokens.WETH, '2');
await claimToken(chainId, user.address, mainnetTokens.USDC, '2');
await claimToken(chainId, user.address, mainnetTokens.USDT, '2');
await claimToken(chainId, user.address, mainnetTokens.DAI, '2', '0x8A610c1C93da88c59F51A6264A4c70927814B320');
await claimToken(chainId, user.address, morphoblue.mainnetTokens.wstETH, '2');
});

snapshotAndRevertEach();

const testCases = [
// morphoblue
{ loans: new common.TokenAmounts([morphoblue.mainnetTokens.wstETH, '0.01']) },
{ repays: new common.TokenAmounts([morphoblue.mainnetTokens.wstETH, '0.01']) },
// balancer-v2
{ loans: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']) },
{ repays: new common.TokenAmounts([mainnetTokens.WETH, '1'], [mainnetTokens.USDC, '1']) },
{ loans: new common.TokenAmounts([mainnetTokens.USDT, '1'], [mainnetTokens.DAI, '1']) },
{ repays: new common.TokenAmounts([mainnetTokens.USDT, '1'], [mainnetTokens.DAI, '1']) },
{ loans: new common.TokenAmounts([mainnetTokens.WETH, '0.01'], [morphoblue.mainnetTokens.wstETH, '0.01']) },
{ repays: new common.TokenAmounts([mainnetTokens.WETH, '0.01'], [morphoblue.mainnetTokens.wstETH, '0.01']) },
// aave-v3
{ loans: new common.TokenAmounts([aavev3.mainnetTokens['1INCH'], '1'], [aavev3.mainnetTokens.USDC, '1']) },
{ repays: new common.TokenAmounts([aavev3.mainnetTokens['1INCH'], '1'], [aavev3.mainnetTokens.USDC, '1']) },
Expand All @@ -45,6 +47,9 @@ describe('mainnet: Test Utility FlashLoanAggregator Logic', function () {
if (params.protocolId) {
expect(protocolId).to.be.eq(params.protocolId);
}
if ((params.loans && params.loans.length > 1) || (params.repays && params.repays.length > 1)) {
expect(protocolId).to.be.not.eq(morphoblue.FlashLoanLogic.protocolId);
}

// 2. build funds and router logics for flash loan
const funds = new common.TokenAmounts();
Expand Down

0 comments on commit ba9bebd

Please sign in to comment.