@defisaver/automation-sdk 3.3.19-sub-fetching-dev → 3.3.19-sub-fetching.1-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/automation/private/StrategiesAutomation.js +14 -4
- package/cjs/automation/private/StrategiesAutomation.test.js +16 -5
- package/cjs/types/index.d.ts +5 -2
- package/esm/automation/private/StrategiesAutomation.js +15 -5
- package/esm/automation/private/StrategiesAutomation.test.js +16 -5
- package/esm/types/index.d.ts +5 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +19 -5
- package/src/automation/private/StrategiesAutomation.ts +15 -6
- package/src/types/index.ts +5 -2
|
@@ -21,6 +21,18 @@ const ethereumService_1 = require("../../services/ethereumService");
|
|
|
21
21
|
const strategiesService_1 = require("../../services/strategiesService");
|
|
22
22
|
const apiSubscriptionsService_1 = require("../../services/apiSubscriptionsService");
|
|
23
23
|
const Automation_1 = __importDefault(require("./Automation"));
|
|
24
|
+
/**
|
|
25
|
+
* Adds the backend flags to a parsed position. A repay or boost half of a leverage management pair also gets its
|
|
26
|
+
* own invalid flag in specific, next to repayEnabled and boostEnabled, so it survives merging.
|
|
27
|
+
*/
|
|
28
|
+
const withApiFlags = (position, record) => {
|
|
29
|
+
const specific = Object.assign({}, position.specific);
|
|
30
|
+
if ((0, utils_1.isDefined)(specific.mergeWithId))
|
|
31
|
+
specific.repayInvalid = record.invalid;
|
|
32
|
+
if ((0, utils_1.isDefined)(specific.mergeId))
|
|
33
|
+
specific.boostInvalid = record.invalid;
|
|
34
|
+
return Object.assign(Object.assign({}, position), { invalid: record.invalid, specific: specific });
|
|
35
|
+
};
|
|
24
36
|
class StrategiesAutomation extends Automation_1.default {
|
|
25
37
|
constructor(args) {
|
|
26
38
|
super();
|
|
@@ -129,9 +141,7 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
129
141
|
mergeExtension.splice(mergePairIndex, 1);
|
|
130
142
|
subscriptions.push(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
131
143
|
// @ts-ignore
|
|
132
|
-
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled }), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(current.
|
|
133
|
-
status: mergePair.status === enums_1.SubscriptionStatus.Active ? enums_1.SubscriptionStatus.Active : current.status,
|
|
134
|
-
})), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
144
|
+
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled }), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(current.invalid), { invalid: !!mergePair.invalid && !!current.invalid })), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
135
145
|
}
|
|
136
146
|
else {
|
|
137
147
|
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
@@ -199,7 +209,7 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
199
209
|
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
200
210
|
let subscriptions = filtered.map((record) => {
|
|
201
211
|
const position = this.getParsedSubscriptions((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, this.chainId));
|
|
202
|
-
return position &&
|
|
212
|
+
return position && withApiFlags(position, record);
|
|
203
213
|
});
|
|
204
214
|
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
205
215
|
subscriptions = this.mergeSubs(subscriptions);
|
|
@@ -724,20 +724,31 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
724
724
|
additional_triggers: null,
|
|
725
725
|
};
|
|
726
726
|
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, status: enums_1.SubscriptionStatus.Disabled, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
727
|
-
it('Given API records should return parsed positions carrying the
|
|
728
|
-
|
|
727
|
+
it('Given API records should return parsed positions carrying the invalid flags', () => {
|
|
728
|
+
var _a, _b;
|
|
729
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, Object.assign(Object.assign({}, boost), { invalid: true })]);
|
|
729
730
|
(0, chai_1.expect)(positions).to.have.length(2);
|
|
730
731
|
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379, 380]);
|
|
731
|
-
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.status)).to.eql([enums_1.SubscriptionStatus.Active, enums_1.SubscriptionStatus.Disabled]);
|
|
732
732
|
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
733
|
+
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.invalid)).to.eql([false, true]);
|
|
734
|
+
(0, chai_1.expect)(((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.specific).repayInvalid).to.equal(false);
|
|
735
|
+
(0, chai_1.expect)(((_b = positions[1]) === null || _b === void 0 ? void 0 : _b.specific).boostInvalid).to.equal(true);
|
|
733
736
|
});
|
|
734
|
-
it('Given
|
|
737
|
+
it('Given a merged pair should keep each half\'s invalid flag and mark the pair invalid only when both are', () => {
|
|
735
738
|
var _a, _b, _c;
|
|
739
|
+
const oneInvalid = strategiesAutomation.parseSubscriptionsFromApi([repay, Object.assign(Object.assign({}, boost), { invalid: true })], { mergeSubs: true });
|
|
740
|
+
(0, chai_1.expect)(oneInvalid).to.have.length(1);
|
|
741
|
+
(0, chai_1.expect)((_a = oneInvalid[0]) === null || _a === void 0 ? void 0 : _a.invalid).to.equal(false);
|
|
742
|
+
(0, chai_1.expect)((_b = oneInvalid[0]) === null || _b === void 0 ? void 0 : _b.specific).to.include({ repayInvalid: false, boostInvalid: true });
|
|
743
|
+
const bothInvalid = strategiesAutomation.parseSubscriptionsFromApi([Object.assign(Object.assign({}, repay), { invalid: true }), Object.assign(Object.assign({}, boost), { invalid: true })], { mergeSubs: true });
|
|
744
|
+
(0, chai_1.expect)((_c = bothInvalid[0]) === null || _c === void 0 ? void 0 : _c.invalid).to.equal(true);
|
|
745
|
+
});
|
|
746
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
747
|
+
var _a, _b;
|
|
736
748
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
737
749
|
(0, chai_1.expect)(positions).to.have.length(1);
|
|
738
750
|
(0, chai_1.expect)((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
739
751
|
(0, chai_1.expect)((_b = positions[0]) === null || _b === void 0 ? void 0 : _b.isEnabled).to.equal(true);
|
|
740
|
-
(0, chai_1.expect)((_c = positions[0]) === null || _c === void 0 ? void 0 : _c.status).to.equal(enums_1.SubscriptionStatus.Active);
|
|
741
752
|
});
|
|
742
753
|
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
743
754
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -122,6 +122,9 @@ export declare namespace Position {
|
|
|
122
122
|
triggerBoostRatio?: number;
|
|
123
123
|
targetBoostRatio?: number;
|
|
124
124
|
boostEnabled?: boolean;
|
|
125
|
+
/** Set only for subscriptions parsed from the automation API: the backend marked that half invalid */
|
|
126
|
+
repayInvalid?: boolean;
|
|
127
|
+
boostInvalid?: boolean;
|
|
125
128
|
}
|
|
126
129
|
interface CloseOnPrice extends Base {
|
|
127
130
|
price: string;
|
|
@@ -255,8 +258,8 @@ export declare namespace Position {
|
|
|
255
258
|
subId: number;
|
|
256
259
|
subIds?: number[];
|
|
257
260
|
isEnabled?: boolean;
|
|
258
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
259
|
-
|
|
261
|
+
/** Set only for subscriptions parsed from the automation API: the backend will not execute this subscription */
|
|
262
|
+
invalid?: boolean;
|
|
260
263
|
subHash: string;
|
|
261
264
|
blockNumber: BlockNumber;
|
|
262
265
|
protocol: Interfaces.Protocol;
|
|
@@ -9,13 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import PromisePool from 'es6-promise-pool';
|
|
12
|
-
import { Strategies, ProtocolIdentifiers
|
|
12
|
+
import { Strategies, ProtocolIdentifiers } from '../../types/enums';
|
|
13
13
|
import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
|
|
14
14
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
15
15
|
import { getEventsFromContract, multicall } from '../../services/ethereumService';
|
|
16
16
|
import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
|
|
17
17
|
import { parseDataFromApiSubscription } from '../../services/apiSubscriptionsService';
|
|
18
18
|
import Automation from './Automation';
|
|
19
|
+
/**
|
|
20
|
+
* Adds the backend flags to a parsed position. A repay or boost half of a leverage management pair also gets its
|
|
21
|
+
* own invalid flag in specific, next to repayEnabled and boostEnabled, so it survives merging.
|
|
22
|
+
*/
|
|
23
|
+
const withApiFlags = (position, record) => {
|
|
24
|
+
const specific = Object.assign({}, position.specific);
|
|
25
|
+
if (isDefined(specific.mergeWithId))
|
|
26
|
+
specific.repayInvalid = record.invalid;
|
|
27
|
+
if (isDefined(specific.mergeId))
|
|
28
|
+
specific.boostInvalid = record.invalid;
|
|
29
|
+
return Object.assign(Object.assign({}, position), { invalid: record.invalid, specific: specific });
|
|
30
|
+
};
|
|
19
31
|
export default class StrategiesAutomation extends Automation {
|
|
20
32
|
constructor(args) {
|
|
21
33
|
super();
|
|
@@ -124,9 +136,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
124
136
|
mergeExtension.splice(mergePairIndex, 1);
|
|
125
137
|
subscriptions.push(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
126
138
|
// @ts-ignore
|
|
127
|
-
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled }), addToObjectIf(isDefined(current.
|
|
128
|
-
status: mergePair.status === SubscriptionStatus.Active ? SubscriptionStatus.Active : current.status,
|
|
129
|
-
})), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
139
|
+
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled }), addToObjectIf(isDefined(current.invalid), { invalid: !!mergePair.invalid && !!current.invalid })), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
130
140
|
}
|
|
131
141
|
else {
|
|
132
142
|
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
@@ -194,7 +204,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
194
204
|
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
195
205
|
let subscriptions = filtered.map((record) => {
|
|
196
206
|
const position = this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId));
|
|
197
|
-
return position &&
|
|
207
|
+
return position && withApiFlags(position, record);
|
|
198
208
|
});
|
|
199
209
|
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
200
210
|
subscriptions = this.mergeSubs(subscriptions);
|
|
@@ -719,20 +719,31 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
719
719
|
additional_triggers: null,
|
|
720
720
|
};
|
|
721
721
|
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, status: SubscriptionStatus.Disabled, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
722
|
-
it('Given API records should return parsed positions carrying the
|
|
723
|
-
|
|
722
|
+
it('Given API records should return parsed positions carrying the invalid flags', () => {
|
|
723
|
+
var _a, _b;
|
|
724
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, Object.assign(Object.assign({}, boost), { invalid: true })]);
|
|
724
725
|
expect(positions).to.have.length(2);
|
|
725
726
|
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.subId)).to.eql([379, 380]);
|
|
726
|
-
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.status)).to.eql([SubscriptionStatus.Active, SubscriptionStatus.Disabled]);
|
|
727
727
|
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
728
|
+
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.invalid)).to.eql([false, true]);
|
|
729
|
+
expect(((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.specific).repayInvalid).to.equal(false);
|
|
730
|
+
expect(((_b = positions[1]) === null || _b === void 0 ? void 0 : _b.specific).boostInvalid).to.equal(true);
|
|
728
731
|
});
|
|
729
|
-
it('Given
|
|
732
|
+
it('Given a merged pair should keep each half\'s invalid flag and mark the pair invalid only when both are', () => {
|
|
730
733
|
var _a, _b, _c;
|
|
734
|
+
const oneInvalid = strategiesAutomation.parseSubscriptionsFromApi([repay, Object.assign(Object.assign({}, boost), { invalid: true })], { mergeSubs: true });
|
|
735
|
+
expect(oneInvalid).to.have.length(1);
|
|
736
|
+
expect((_a = oneInvalid[0]) === null || _a === void 0 ? void 0 : _a.invalid).to.equal(false);
|
|
737
|
+
expect((_b = oneInvalid[0]) === null || _b === void 0 ? void 0 : _b.specific).to.include({ repayInvalid: false, boostInvalid: true });
|
|
738
|
+
const bothInvalid = strategiesAutomation.parseSubscriptionsFromApi([Object.assign(Object.assign({}, repay), { invalid: true }), Object.assign(Object.assign({}, boost), { invalid: true })], { mergeSubs: true });
|
|
739
|
+
expect((_c = bothInvalid[0]) === null || _c === void 0 ? void 0 : _c.invalid).to.equal(true);
|
|
740
|
+
});
|
|
741
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
742
|
+
var _a, _b;
|
|
731
743
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
732
744
|
expect(positions).to.have.length(1);
|
|
733
745
|
expect((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
734
746
|
expect((_b = positions[0]) === null || _b === void 0 ? void 0 : _b.isEnabled).to.equal(true);
|
|
735
|
-
expect((_c = positions[0]) === null || _c === void 0 ? void 0 : _c.status).to.equal(SubscriptionStatus.Active);
|
|
736
747
|
});
|
|
737
748
|
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
738
749
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
package/esm/types/index.d.ts
CHANGED
|
@@ -122,6 +122,9 @@ export declare namespace Position {
|
|
|
122
122
|
triggerBoostRatio?: number;
|
|
123
123
|
targetBoostRatio?: number;
|
|
124
124
|
boostEnabled?: boolean;
|
|
125
|
+
/** Set only for subscriptions parsed from the automation API: the backend marked that half invalid */
|
|
126
|
+
repayInvalid?: boolean;
|
|
127
|
+
boostInvalid?: boolean;
|
|
125
128
|
}
|
|
126
129
|
interface CloseOnPrice extends Base {
|
|
127
130
|
price: string;
|
|
@@ -255,8 +258,8 @@ export declare namespace Position {
|
|
|
255
258
|
subId: number;
|
|
256
259
|
subIds?: number[];
|
|
257
260
|
isEnabled?: boolean;
|
|
258
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
259
|
-
|
|
261
|
+
/** Set only for subscriptions parsed from the automation API: the backend will not execute this subscription */
|
|
262
|
+
invalid?: boolean;
|
|
260
263
|
subHash: string;
|
|
261
264
|
blockNumber: BlockNumber;
|
|
262
265
|
protocol: Interfaces.Protocol;
|
package/package.json
CHANGED
|
@@ -743,20 +743,34 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
743
743
|
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
744
744
|
};
|
|
745
745
|
|
|
746
|
-
it('Given API records should return parsed positions carrying the
|
|
747
|
-
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
746
|
+
it('Given API records should return parsed positions carrying the invalid flags', () => {
|
|
747
|
+
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, { ...boost, invalid: true }]);
|
|
748
748
|
expect(positions).to.have.length(2);
|
|
749
749
|
expect(positions.map((p) => p?.subId)).to.eql([379, 380]);
|
|
750
|
-
expect(positions.map((p) => p?.status)).to.eql([SubscriptionStatus.Active, SubscriptionStatus.Disabled]);
|
|
751
750
|
expect(positions.map((p) => p?.isEnabled)).to.eql([true, false]);
|
|
751
|
+
expect(positions.map((p) => p?.invalid)).to.eql([false, true]);
|
|
752
|
+
expect((positions[0]?.specific as { repayInvalid?: boolean }).repayInvalid).to.equal(false);
|
|
753
|
+
expect((positions[1]?.specific as { boostInvalid?: boolean }).boostInvalid).to.equal(true);
|
|
752
754
|
});
|
|
753
755
|
|
|
754
|
-
it('Given
|
|
756
|
+
it('Given a merged pair should keep each half\'s invalid flag and mark the pair invalid only when both are', () => {
|
|
757
|
+
const oneInvalid = strategiesAutomation.parseSubscriptionsFromApi([repay, { ...boost, invalid: true }], { mergeSubs: true });
|
|
758
|
+
expect(oneInvalid).to.have.length(1);
|
|
759
|
+
expect(oneInvalid[0]?.invalid).to.equal(false);
|
|
760
|
+
expect(oneInvalid[0]?.specific).to.include({ repayInvalid: false, boostInvalid: true });
|
|
761
|
+
|
|
762
|
+
const bothInvalid = strategiesAutomation.parseSubscriptionsFromApi(
|
|
763
|
+
[{ ...repay, invalid: true }, { ...boost, invalid: true }],
|
|
764
|
+
{ mergeSubs: true },
|
|
765
|
+
);
|
|
766
|
+
expect(bothInvalid[0]?.invalid).to.equal(true);
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
755
770
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
756
771
|
expect(positions).to.have.length(1);
|
|
757
772
|
expect(positions[0]?.subIds).to.eql([379, 380]);
|
|
758
773
|
expect(positions[0]?.isEnabled).to.equal(true);
|
|
759
|
-
expect(positions[0]?.status).to.equal(SubscriptionStatus.Active);
|
|
760
774
|
});
|
|
761
775
|
|
|
762
776
|
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
StrategyModel, Subscribe, SubStorage, UpdateData,
|
|
11
11
|
} from '../../types/contracts/generated/SubStorage';
|
|
12
12
|
import type { ChainId } from '../../types/enums';
|
|
13
|
-
import { Strategies, ProtocolIdentifiers
|
|
13
|
+
import { Strategies, ProtocolIdentifiers } from '../../types/enums';
|
|
14
14
|
|
|
15
15
|
import { addToObjectIf, isDefined, isUndefined } from '../../services/utils';
|
|
16
16
|
import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
|
|
@@ -25,6 +25,17 @@ interface IStrategiesAutomation extends Interfaces.Automation {
|
|
|
25
25
|
providerFork?: Web3,
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Adds the backend flags to a parsed position. A repay or boost half of a leverage management pair also gets its
|
|
30
|
+
* own invalid flag in specific, next to repayEnabled and boostEnabled, so it survives merging.
|
|
31
|
+
*/
|
|
32
|
+
const withApiFlags = (position: Position.Automated, record: ApiSubscriptionRecord): Position.Automated => {
|
|
33
|
+
const specific = { ...position.specific } as Position.Specific.RatioProtection;
|
|
34
|
+
if (isDefined(specific.mergeWithId)) specific.repayInvalid = record.invalid;
|
|
35
|
+
if (isDefined(specific.mergeId)) specific.boostInvalid = record.invalid;
|
|
36
|
+
return { ...position, invalid: record.invalid, specific: specific as Position.SpecificAny };
|
|
37
|
+
};
|
|
38
|
+
|
|
28
39
|
export default class StrategiesAutomation extends Automation {
|
|
29
40
|
protected chainId: ChainId;
|
|
30
41
|
|
|
@@ -169,10 +180,8 @@ export default class StrategiesAutomation extends Automation {
|
|
|
169
180
|
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
170
181
|
subIds: [current.subId, mergePair.subId],
|
|
171
182
|
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
172
|
-
//
|
|
173
|
-
...addToObjectIf(isDefined(current.
|
|
174
|
-
status: mergePair.status === SubscriptionStatus.Active ? SubscriptionStatus.Active : current.status,
|
|
175
|
-
}),
|
|
183
|
+
// set only for subscriptions parsed from the automation API, per half flags live in specific
|
|
184
|
+
...addToObjectIf(isDefined(current.invalid), { invalid: !!mergePair.invalid && !!current.invalid }),
|
|
176
185
|
specific: {
|
|
177
186
|
...mergePair.specific,
|
|
178
187
|
...current.specific,
|
|
@@ -273,7 +282,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
273
282
|
|
|
274
283
|
let subscriptions: (Position.Automated | null)[] = filtered.map((record) => {
|
|
275
284
|
const position = this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId));
|
|
276
|
-
return position &&
|
|
285
|
+
return position && withApiFlags(position, record);
|
|
277
286
|
});
|
|
278
287
|
|
|
279
288
|
if (options?.mergeSubs) {
|
package/src/types/index.ts
CHANGED
|
@@ -150,6 +150,9 @@ export declare namespace Position {
|
|
|
150
150
|
triggerBoostRatio?: number,
|
|
151
151
|
targetBoostRatio?: number,
|
|
152
152
|
boostEnabled?: boolean,
|
|
153
|
+
/** Set only for subscriptions parsed from the automation API: the backend marked that half invalid */
|
|
154
|
+
repayInvalid?: boolean,
|
|
155
|
+
boostInvalid?: boolean,
|
|
153
156
|
}
|
|
154
157
|
interface CloseOnPrice extends Base {
|
|
155
158
|
price: string,
|
|
@@ -320,8 +323,8 @@ export declare namespace Position {
|
|
|
320
323
|
subId: number,
|
|
321
324
|
subIds?: number[],
|
|
322
325
|
isEnabled?: boolean,
|
|
323
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
324
|
-
|
|
326
|
+
/** Set only for subscriptions parsed from the automation API: the backend will not execute this subscription */
|
|
327
|
+
invalid?: boolean,
|
|
325
328
|
subHash: string,
|
|
326
329
|
blockNumber: BlockNumber,
|
|
327
330
|
protocol: Interfaces.Protocol,
|