diff --git a/.changeset/bright-lions-argue.md b/.changeset/bright-lions-argue.md new file mode 100644 index 00000000..ef7c0dc7 --- /dev/null +++ b/.changeset/bright-lions-argue.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': patch +--- + +add Morpho Ethereum diff --git a/.changeset/nine-islands-tan.md b/.changeset/nine-islands-tan.md new file mode 100644 index 00000000..1ea08ca6 --- /dev/null +++ b/.changeset/nine-islands-tan.md @@ -0,0 +1,5 @@ +--- +'@protocolink/logics': patch +--- + +exclude Morphoblue from flashloan aggregator when flashloan token length > 1 diff --git a/.env.goerli b/.env.goerli deleted file mode 100644 index 44e843ac..00000000 --- a/.env.goerli +++ /dev/null @@ -1,3 +0,0 @@ -CHAIN_ID=5 -HTTP_RPC_URL=https://rpc.ankr.com/eth_goerli -BLOCK_NUMBER=10320000 diff --git a/.github/workflows/e2e-test-goerli.yml b/.github/workflows/e2e-test-goerli.yml deleted file mode 100644 index 3ba7a5bb..00000000 --- a/.github/workflows/e2e-test-goerli.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: E2E Test - -on: - push: - pull_request: - -jobs: - run-e2e-test: - name: Run e2e test - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Install dependencies - run: yarn install - - - name: Run e2e test - run: yarn test:e2e:goerli diff --git a/package.json b/package.json index d3c6b895..b86c085d 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "test": "mocha", "test:e2e": "yarn run test:e2e:mainnet && yarn run test:e2e:polygon && yarn run test:e2e:metis && yarn run test:e2e:arbitrum", "test:e2e:mainnet": "env-cmd -f .env.mainnet hardhat test --grep 'mainnet'", - "test:e2e:goerli": "env-cmd -f .env.goerli hardhat test --grep 'goerli'", "test:e2e:polygon": "env-cmd -f .env.polygon hardhat test --grep 'polygon'", "test:e2e:metis": "env-cmd -f .env.metis hardhat test --grep 'metis'", "test:e2e:arbitrum": "env-cmd -f .env.arbitrum hardhat test --grep 'arbitrum'", diff --git a/src/logics/morphoblue/configs.ts b/src/logics/morphoblue/configs.ts index 4e328795..d512bb54 100644 --- a/src/logics/morphoblue/configs.ts +++ b/src/logics/morphoblue/configs.ts @@ -1,5 +1,5 @@ import * as common from '@protocolink/common'; -import { goerliTokens } from './tokens'; +import { goerliTokens, mainnetTokens } from './tokens'; type ContractNames = 'Morpho' | 'MorphoFlashLoanCallback'; @@ -19,6 +19,34 @@ export interface Config { } export const configs: Config[] = [ + { + chainId: common.ChainId.mainnet, + contract: { + Morpho: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb', + MorphoFlashLoanCallback: '0x24D5b6b712D1f0D0B628E21E39dBaDde3f28C56e', + }, + // get meta morpho addresses from MetaMorphoFactory CreateMetaMorpho events + // get market ids from meta morpho supply/withdraw queues + // zero oracle address is excluded + markets: [ + { + id: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + loanTokenAddress: mainnetTokens.WETH.address, + collateralTokenAddress: mainnetTokens.wstETH.address, + oracle: '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72', + irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC', + lltv: '945000000000000000', + }, + { + id: '0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc', + loanTokenAddress: mainnetTokens.USDC.address, + collateralTokenAddress: mainnetTokens.wstETH.address, + oracle: '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2', + irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC', + lltv: '860000000000000000', + }, + ], + }, { chainId: common.ChainId.goerli, contract: { @@ -32,7 +60,7 @@ export const configs: Config[] = [ collateralTokenAddress: goerliTokens.DAI.address, oracle: '0x2bCd59a5fc4Eb21eD6c906702E471922fABbe9a9', irm: '0x9ee101eB4941d8D7A665fe71449360CEF3C8Bb87', - lltv: '900000000000000000', // 90% + lltv: '900000000000000000', }, { id: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', @@ -40,7 +68,7 @@ export const configs: Config[] = [ collateralTokenAddress: goerliTokens.USDC.address, oracle: '0xC801d09b2314D85dE751D03497E7a7482c91e4FB', irm: '0x9ee101eB4941d8D7A665fe71449360CEF3C8Bb87', - lltv: '900000000000000000', // 90% + lltv: '900000000000000000', }, { id: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', diff --git a/src/logics/morphoblue/logic.borrow.test.ts b/src/logics/morphoblue/logic.borrow.test.ts index 33e1370e..473a847d 100644 --- a/src/logics/morphoblue/logic.borrow.test.ts +++ b/src/logics/morphoblue/logic.borrow.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue BorrowLogic', function () { context('Test getTokenList', async function () { @@ -24,7 +24,7 @@ describe('MorphoBlue BorrowLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new BorrowLogic(chainId); const iface = Morpho__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; @@ -32,14 +32,14 @@ describe('MorphoBlue BorrowLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(mainnetTokens.WETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(mainnetTokens.ETH, '1'), }, }, ]; diff --git a/src/logics/morphoblue/logic.flash-loan.test.ts b/src/logics/morphoblue/logic.flash-loan.test.ts index 98c044fd..44f38c01 100644 --- a/src/logics/morphoblue/logic.flash-loan.test.ts +++ b/src/logics/morphoblue/logic.flash-loan.test.ts @@ -5,7 +5,7 @@ import * as common from '@protocolink/common'; import { constants, utils } from 'ethers'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('Morphoblue FlashLoanLogic', function () { context('Test getTokenList', async function () { @@ -19,14 +19,14 @@ describe('Morphoblue FlashLoanLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new FlashLoanLogic(chainId); const iface = Morpho__factory.createInterface(); const testCases: LogicTestCase[] = [ { fields: { - loans: new common.TokenAmounts([goerliTokens.WETH, '1']), + loans: new common.TokenAmounts([mainnetTokens.WETH, '1']), params: '0x', }, }, diff --git a/src/logics/morphoblue/logic.flash-loan.ts b/src/logics/morphoblue/logic.flash-loan.ts index e75552da..20d338ad 100644 --- a/src/logics/morphoblue/logic.flash-loan.ts +++ b/src/logics/morphoblue/logic.flash-loan.ts @@ -36,9 +36,8 @@ export class FlashLoanLogic extends core.Logic implements core.LogicTokenListInt const markets = getMarkets(this.chainId); for (const market of markets) { - const tokens = await service.getMarketTokens(market.id); - tokenAddressSet.add(tokens.loanTokenAddress); - tokenAddressSet.add(tokens.collateralTokenAddress); + tokenAddressSet.add(market.loanTokenAddress); + tokenAddressSet.add(market.collateralTokenAddress); } const tokenList: FlashLoanLogicTokenList = await service.getTokens([...tokenAddressSet]); diff --git a/src/logics/morphoblue/logic.repay.test.ts b/src/logics/morphoblue/logic.repay.test.ts index 88047c74..de2aab9a 100644 --- a/src/logics/morphoblue/logic.repay.test.ts +++ b/src/logics/morphoblue/logic.repay.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue RepayLogic', function () { context('Test getTokenList', async function () { @@ -24,38 +24,38 @@ describe('MorphoBlue RepayLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new RepayLogic(chainId); const iface = Morpho__factory.createInterface(); const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', - input: new common.TokenAmount(goerliTokens.WETH, '1'), + input: new common.TokenAmount(mainnetTokens.WETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', - input: new common.TokenAmount(goerliTokens.WETH, '0'), + input: new common.TokenAmount(mainnetTokens.WETH, '0'), balanceBps: 5000, }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', - input: new common.TokenAmount(goerliTokens.ETH, '1'), + input: new common.TokenAmount(mainnetTokens.ETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', borrower: '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa', - input: new common.TokenAmount(goerliTokens.ETH, '0'), + input: new common.TokenAmount(mainnetTokens.ETH, '0'), balanceBps: 5000, }, }, diff --git a/src/logics/morphoblue/logic.supply-collateral.test.ts b/src/logics/morphoblue/logic.supply-collateral.test.ts index 20112550..65c5a7d6 100644 --- a/src/logics/morphoblue/logic.supply-collateral.test.ts +++ b/src/logics/morphoblue/logic.supply-collateral.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue SupplyCollateralLogic', function () { context('Test getTokenList', async function () { @@ -24,7 +24,7 @@ describe('MorphoBlue SupplyCollateralLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new SupplyCollateralLogic(chainId); const iface = Morpho__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; @@ -32,40 +32,14 @@ describe('MorphoBlue SupplyCollateralLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.DAI, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.wstETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.DAI, '1'), - balanceBps: 5000, - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(goerliTokens.WETH, '1'), - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(goerliTokens.WETH, '1'), - balanceBps: 5000, - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(goerliTokens.ETH, '1'), - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.wstETH, '1'), balanceBps: 5000, }, }, diff --git a/src/logics/morphoblue/logic.supply.test.ts b/src/logics/morphoblue/logic.supply.test.ts index 3704f24a..1b6db0f1 100644 --- a/src/logics/morphoblue/logic.supply.test.ts +++ b/src/logics/morphoblue/logic.supply.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue SupplyLogic', function () { context('Test getTokenList', async function () { @@ -24,7 +24,7 @@ describe('MorphoBlue SupplyLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new SupplyLogic(chainId); const iface = Morpho__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; @@ -32,27 +32,27 @@ describe('MorphoBlue SupplyLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.WETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.WETH, '1'), balanceBps: 5000, }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.ETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(mainnetTokens.ETH, '1'), balanceBps: 5000, }, }, diff --git a/src/logics/morphoblue/logic.withdraw-collateral.test.ts b/src/logics/morphoblue/logic.withdraw-collateral.test.ts index 0df052c0..0f024f76 100644 --- a/src/logics/morphoblue/logic.withdraw-collateral.test.ts +++ b/src/logics/morphoblue/logic.withdraw-collateral.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue WithdrawCollateralLogic', function () { context('Test getTokenList', async function () { @@ -24,7 +24,7 @@ describe('MorphoBlue WithdrawCollateralLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new WithdrawCollateralLogic(chainId); const iface = Morpho__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; @@ -32,20 +32,8 @@ describe('MorphoBlue WithdrawCollateralLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(goerliTokens.DAI, '1'), - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(goerliTokens.WETH, '1'), - }, - }, - { - fields: { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(mainnetTokens.wstETH, '1'), }, }, ]; diff --git a/src/logics/morphoblue/logic.withdraw.test.ts b/src/logics/morphoblue/logic.withdraw.test.ts index 99ace64d..f6e08740 100644 --- a/src/logics/morphoblue/logic.withdraw.test.ts +++ b/src/logics/morphoblue/logic.withdraw.test.ts @@ -6,7 +6,7 @@ import { constants, utils } from 'ethers'; import * as core from '@protocolink/core'; import { expect } from 'chai'; import { getContractAddress } from './configs'; -import { goerliTokens } from './tokens'; +import { mainnetTokens } from './tokens'; describe('MorphoBlue WithdrawLogic', function () { context('Test getTokenList', async function () { @@ -24,7 +24,7 @@ describe('MorphoBlue WithdrawLogic', function () { }); context('Test build', function () { - const chainId = common.ChainId.goerli; + const chainId = common.ChainId.mainnet; const logic = new WithdrawLogic(chainId); const iface = Morpho__factory.createInterface(); const account = '0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa'; @@ -32,14 +32,14 @@ describe('MorphoBlue WithdrawLogic', function () { const testCases: LogicTestCase[] = [ { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(mainnetTokens.WETH, '1'), }, }, { fields: { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(mainnetTokens.ETH, '1'), }, }, ]; diff --git a/src/logics/morphoblue/service.ts b/src/logics/morphoblue/service.ts index 74ed5cdd..34624bea 100644 --- a/src/logics/morphoblue/service.ts +++ b/src/logics/morphoblue/service.ts @@ -1,7 +1,6 @@ import { BigNumber } from 'ethers'; import { Morpho, Morpho__factory } from './contracts'; import { MorphoInterface } from './contracts/Morpho'; -import { TokenAddresses } from './types'; import * as common from '@protocolink/common'; import { getContractAddress, getMarket } from './configs'; @@ -26,38 +25,19 @@ export class Service extends common.Web3Toolkit { } async getLoanToken(marketId: string) { - const tokens = await this.getMarketTokens(marketId); - const loanToken = await this.getToken(tokens.loanTokenAddress); + const market = getMarket(this.chainId, marketId); + const loanToken = await this.getToken(market.loanTokenAddress); return loanToken; } async getCollateralToken(marketId: string) { - const tokens = await this.getMarketTokens(marketId); - const collateralToken = await this.getToken(tokens.collateralTokenAddress); + const market = getMarket(this.chainId, marketId); + const collateralToken = await this.getToken(market.collateralTokenAddress); return collateralToken; } - async getMarket(marketId: string) { - return getMarket(this.chainId, marketId); - } - - async getMarketTokens(marketId: string) { - const calls: common.Multicall3.CallStruct[] = []; - calls.push({ - target: this.morpho.address, - callData: this.morphoIface.encodeFunctionData('idToMarketParams', [marketId]), - }); - const { returnData } = await this.multicall3.callStatic.aggregate(calls); - - const { loanToken, collateralToken } = this.morphoIface.decodeFunctionResult('idToMarketParams', returnData[0]); - - const tokens: TokenAddresses = { loanTokenAddress: loanToken, collateralTokenAddress: collateralToken }; - return tokens; - } - async getSupplyBalance(marketId: string, account: string) { - const market = getMarket(this.chainId, marketId); - const loanToken = await this.getToken(market.loanTokenAddress); + const loanToken = await this.getLoanToken(marketId); const { supplyShares } = await this.morpho.position(marketId, account); const { totalSupplyAssets, totalSupplyShares } = await this.morpho.market(marketId); @@ -67,8 +47,7 @@ export class Service extends common.Web3Toolkit { } async getCollateralBalance(marketId: string, account: string) { - const market = getMarket(this.chainId, marketId); - const collateralToken = await this.getToken(market.collateralTokenAddress); + const collateralToken = await this.getCollateralToken(marketId); const { collateral } = await this.morpho.position(marketId, account); return new common.TokenAmount(collateralToken).setWei(collateral); diff --git a/src/logics/morphoblue/tokens/data/mainnet.json b/src/logics/morphoblue/tokens/data/mainnet.json new file mode 100644 index 00000000..c44f111b --- /dev/null +++ b/src/logics/morphoblue/tokens/data/mainnet.json @@ -0,0 +1,30 @@ +{ + "ETH": { + "chainId": 1, + "address": "0x0000000000000000000000000000000000000000", + "decimals": 18, + "symbol": "ETH", + "name": "Ethereum" + }, + "WETH": { + "chainId": 1, + "address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", + "decimals": 18, + "symbol": "WETH", + "name": "Wrapped Ether" + }, + "wstETH": { + "chainId": 1, + "address": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0", + "decimals": 18, + "symbol": "wstETH", + "name": "Wrapped liquid staked Ether 2.0" + }, + "USDC": { + "chainId": 1, + "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", + "decimals": 6, + "symbol": "USDC", + "name": "USD Coin" + } +} diff --git a/src/logics/morphoblue/tokens/index.ts b/src/logics/morphoblue/tokens/index.ts index 050b883f..f4005811 100644 --- a/src/logics/morphoblue/tokens/index.ts +++ b/src/logics/morphoblue/tokens/index.ts @@ -1,6 +1,11 @@ import * as common from '@protocolink/common'; import goerliTokensJSON from './data/goerli.json'; +import mainnetTokensJSON from './data/mainnet.json'; type GoerliTokenSymbols = keyof typeof goerliTokensJSON; export const goerliTokens = common.toTokenMap(goerliTokensJSON); + +type MainnetTokenSymbols = keyof typeof mainnetTokensJSON; + +export const mainnetTokens = common.toTokenMap(mainnetTokensJSON); diff --git a/src/logics/morphoblue/types.ts b/src/logics/morphoblue/types.ts deleted file mode 100644 index deb6589a..00000000 --- a/src/logics/morphoblue/types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface TokenAddresses { - loanTokenAddress: string; - collateralTokenAddress: string; -} diff --git a/src/logics/utility/logic.flash-loan-aggregator.ts b/src/logics/utility/logic.flash-loan-aggregator.ts index ec4a63f3..01a92e3a 100644 --- a/src/logics/utility/logic.flash-loan-aggregator.ts +++ b/src/logics/utility/logic.flash-loan-aggregator.ts @@ -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[] = []; diff --git a/test/logics/morphoblue/borrow.test.ts b/test/logics/morphoblue/borrow.test.ts index dffd894b..3d2624a9 100644 --- a/test/logics/morphoblue/borrow.test.ts +++ b/test/logics/morphoblue/borrow.test.ts @@ -7,7 +7,7 @@ import * as helpers from './helpers'; import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; -describe('goerli: Test Morphoblue Borrow Logic', function () { +describe('mainnet: Test Morphoblue Borrow Logic', function () { let chainId: number; let user: SignerWithAddress; let service: morphoblue.Service; @@ -17,39 +17,21 @@ describe('goerli: Test Morphoblue Borrow Logic', function () { [, user] = await hre.ethers.getSigners(); service = new morphoblue.Service(chainId, hre.ethers.provider); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.USDC, - '5000', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.wstETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - output: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), }, { - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - output: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(morphoblue.goerliTokens.USDC, '1000'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.01'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), }, ]; diff --git a/test/logics/morphoblue/flash-loan.test.ts b/test/logics/morphoblue/flash-loan.test.ts index 2171bc1e..1773639d 100644 --- a/test/logics/morphoblue/flash-loan.test.ts +++ b/test/logics/morphoblue/flash-loan.test.ts @@ -8,7 +8,7 @@ import * as morphoblue from 'src/logics/morphoblue'; import * as utility from 'src/logics/utility'; import * as utils from 'test/utils'; -describe('goerli: Test Morphoblue FlashLoan Logic', function () { +describe('mainnet: Test Morphoblue FlashLoan Logic', function () { let chainId: number; let user: SignerWithAddress; @@ -16,29 +16,17 @@ describe('goerli: Test Morphoblue FlashLoan Logic', function () { chainId = await getChainId(); [, user] = await hre.ethers.getSigners(); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '2', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.USDC, - '2', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.WETH, '1'); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.wstETH, '1'); }); snapshotAndRevertEach(); const testCases = [ - { loans: new common.TokenAmounts([morphoblue.goerliTokens.WETH, '1']) }, - { repays: new common.TokenAmounts([morphoblue.goerliTokens.WETH, '1']) }, - { loans: new common.TokenAmounts([morphoblue.goerliTokens.USDC, '1']) }, - { repays: new common.TokenAmounts([morphoblue.goerliTokens.USDC, '1']) }, + { loans: new common.TokenAmounts([morphoblue.mainnetTokens.WETH, '0.01']) }, + { repays: new common.TokenAmounts([morphoblue.mainnetTokens.WETH, '0.01']) }, + { loans: new common.TokenAmounts([morphoblue.mainnetTokens.wstETH, '0.01']) }, + { repays: new common.TokenAmounts([morphoblue.mainnetTokens.wstETH, '0.01']) }, ]; testCases.forEach((params, i) => { diff --git a/test/logics/morphoblue/repay.test.ts b/test/logics/morphoblue/repay.test.ts index 07fc4349..9db916f3 100644 --- a/test/logics/morphoblue/repay.test.ts +++ b/test/logics/morphoblue/repay.test.ts @@ -8,7 +8,7 @@ import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; import * as utils from 'test/utils'; -describe('goerli: Test Morphoblue Borrow Logic', function () { +describe('mainnet: Test Morphoblue Borrow Logic', function () { let chainId: number; let users: SignerWithAddress[]; let service: morphoblue.Service; @@ -19,152 +19,126 @@ describe('goerli: Test Morphoblue Borrow Logic', function () { users = [user1, user2]; service = new morphoblue.Service(chainId, hre.ethers.provider); - await claimToken( - chainId, - user1.address, - morphoblue.goerliTokens.USDC, - '5000', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); - await claimToken( - chainId, - user1.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); - await claimToken( - chainId, - user2.address, - morphoblue.goerliTokens.USDC, - '5000', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); - await claimToken( - chainId, - user2.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); + await claimToken(chainId, user1.address, morphoblue.mainnetTokens.WETH, '10'); + await claimToken(chainId, user1.address, morphoblue.mainnetTokens.wstETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - title: 'WETH-USDC market: repay fixed amount', + title: 'WETH-wstETH market: repay fixed amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, { - title: 'WETH-USDC market: repay 50% amount', + title: 'WETH-wstETH market: repay 50% amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 5000, }, { - title: 'WETH-USDC market: repay 100% amount', + title: 'WETH-wstETH market: repay 100% amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 10000, }, { - title: 'WETH-USDC market: repay more amount', + title: 'WETH-wstETH market: repay more amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '2'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '1'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, { - title: 'WETH-USDC market: repay native fixed amount', + title: 'WETH-wstETH market: repay native fixed amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, { - title: 'WETH-USDC market: repay native 50% amount', + title: 'WETH-wstETH market: repay native 50% amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 5000, }, { - title: 'WETH-USDC market: repay native 100% amount', + title: 'WETH-wstETH market: repay native 100% amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 10000, }, { - title: 'WETH-USDC market: repay native more amount', + title: 'WETH-wstETH market: repay native more amount', borrowerIndex: 0, repayerIndex: 0, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '2'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '1'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, { - title: 'WETH-USDC market: help repay fixed amount', + title: 'WETH-wstETH market: help repay fixed amount', borrowerIndex: 0, repayerIndex: 1, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, { - title: 'WETH-USDC market: help repay 50% amount', + title: 'WETH-wstETH market: help repay 50% amount', borrowerIndex: 0, repayerIndex: 1, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 5000, }, { - title: 'WETH-USDC market: help repay 100% amount', + title: 'WETH-wstETH market: help repay 100% amount', borrowerIndex: 0, repayerIndex: 1, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '0.5'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '0.005'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), balanceBps: 10000, }, { - title: 'WETH-USDC market: help repay more amount', + title: 'WETH-wstETH market: help repay more amount', borrowerIndex: 0, repayerIndex: 1, - marketId: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '2'), - collateral: new common.TokenAmount(morphoblue.goerliTokens.USDC, '3000'), - borrow: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '1'), + collateral: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), + borrow: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '0.01'), }, ]; diff --git a/test/logics/morphoblue/supply-collateral.test.ts b/test/logics/morphoblue/supply-collateral.test.ts index e54d18bb..1091dd7f 100644 --- a/test/logics/morphoblue/supply-collateral.test.ts +++ b/test/logics/morphoblue/supply-collateral.test.ts @@ -7,7 +7,7 @@ import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; import * as utils from 'test/utils'; -describe('goerli: Test Morphoblue SupplyCollateral Logic', function () { +describe('mainnet: Test Morphoblue SupplyCollateral Logic', function () { let chainId: number; let user: SignerWithAddress; let service: morphoblue.Service; @@ -17,51 +17,19 @@ describe('goerli: Test Morphoblue SupplyCollateral Logic', function () { [, user] = await hre.ethers.getSigners(); service = new morphoblue.Service(chainId, hre.ethers.provider); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.DAI, - '5000', - '0x112EC3b862AB061609Ef01D308109a6691Ee6a2d' - ); - - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.wstETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.DAI, '1000'), - }, - { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.DAI, '1000'), - balanceBps: 5000, - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), - balanceBps: 5000, - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), }, { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), balanceBps: 5000, }, ]; diff --git a/test/logics/morphoblue/supply.test.ts b/test/logics/morphoblue/supply.test.ts index 91856614..dd97642f 100644 --- a/test/logics/morphoblue/supply.test.ts +++ b/test/logics/morphoblue/supply.test.ts @@ -7,7 +7,7 @@ import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; import * as utils from 'test/utils'; -describe('goerli: Test Morphoblue Supply Logic', function () { +describe('mainnet: Test Morphoblue Supply Logic', function () { let chainId: number; let user: SignerWithAddress; let service: morphoblue.Service; @@ -17,50 +17,28 @@ describe('goerli: Test Morphoblue Supply Logic', function () { [, user] = await hre.ethers.getSigners(); service = new morphoblue.Service(chainId, hre.ethers.provider); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.USDC, - '1000', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.WETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '1'), }, { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '1'), balanceBps: 5000, }, { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '1'), }, { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - input: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), - balanceBps: 5000, - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.USDC, '100'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - input: new common.TokenAmount(morphoblue.goerliTokens.USDC, '100'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + input: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '1'), balanceBps: 5000, }, ]; diff --git a/test/logics/morphoblue/withdraw-collateral.test.ts b/test/logics/morphoblue/withdraw-collateral.test.ts index 07d79c08..a32c0ca9 100644 --- a/test/logics/morphoblue/withdraw-collateral.test.ts +++ b/test/logics/morphoblue/withdraw-collateral.test.ts @@ -7,7 +7,7 @@ import * as helpers from './helpers'; import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; -describe('goerli: Test Morphoblue Withdraw Collateral Logic', function () { +describe('mainnet: Test Morphoblue Withdraw Collateral Logic', function () { let chainId: number; let user: SignerWithAddress; @@ -15,36 +15,15 @@ describe('goerli: Test Morphoblue Withdraw Collateral Logic', function () { chainId = await getChainId(); [, user] = await hre.ethers.getSigners(); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.DAI, - '1000', - '0x112EC3b862AB061609Ef01D308109a6691Ee6a2d' - ); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.wstETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(morphoblue.goerliTokens.DAI, '100'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(morphoblue.mainnetTokens.wstETH, '1'), }, ]; diff --git a/test/logics/morphoblue/withdraw.test.ts b/test/logics/morphoblue/withdraw.test.ts index 5f924488..eece1505 100644 --- a/test/logics/morphoblue/withdraw.test.ts +++ b/test/logics/morphoblue/withdraw.test.ts @@ -7,7 +7,7 @@ import * as helpers from './helpers'; import hre from 'hardhat'; import * as morphoblue from 'src/logics/morphoblue'; -describe('goerli: Test Morphoblue Withdraw Logic', function () { +describe('mainnet: Test Morphoblue Withdraw Logic', function () { let chainId: number; let user: SignerWithAddress; @@ -15,36 +15,19 @@ describe('goerli: Test Morphoblue Withdraw Logic', function () { chainId = await getChainId(); [, user] = await hre.ethers.getSigners(); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.WETH, - '10', - '0x88124Ef4A9EC47e691F254F2E8e348fd1e341e9B' - ); - await claimToken( - chainId, - user.address, - morphoblue.goerliTokens.USDC, - '1000', - '0x64c7044050Ba0431252df24fEd4d9635a275CB41' - ); + await claimToken(chainId, user.address, morphoblue.mainnetTokens.WETH, '10'); }); snapshotAndRevertEach(); const testCases = [ { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(morphoblue.goerliTokens.WETH, '1'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(morphoblue.mainnetTokens.WETH, '1'), }, { - marketId: '0x3098a46de09dd8d9a8c6fa1ab7b3f943b6f13e5ea72a4e475d9e48f222bfd5a0', - output: new common.TokenAmount(morphoblue.goerliTokens.ETH, '1'), - }, - { - marketId: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd', - output: new common.TokenAmount(morphoblue.goerliTokens.USDC, '1000'), + marketId: '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41', + output: new common.TokenAmount(morphoblue.mainnetTokens.ETH, '1'), }, ]; diff --git a/test/logics/utility/flash-loan-aggregrator.test.ts b/test/logics/utility/flash-loan-aggregrator.test.ts index 8dd9a6d8..f64d606d 100644 --- a/test/logics/utility/flash-loan-aggregrator.test.ts +++ b/test/logics/utility/flash-loan-aggregrator.test.ts @@ -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'; @@ -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']) }, @@ -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();