Skip to content

Commit

Permalink
Merge pull request #116 from OasisDEX/jt/sc-15288/common-update-with-…
Browse files Browse the repository at this point in the history
…new-trigger-ids

feat: add morpho triggers
  • Loading branch information
zerotucks authored May 30, 2024
2 parents 98f648d + 21168c7 commit ab4a0f1
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/automation/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@oasisdex/automation",
"packageManager": "yarn@1.22.21",
"version": "1.6.5",
"version": "1.6.6",
"description": "The set of utilities for Oasis automation",
"homepage": "https://github.com/OasisDEX/common#readme",
"main": "lib/src/index.js",
Expand Down
171 changes: 171 additions & 0 deletions packages/automation/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,78 @@ export const commandTypeJsonMapping: Record<CommandContractType, string[]> = {
'deviation',
'withdrawToDebt',
],

// Morpho
[CommandContractType.DmaMorphoBlueBasicBuyCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'poolId',
'quoteDecimals',
'collateralDecimals',
'executionLtv',
'targetLtv',
'maxBuyPrice',
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.DmaMorphoBlueBasicSellCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'poolId',
'executionLtv',
'targetLtv',
'minSellPrice',
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.DmaMorphoBlueStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'poolId',
'executionLtv',
'closeToCollateral',
],
[CommandContractType.DmaMorphoBluePartialTakeProfitCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'poolId',
'executionLtv',
'targetLtv',
'executionPrice',
'deviation',
'withdrawToDebt',
],
[CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'poolId',
'collateralOracle',
'collateralAddedRoundId',
'debtOracle',
'debtAddedRoundId',
'trailingDistance',
'closeToCollateral',
],
};
export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
Expand All @@ -234,6 +306,11 @@ export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractT
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
[CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2]: [
'collateralMaxPriceRoundId',
'debtClosestPriceRoundId',
'debtNextPriceRoundId',
],
};
export const commandAddressMapping: Record<
number,
Expand Down Expand Up @@ -345,6 +422,23 @@ export const commandAddressMapping: Record<
'0x739838d896B50703968e43876f2D43885C9ff8aD': {
type: CommandContractType.DmaAavePartialTakeProfitCommandV2,
},

// TODO: Add addresses once deployed
'0x5800e875cf803aFb5f963faC40623548C27e342a': {
type: CommandContractType.DmaMorphoBlueBasicBuyCommandV2,
},
'0x1F6D1f30ccc00B5Df9b2f3ACeF26D555b8Efe69E': {
type: CommandContractType.DmaMorphoBlueBasicSellCommandV2,
},
'0x0DF4F9B2cAb35075677253eA15e424B97ABc7dEb': {
type: CommandContractType.DmaMorphoBluePartialTakeProfitCommandV2,
},
'0xdEBd95B6fea8F2c39e0232358608Acfd7E557A5A': {
type: CommandContractType.DmaMorphoBlueStopLossCommandV2,
},
'0xCe72966Ea1a8777e0E2Fb60c476C6cA8D59bEfdd': {
type: CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2,
},
},
[EthereumNetwork.BASE]: {
'0xb7CB13e4cD2D64e739b5746563978Ab7ee36B064': {
Expand Down Expand Up @@ -599,6 +693,78 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
'uint256', // targetLtv
'uint256', // excutionPrice
'uint64', // deviation
'bool', // withdrawToDebt
],

// Morpho
[CommandContractType.DmaMorphoBlueBasicBuyCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'bytes32', // marketId
'uint8', // quote decimals
'uint8', // collateral decimals
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // maxBuyPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
],
[CommandContractType.DmaMorphoBlueBasicSellCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'bytes32', // marketId
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // minSellPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
],
[CommandContractType.DmaMorphoBlueStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'bytes32', // marketId
'uint256', // executionLTV
'bool', // closeToCollateral
],
[CommandContractType.DmaMorphoBluePartialTakeProfitCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'bytes32', // marketId
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // executionPrice
'uint64', // deviation
'bool', // withdrawToDebt
],
[CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'bytes32', // marketId
'address', // collateralOracle
'uint80', // collateralAddedRoundId
'address', // debtOracle
'uint80', // debtAddedRoundId
'uint256', // trailingDistance
'bool', // closeToCollateral
],
} as const;
Expand All @@ -617,6 +783,11 @@ export const defaultCommandOffchainDataTypeMapping: Partial<Record<
'uint80', // debtClosestPriceRoundId
'uint80', // debtNextPriceRoundId
],
[CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2]: [
'uint80', // collateralMaxPriceRoundId
'uint80', // debtClosestPriceRoundId
'uint80', // debtNextPriceRoundId
],
} as const;

