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

🚀 feat: add partial take profit triggers #114

Merged
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
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.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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is it closeToColalteral or withdrawToDebt @halaprix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably withdrawToDebt

],
} 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
Loading