Skip to content

Commit

Permalink
Merge pull request #34 from OasisDEX/jt/publish/automation-lib-with-m…
Browse files Browse the repository at this point in the history
…orpho

feat: transfer Morpho logic from earn-sc to automation lib
  • Loading branch information
zerotucks authored May 1, 2024
2 parents 82ec556 + 5c7c32e commit f070deb
Show file tree
Hide file tree
Showing 60 changed files with 1,411 additions and 752 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"format": "lerna run format --stream",
"format:check": "lerna run format:check --stream",
"lint": "lerna run lint --stream && yarn clean",
"publish:all": "npx lerna publish --no-private"
"publish:all": "npx lerna publish --no-private",
"postinstall": "patch-package"
},
"devDependencies": {
"@babel/core": "^7.21.4",
Expand Down Expand Up @@ -73,6 +74,7 @@
"lerna": "^6.6.1",
"mocha": "^10.1.0",
"parcel": "2.8.3",
"patch-package": "^8.0.0",
"prettier-plugin-solidity": "^1.0.0-beta.17",
"solhint": "^3.2.2",
"solhint-plugin-prettier": "0.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/addresses/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oasisdex/addresses",
"version": "0.1.17-automation",
"version": "0.1.20-automation.0",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
20 changes: 11 additions & 9 deletions packages/deploy-configurations/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
MakerProtocolJoins,
MakerProtocolPips,
} from '@deploy-configurations/types/deployment-config/maker-protocol'
import { MorphoBlueProtocol } from '@deploy-configurations/types/deployment-config/morpho-blue'
import {
OptionalSparkProtocolContracts,
SparkProtocol,
Expand All @@ -45,7 +46,7 @@ enum AaveKeys {
V3 = 'v3',
}

type DefaultDeployment = {
export type DefaultDeployment = {
[SystemKeys.MPA]: {
[MpaKeys.CORE]: Record<Core, Address>
[MpaKeys.ACTIONS]: Record<Actions, Address>
Expand All @@ -63,6 +64,7 @@ type DefaultDeployment = {
}
[SystemKeys.AUTOMATION]: Record<Automation, Address>
[SystemKeys.AJNA]: Record<AjnaProtocol, Address>
[SystemKeys.MORPHO_BLUE]: Record<MorphoBlueProtocol, Address>
}

export type Addresses = {
Expand All @@ -78,10 +80,7 @@ export type Addresses = {
if (!mainnetConfig.aave.v2) throw new Error('Missing aave v2 config on mainnet')
if (!optimismConfig.aave.v3.L2Encoder) throw new Error('Missing L2Encoder config on optimism')

const createAddressesStructure = (
networkConfig: SystemConfig,
ajnaConfig?: SystemConfig,
): DefaultDeployment => ({
const createAddressesStructure = (networkConfig: SystemConfig): DefaultDeployment => ({
mpa: {
core: {
...extractAddressesFromConfig<Core>(networkConfig.mpa.core),
Expand Down Expand Up @@ -119,7 +118,10 @@ const createAddressesStructure = (
...extractAddressesFromConfig(networkConfig.automation),
},
ajna: {
...extractAddressesFromConfig(ajnaConfig?.ajna || networkConfig.ajna),
...extractAddressesFromConfig(networkConfig.ajna),
},
morphoblue: {
...extractAddressesFromConfig(networkConfig.morphoblue),
},
})

Expand Down Expand Up @@ -149,9 +151,9 @@ function extractAddressesFromConfig<T extends Contracts>(
export const ADDRESSES: Addresses = {
[Network.MAINNET]: createAddressesStructure(mainnetConfig),
[Network.OPTIMISM]: createAddressesStructure(optimismConfig),
[Network.GOERLI]: createAddressesStructure(goerliConfig, goerliConfig),
[Network.ARBITRUM]: createAddressesStructure(arbitrumConfig, mainnetConfig),
[Network.BASE]: createAddressesStructure(baseConfig, mainnetConfig),
[Network.GOERLI]: createAddressesStructure(goerliConfig),
[Network.ARBITRUM]: createAddressesStructure(arbitrumConfig),
[Network.BASE]: createAddressesStructure(baseConfig),
[Network.TEST]: createAddressesStructure(testConfig),
[Network.SEPOLIA]: createAddressesStructure(sepoliaConfig),
}
Expand Down
6 changes: 5 additions & 1 deletion packages/deploy-configurations/configs/mainnet.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,8 +1476,12 @@ export const config: SystemConfig = {
morphoblue: {
MorphoBlue: {
name: 'MorphoBlue',
address: '0x0000000000000000000000000000000000000000',
address: '0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb',
serviceRegistryName: SERVICE_REGISTRY_NAMES.morphoblue.MORPHO_BLUE,
},
AdaptiveCurveIrm: {
name: 'AdaptiveCurveIrm',
address: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
},
},
}
60 changes: 17 additions & 43 deletions packages/deploy-configurations/constants/load-contract-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@ import { Network } from '@deploy-configurations/types/network'

export function loadContractNames(network: Network) {
return SERVICE_REGISTRY_NAMES
//
// if (network === Network.MAINNET) {
// console.log('LOADING MAINNET CONFIG')
// loadedConfig = require('./contract-names.mainnet')
// console.log("LOADED CONFIG: ", JSON.stringify(loadedConfig.SERVICE_REGISTRY_NAMES.common))
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.OPTIMISM) {
// loadedConfig = require('./contract-names.optimism')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.ARBITRUM) {
// loadedConfig = require('./contract-names.arbitrum')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.BASE) {
// loadedConfig = require('./contract-names.base')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.GOERLI) {
// loadedConfig = require('./contract-names.mainnet')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.SEPOLIA) {
// loadedConfig = require('./contract-names.mainnet')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.LOCAL) {
// loadedConfig = require('./contract-names.local')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else if (network === Network.TEST) {
// loadedConfig = require('./contract-names.test')
// return loadedConfig.SERVICE_REGISTRY_NAMES
// } else {
// throw new Error(`Invalid network: ${network}`)
// }
// return loadedConfig.SERVICE_REGISTRY_NAMES
}

/**
Expand All @@ -46,6 +15,7 @@ export function loadContractNames(network: Network) {
export const SERVICE_REGISTRY_NAMES = {
common: {
PULL_TOKEN: 'PullToken_7',
PULL_TOKEN_MAX_AMOUNT: 'PullTokenMaxAmount',
SEND_TOKEN: 'SendToken_7',
SEND_TOKEN_AUTO: 'SendTokenAuto_7',
SET_APPROVAL: 'SetApproval_6',
Expand All @@ -55,8 +25,12 @@ export const SERVICE_REGISTRY_NAMES = {
WRAP_ETH: 'WrapEth_6',
UNWRAP_ETH: 'UnwrapEth_6',
RETURN_FUNDS: 'ReturnFunds_6',
RETURN_MULTIPLE_TOKENS: 'ReturnMultipleTokens',
COLLECT_FEE: 'CollectFee_3',
POSITION_CREATED: 'PositionCreated',
TOKEN_BALANCE: 'TokenBalance',
ERC4626_DEPOSIT: 'ERC4626Deposit',
ERC4626_WITHDRAW: 'ERC4626Withdraw',
ACCOUNT_GUARD: 'AccountGuard',
ACCOUNT_FACTORY: 'AccountFactory',
OPERATION_EXECUTOR: 'OperationExecutor_5',
Expand Down Expand Up @@ -101,13 +75,12 @@ export const SERVICE_REGISTRY_NAMES = {
L2_ENCODER: 'AaveL2Encoder',
},
spark: {
DEPOSIT: 'SparkDeposit_auto_3',
WITHDRAW: 'SparkWithdraw_auto_3',
WITHDRAW_AUTO: 'SparkWithdrawAuto_auto_3',
BORROW: 'SparkBorrow_auto_3',
PAYBACK: 'SparkPayback_auto_3',
DEPOSIT: 'SparkDeposit',
WITHDRAW: 'SparkWithdraw',
BORROW: 'SparkBorrow_2',
PAYBACK: 'SparkPayback_2',
LENDING_POOL: 'SparkLendingPool',
SET_EMODE: 'SparkSetEMode_auto_3',
SET_EMODE: 'SparkSetEMode',
},
maker: {
DEPOSIT: 'MakerDeposit',
Expand All @@ -125,23 +98,24 @@ export const SERVICE_REGISTRY_NAMES = {
CHAINLOG_VIEW: 'ChainLogView',
},
ajna: {
DEPOSIT_BORROW: 'AjnaDepositBorrow',
REPAY_WITHDRAW: 'AjnaRepayWithdraw',
ERC20_POOL_FACTORY: 'ERC20PoolFactory',
AJNA_POOL_UTILS_INFO: 'AjnaPoolUtilsInfo',
DEPOSIT_BORROW: 'AjnaDepositBorrow_5',
REPAY_WITHDRAW: 'AjnaRepayWithdraw_5',
ERC20_POOL_FACTORY: 'ERC20PoolFactoryRc14',
AJNA_POOL_UTILS_INFO: 'AjnaPoolUtilsInfoRc14',
},
morphoblue: {
MORPHO_BLUE: 'MorphoBlue',
DEPOSIT: 'MorphoBlueDeposit',
WITHDRAW: 'MorphoBlueWithdraw',
BORROW: 'MorphoBlueBorrow',
PAYBACK: 'MorphoBluePayback',
PAYBACK: 'MorphoBluePayback_2',
CLAIM_REWARDS: 'MorphoBlueClaimRewards',
},
test: {
DUMMY_ACTION: 'DummyAction',
DUMMY_OPTIONAL_ACTION: 'DummyOptionalAction',
DUMMY_SWAP: 'DummySwap',
DUMMY_EXCHANGE: 'DummyExchange',
DUMMY_EXCHANGE: 'MockExchange',
SWAP: 'uSwap',
},
} as const
2 changes: 2 additions & 0 deletions packages/deploy-configurations/constants/operation-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export const OPERATION_NAMES = {
},
common: {
CUSTOM_OPERATION: 'CustomOperation',
ERC4626_DEPOSIT: 'ERC4626Deposit',
ERC4626_WITHDRAW: 'ERC4626Withdraw',
},
} as const

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { loadContractNames, OPERATION_NAMES } from '@deploy-configurations/constants'
import { Network } from '@deploy-configurations/types/network'
import { getActionHash } from '@deploy-configurations/utils/action-hash'

export function getErc4626DepositOperationDefinition(network: Network) {
const SERVICE_REGISTRY_NAMES = loadContractNames(network)

return {
name: OPERATION_NAMES.common.ERC4626_DEPOSIT,
actions: [
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.PULL_TOKEN),
optional: true,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.WRAP_ETH),
optional: true,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.SWAP_ACTION),
optional: true,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.SET_APPROVAL),
optional: false,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.ERC4626_DEPOSIT),
optional: false,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.POSITION_CREATED),
optional: true,
},
],
log: false,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { getErc4626DepositOperationDefinition } from './deposit'
export { getErc4626WithdrawOperationDefinition } from './withdraw'
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { loadContractNames, OPERATION_NAMES } from '@deploy-configurations/constants'
import { Network } from '@deploy-configurations/types/network'
import { getActionHash } from '@deploy-configurations/utils/action-hash'

export function getErc4626WithdrawOperationDefinition(network: Network) {
const SERVICE_REGISTRY_NAMES = loadContractNames(network)

return {
name: OPERATION_NAMES.common.ERC4626_WITHDRAW,
actions: [
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.ERC4626_WITHDRAW),
optional: false,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.SWAP_ACTION),
optional: true,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.UNWRAP_ETH),
optional: true,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.RETURN_FUNDS),
optional: false,
},
{
hash: getActionHash(SERVICE_REGISTRY_NAMES.common.RETURN_FUNDS),
optional: true,
},
],
log: false,
}
}
4 changes: 4 additions & 0 deletions packages/deploy-configurations/operation-definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ export { getMorphoBlueOpenOperationDefinition } from './morphoblue/multiply'
export { getMorphoBlueCloseOperationDefinition } from './morphoblue/multiply'
export { getMorphoBlueAdjustDownOperationDefinition } from './morphoblue/multiply'
export { getMorphoBlueAdjustUpOperationDefinition } from './morphoblue/multiply'

// COMMON
export { getErc4626DepositOperationDefinition } from './common/erc4626'
export { getErc4626WithdrawOperationDefinition } from './common/erc4626'
2 changes: 2 additions & 0 deletions packages/deploy-configurations/types/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const ProtocolNames = [
'Maker',
'Compound',
'Ajna',
'Ajna_rc13',
'Ajna_rc14',
'Spark',
'MorphoBlue',
] as const
Expand Down
2 changes: 1 addition & 1 deletion packages/dma-common/types/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface Swap {
minToTokenAmount: BigNumber
exchangeCalldata: string | number
collectFeeFrom: Address
fee: BigNumber
tokenFee: BigNumber
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '@dma-contracts/test/fixtures'
import { ETH, MULTIPLE, USDC } from '@dma-contracts/test/fixtures/factories/common'
import { AjnaPosition, Network, RiskRatio, strategies } from '@dma-library'
import { AjnaPool, AjnaStrategy } from '@dma-library/types/ajna'
import { AjnaPool, SummerStrategy } from '@dma-library/types/ajna'
import BigNumber from 'bignumber.js'
import { ethers } from 'ethers'

Expand Down Expand Up @@ -46,7 +46,7 @@ const ethUsdcMultiplyAjnaPosition: EthUsdcMultiplyAjnaPosition = async ({
const pool = ajnaSystem.pools.wethUsdcPool
if (!pool) throw new Error('wethUsdcPool is not set')

await addLiquidityToPool(ajnaSystem, pool, config)
await addLiquidityToPool(ajnaSystem, pool)

const ajnaPool = await dependencies.getPoolData(pool.address)

Expand Down Expand Up @@ -179,7 +179,7 @@ async function getEthUsdcMultiplyAjnaPositionPayload(
}

async function executeTx(
payload: AjnaStrategy<AjnaPosition>,
payload: SummerStrategy<AjnaPosition>,
dependencies: StrategyDependenciesAjna,
feeRecipient: string,
config: RuntimeConfig,
Expand Down Expand Up @@ -217,7 +217,7 @@ function buildPositionDetails(
dependencies: StrategyDependenciesAjna,
tokens: ReturnType<typeof configureTokens>,
getSwapDataFn: AjnaPositionDetails['getSwapData'],
payload: AjnaStrategy<AjnaPosition>,
payload: SummerStrategy<AjnaPosition>,
pool: AjnaPool,
feesCollected: BigNumber,
mockMarketPrice: BigNumber,
Expand Down
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.5.21-dma-v2-workers.32-auto-withdraw-to-ltv",
"version": "0.6.4-automation",
"typings": "lib/index.d.ts",
"types": "lib/index.d.ts",
"main": "lib/index.js",
Expand Down
Loading

0 comments on commit f070deb

Please sign in to comment.