Skip to content

Commit

Permalink
🚀 feat: add partial take profit triggers (#114)
Browse files Browse the repository at this point in the history
* chore: add partial take profit triggers

* chore: change version

* chore: add `excutionPrice` to partial take profit trigger data

* chore: update name
  • Loading branch information
halaprix authored Mar 4, 2024
1 parent 7a77408 commit 59eb3ee
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 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": "[email protected]",
"version": "1.6.3",
"version": "1.6.4-alpha.1",
"description": "The set of utilities for Oasis automation",
"homepage": "https://github.com/OasisDEX/common#readme",
"main": "lib/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions packages/automation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { getCommandAddresses, commandTypeJsonMapping } from './mapping';
export {
CommandContractType,
TriggerType,
TrailingStopLossTriggers,
TriggerGroupType,
triggerTypeToCommandContractTypeMap,
} from './types';
68 changes: 60 additions & 8 deletions packages/automation/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ export const commandTypeJsonMapping: Record<CommandContractType, string[]> = {
'deviation',
'maxBaseFeeInGwei',
],
[CommandContractType.DmaSparkPartialTakeProfitCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'excutionPrice',
'deviation',
'withdrawToDebt',
],
[CommandContractType.DmaAavePartialTakeProfitCommandV2]: [
'positionAddress',
'triggerType',
'maxCoverage',
'debtToken',
'collateralToken',
'operationName',
'executionLtv',
'targetLtv',
'excutionPrice',
'deviation',
'withdrawToDebt',
],
};
export const commandOffchainDataTypeJsonMapping: Partial<Record<CommandContractType, string[]>> = {
[CommandContractType.DmaAaveTrailingStopLossCommandV2]: [
Expand Down Expand Up @@ -428,8 +454,8 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // maxBuyPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
Expand All @@ -441,8 +467,8 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // minSellPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
Expand Down Expand Up @@ -500,8 +526,8 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // maxBuyPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
Expand All @@ -513,12 +539,38 @@ export const defaultCommandTypeMapping: Record<CommandContractType, ParamDefinit
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execCollRatio
'uint256', // targetCollRatio
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // minSellPrice
'uint64', // deviation
'uint32', // maxBaseFeeInGwei
],
[CommandContractType.DmaAavePartialTakeProfitCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // excutionPrice
'uint64', // deviation
'bool', // closeToCollateral
],
[CommandContractType.DmaSparkPartialTakeProfitCommandV2]: [
'address', //positionAddress
'uint16', // triggerType
'uint256', // maxCoverage
'address', // debtToken
'address', // collateralToken
'bytes32', // operationName
'uint256', // execLtv
'uint256', // targetLtv
'uint256', // excutionPrice
'uint64', // deviation
'bool', // closeToCollateral
],
} as const;

export const defaultCommandOffchainDataTypeMapping: Partial<Record<
Expand Down
8 changes: 8 additions & 0 deletions packages/automation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export enum CommandContractType {
DmaSparkTrailingStopLossCommandV2 = 'DmaSparkTrailingStopLossCommandV2',
DmaSparkBasicBuyCommandV2 = 'DmaSparkBasicBuyCommandV2',
DmaSparkBasicSellCommandV2 = 'DmaSparkBasicSellCommandV2',
DmaAavePartialTakeProfitCommandV2 = 'DmaAaveV3PartialTakeProfitCommandV2',
DmaSparkPartialTakeProfitCommandV2 = 'DmaSparkPartialTakeProfitCommandV2',
}

export enum TriggerType {
Expand Down Expand Up @@ -59,10 +61,14 @@ export enum TriggerType {
DmaSparkStopLossToDebtV2 = 130,
DmaSparkBasicBuyV2 = 131,
DmaSparkBasicSellV2 = 132,
DmaAavePartialTakeProfitV2 = 133,
DmaSparkPartialTakeProfitV2 = 134,
DmaAaveTrailingStopLossV2 = 10006,
DmaSparkTrailingStopLossV2 = 10007,
}

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

export const triggerTypeToCommandContractTypeMap: Record<TriggerType, CommandContractType> = {
[TriggerType.StopLossToCollateral]: CommandContractType.CloseCommand,
[TriggerType.StopLossToDai]: CommandContractType.CloseCommand,
Expand Down Expand Up @@ -93,6 +99,8 @@ export const triggerTypeToCommandContractTypeMap: Record<TriggerType, CommandCon
[TriggerType.DmaSparkTrailingStopLossV2]: CommandContractType.DmaSparkTrailingStopLossCommandV2,
[TriggerType.DmaSparkBasicBuyV2]: CommandContractType.DmaSparkBasicBuyCommandV2,
[TriggerType.DmaSparkBasicSellV2]: CommandContractType.DmaSparkBasicSellCommandV2,
[TriggerType.DmaAavePartialTakeProfitV2]: CommandContractType.DmaAavePartialTakeProfitCommandV2,
[TriggerType.DmaSparkPartialTakeProfitV2]: CommandContractType.DmaSparkPartialTakeProfitCommandV2,
};

export enum TriggerGroupType {
Expand Down

0 comments on commit 59eb3ee

Please sign in to comment.