export function getCommandAddresses(network: number): Record<CommandContractType, string[]> {
Expand Down
30 changes: 29 additions & 1 deletion packages/automation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export enum CommandContractType {
DmaSparkBasicSellCommandV2 = 'DmaSparkBasicSellCommandV2',
DmaAavePartialTakeProfitCommandV2 = 'DmaAaveV3PartialTakeProfitCommandV2',
DmaSparkPartialTakeProfitCommandV2 = 'DmaSparkPartialTakeProfitCommandV2',

DmaMorphoBlueBasicBuyCommandV2 = 'DmaMorphoBlueBasicBuyCommandV2',
DmaMorphoBlueBasicSellCommandV2 = 'DmaMorphoBlueBasicSellCommandV2',
DmaMorphoBluePartialTakeProfitCommandV2 = 'DmaMorphoBluePartialTakeProfitCommandV2',
DmaMorphoBlueStopLossCommandV2 = 'DmaMorphoBlueStopLossCommandV2',
DmaMorphoBlueTrailingStopLossCommandV2 = 'DmaMorphoBlueTrailingStopLossCommandV2',
}

export enum TriggerType {
Expand Down Expand Up @@ -65,9 +71,23 @@ export enum TriggerType {
DmaSparkPartialTakeProfitV2 = 134,
DmaAaveTrailingStopLossV2 = 10006,
DmaSparkTrailingStopLossV2 = 10007,
// DmaMorphoBlueBasicBuyV2 = 135,
// DmaMorphoBlueBasicSellV2 = 136,
// DmaMorphoBluePartialTakeProfitV2 = 137,
// DmaMorphoBlueStopLossV2 = 138,
// DmaMorphoBlueTrailingStopLossV2 = 10008,
DmaMorphoBlueBasicBuyV2 = 139,
DmaMorphoBlueBasicSellV2 = 140,
DmaMorphoBluePartialTakeProfitV2 = 141,
DmaMorphoBlueStopLossV2 = 142,
DmaMorphoBlueTrailingStopLossV2 = 10009,
}

export const TrailingStopLossTriggers = [TriggerType.DmaAaveTrailingStopLossV2, TriggerType.DmaSparkTrailingStopLossV2];
export const TrailingStopLossTriggers = [
TriggerType.DmaAaveTrailingStopLossV2,
TriggerType.DmaSparkTrailingStopLossV2,
TriggerType.DmaMorphoBlueTrailingStopLossV2,
];

export const triggerTypeToCommandContractTypeMap: Record<TriggerType, CommandContractType> = {
[TriggerType.StopLossToCollateral]: CommandContractType.CloseCommand,
Expand Down Expand Up @@ -101,6 +121,14 @@ export const triggerTypeToCommandContractTypeMap: Record<TriggerType, CommandCon
[TriggerType.DmaSparkBasicSellV2]: CommandContractType.DmaSparkBasicSellCommandV2,
[TriggerType.DmaAavePartialTakeProfitV2]: CommandContractType.DmaAavePartialTakeProfitCommandV2,
[TriggerType.DmaSparkPartialTakeProfitV2]: CommandContractType.DmaSparkPartialTakeProfitCommandV2,

[TriggerType.DmaMorphoBlueBasicBuyV2]: CommandContractType.DmaMorphoBlueBasicBuyCommandV2,
[TriggerType.DmaMorphoBlueBasicSellV2]: CommandContractType.DmaMorphoBlueBasicSellCommandV2,
[TriggerType.DmaMorphoBluePartialTakeProfitV2]:
CommandContractType.DmaMorphoBluePartialTakeProfitCommandV2,
[TriggerType.DmaMorphoBlueStopLossV2]: CommandContractType.DmaMorphoBlueStopLossCommandV2,
[TriggerType.DmaMorphoBlueTrailingStopLossV2]:
CommandContractType.DmaMorphoBlueTrailingStopLossCommandV2,
};

export enum TriggerGroupType {
Expand Down

0 comments on commit ab4a0f1

Please sign in to comment.