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

Add Morphoblue Ethereum #35

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/bright-lions-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': patch
---

add Morpho Ethereum
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
3 changes: 0 additions & 3 deletions .env.goerli

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/e2e-test-goerli.yml

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
34 changes: 31 additions & 3 deletions src/logics/morphoblue/configs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as common from '@protocolink/common';
import { goerliTokens } from './tokens';
import { goerliTokens, mainnetTokens } from './tokens';

type ContractNames = 'Morpho' | 'MorphoFlashLoanCallback';

Expand All @@ -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',
hihiben marked this conversation as resolved.
Show resolved Hide resolved
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: {
Expand All @@ -32,15 +60,15 @@ export const configs: Config[] = [
collateralTokenAddress: goerliTokens.DAI.address,
oracle: '0x2bCd59a5fc4Eb21eD6c906702E471922fABbe9a9',
irm: '0x9ee101eB4941d8D7A665fe71449360CEF3C8Bb87',
lltv: '900000000000000000', // 90%
lltv: '900000000000000000',
},
{
id: '0x900d90c624f9bd1e1143059c14610bde45ff7d1746c52bf6c094d3568285b661',
loanTokenAddress: goerliTokens.WETH.address,
collateralTokenAddress: goerliTokens.USDC.address,
oracle: '0xC801d09b2314D85dE751D03497E7a7482c91e4FB',
irm: '0x9ee101eB4941d8D7A665fe71449360CEF3C8Bb87',
lltv: '900000000000000000', // 90%
lltv: '900000000000000000',
hihiben marked this conversation as resolved.
Show resolved Hide resolved
},
{
id: '0x98ee9f294c961a5dbb9073c0fd2c2a6a66468f911e49baa935c0eab364499dbd',
Expand Down
12 changes: 6 additions & 6 deletions src/logics/morphoblue/logic.borrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -24,22 +24,22 @@ 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';

const testCases: LogicTestCase<BorrowLogicFields>[] = [
{
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'),
},
},
];
Expand Down
6 changes: 3 additions & 3 deletions src/logics/morphoblue/logic.flash-loan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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<FlashLoanLogicFields>[] = [
{
fields: {
loans: new common.TokenAmounts([goerliTokens.WETH, '1']),
loans: new common.TokenAmounts([mainnetTokens.WETH, '1']),
params: '0x',
},
},
Expand Down
5 changes: 2 additions & 3 deletions src/logics/morphoblue/logic.flash-loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
20 changes: 10 additions & 10 deletions src/logics/morphoblue/logic.repay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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<RepayLogicFields>[] = [
{
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,
},
},
Expand Down
38 changes: 6 additions & 32 deletions src/logics/morphoblue/logic.supply-collateral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -24,48 +24,22 @@ 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';

const testCases: LogicTestCase<SupplyCollateralLogicFields>[] = [
{
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,
},
},
Expand Down
20 changes: 10 additions & 10 deletions src/logics/morphoblue/logic.supply.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -24,35 +24,35 @@ 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';

const testCases: LogicTestCase<SupplyLogicFields>[] = [
{
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,
},
},
Expand Down
20 changes: 4 additions & 16 deletions src/logics/morphoblue/logic.withdraw-collateral.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -24,28 +24,16 @@ 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';

const testCases: LogicTestCase<WithdrawCollateralLogicFields>[] = [
{
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'),
},
},
];
Expand Down
Loading
Loading