@defisaver/automation-sdk 3.3.19-sub-fetching-dev → 3.3.19-sub-fetching.2-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 +3 -8
- package/cjs/automation/private/StrategiesAutomation.test.js +4 -8
- package/cjs/services/apiSubscriptionsService.test.js +0 -2
- package/cjs/types/enums.d.ts +0 -6
- package/cjs/types/enums.js +1 -8
- package/cjs/types/index.d.ts +1 -5
- package/esm/automation/private/StrategiesAutomation.js +4 -9
- package/esm/automation/private/StrategiesAutomation.test.js +5 -9
- package/esm/services/apiSubscriptionsService.test.js +1 -3
- package/esm/types/enums.d.ts +0 -6
- package/esm/types/enums.js +0 -7
- package/esm/types/index.d.ts +1 -5
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +3 -8
- package/src/automation/private/StrategiesAutomation.ts +2 -9
- package/src/services/apiSubscriptionsService.test.ts +1 -3
- package/src/types/enums.ts +0 -7
- package/src/types/index.ts +0 -5
|
@@ -127,11 +127,9 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
127
127
|
if (mergePairIndex !== -1) {
|
|
128
128
|
const mergePair = mergeExtension[mergePairIndex];
|
|
129
129
|
mergeExtension.splice(mergePairIndex, 1);
|
|
130
|
-
subscriptions.push(Object.assign(Object.assign(Object.assign(
|
|
130
|
+
subscriptions.push(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
131
131
|
// @ts-ignore
|
|
132
|
-
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled
|
|
133
|
-
status: mergePair.status === enums_1.SubscriptionStatus.Active ? enums_1.SubscriptionStatus.Active : current.status,
|
|
134
|
-
})), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
132
|
+
blockNumber: decimal_js_1.default.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled, specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
135
133
|
}
|
|
136
134
|
else {
|
|
137
135
|
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
@@ -197,10 +195,7 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
197
195
|
*/
|
|
198
196
|
parseSubscriptionsFromApi(records, options) {
|
|
199
197
|
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
200
|
-
let subscriptions = filtered.map((record) =>
|
|
201
|
-
const position = this.getParsedSubscriptions((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, this.chainId));
|
|
202
|
-
return position && Object.assign(Object.assign({}, position), { status: record.status });
|
|
203
|
-
});
|
|
198
|
+
let subscriptions = filtered.map((record) => this.getParsedSubscriptions((0, apiSubscriptionsService_1.parseDataFromApiSubscription)(record, this.chainId)));
|
|
204
199
|
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
205
200
|
subscriptions = this.mergeSubs(subscriptions);
|
|
206
201
|
}
|
|
@@ -712,8 +712,6 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
712
712
|
wallet: owner,
|
|
713
713
|
wallet_type: 'safe',
|
|
714
714
|
is_enabled: true,
|
|
715
|
-
invalid: false,
|
|
716
|
-
status: enums_1.SubscriptionStatus.Active,
|
|
717
715
|
is_bundle: true,
|
|
718
716
|
strategy_or_bundle_id: 8,
|
|
719
717
|
strategy_ids: [34, 35],
|
|
@@ -723,21 +721,19 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
723
721
|
block_number: 18015756,
|
|
724
722
|
additional_triggers: null,
|
|
725
723
|
};
|
|
726
|
-
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false,
|
|
727
|
-
it('Given API records should return parsed positions
|
|
724
|
+
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
725
|
+
it('Given API records should return parsed positions', () => {
|
|
728
726
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
729
727
|
(0, chai_1.expect)(positions).to.have.length(2);
|
|
730
728
|
(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
729
|
(0, chai_1.expect)(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
733
730
|
});
|
|
734
|
-
it('Given mergeSubs option should merge the repay and boost pair
|
|
735
|
-
var _a, _b
|
|
731
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
732
|
+
var _a, _b;
|
|
736
733
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
737
734
|
(0, chai_1.expect)(positions).to.have.length(1);
|
|
738
735
|
(0, chai_1.expect)((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
739
736
|
(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
737
|
});
|
|
742
738
|
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
743
739
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
@@ -13,8 +13,6 @@ describe('Feature: apiSubscriptionsService.ts', () => {
|
|
|
13
13
|
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
14
14
|
wallet_type: 'safe',
|
|
15
15
|
is_enabled: true,
|
|
16
|
-
invalid: false,
|
|
17
|
-
status: enums_1.SubscriptionStatus.Active,
|
|
18
16
|
is_bundle: true,
|
|
19
17
|
strategy_or_bundle_id: 8,
|
|
20
18
|
strategy_ids: [34, 35],
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -4,12 +4,6 @@ export declare enum ChainId {
|
|
|
4
4
|
Arbitrum = 42161,
|
|
5
5
|
Base = 8453
|
|
6
6
|
}
|
|
7
|
-
export declare enum SubscriptionStatus {
|
|
8
|
-
Active = "active",
|
|
9
|
-
Disabled = "disabled",
|
|
10
|
-
Finished = "finished",
|
|
11
|
-
Invalid = "invalid"
|
|
12
|
-
}
|
|
13
7
|
export declare enum RatioState {
|
|
14
8
|
OVER = 0,
|
|
15
9
|
UNDER = 1
|
package/cjs/types/enums.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.CloseToAssetType = exports.CloseStrategyType = exports.DebtActionType = exports.CollActionType = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.
|
|
3
|
+
exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.CloseToAssetType = exports.CloseStrategyType = exports.DebtActionType = exports.CollActionType = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.ChainId = void 0;
|
|
4
4
|
var ChainId;
|
|
5
5
|
(function (ChainId) {
|
|
6
6
|
ChainId[ChainId["Ethereum"] = 1] = "Ethereum";
|
|
@@ -8,13 +8,6 @@ var ChainId;
|
|
|
8
8
|
ChainId[ChainId["Arbitrum"] = 42161] = "Arbitrum";
|
|
9
9
|
ChainId[ChainId["Base"] = 8453] = "Base";
|
|
10
10
|
})(ChainId = exports.ChainId || (exports.ChainId = {}));
|
|
11
|
-
var SubscriptionStatus;
|
|
12
|
-
(function (SubscriptionStatus) {
|
|
13
|
-
SubscriptionStatus["Active"] = "active";
|
|
14
|
-
SubscriptionStatus["Disabled"] = "disabled";
|
|
15
|
-
SubscriptionStatus["Finished"] = "finished";
|
|
16
|
-
SubscriptionStatus["Invalid"] = "invalid";
|
|
17
|
-
})(SubscriptionStatus = exports.SubscriptionStatus || (exports.SubscriptionStatus = {}));
|
|
18
11
|
var RatioState;
|
|
19
12
|
(function (RatioState) {
|
|
20
13
|
RatioState[RatioState["OVER"] = 0] = "OVER";
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Web3 from 'web3';
|
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
4
|
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
|
-
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType
|
|
5
|
+
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
8
8
|
export type BlockNumber = BlockType;
|
|
@@ -59,8 +59,6 @@ export interface ApiSubscriptionRecord {
|
|
|
59
59
|
wallet: EthereumAddress;
|
|
60
60
|
wallet_type: string;
|
|
61
61
|
is_enabled: boolean;
|
|
62
|
-
invalid: boolean;
|
|
63
|
-
status: SubscriptionStatus;
|
|
64
62
|
is_bundle: boolean;
|
|
65
63
|
strategy_or_bundle_id: number;
|
|
66
64
|
strategy_ids: number[];
|
|
@@ -255,8 +253,6 @@ export declare namespace Position {
|
|
|
255
253
|
subId: number;
|
|
256
254
|
subIds?: number[];
|
|
257
255
|
isEnabled?: boolean;
|
|
258
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
259
|
-
status?: SubscriptionStatus;
|
|
260
256
|
subHash: string;
|
|
261
257
|
blockNumber: BlockNumber;
|
|
262
258
|
protocol: Interfaces.Protocol;
|
|
@@ -9,7 +9,7 @@ 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';
|
|
@@ -122,11 +122,9 @@ export default class StrategiesAutomation extends Automation {
|
|
|
122
122
|
if (mergePairIndex !== -1) {
|
|
123
123
|
const mergePair = mergeExtension[mergePairIndex];
|
|
124
124
|
mergeExtension.splice(mergePairIndex, 1);
|
|
125
|
-
subscriptions.push(Object.assign(Object.assign(Object.assign(
|
|
125
|
+
subscriptions.push(Object.assign(Object.assign(Object.assign({}, mergePair), current), {
|
|
126
126
|
// @ts-ignore
|
|
127
|
-
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled }),
|
|
128
|
-
status: mergePair.status === SubscriptionStatus.Active ? SubscriptionStatus.Active : current.status,
|
|
129
|
-
})), { specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
127
|
+
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(), subIds: [current.subId, mergePair.subId], isEnabled: mergePair.isEnabled || current.isEnabled, specific: Object.assign(Object.assign({}, mergePair.specific), current.specific) }));
|
|
130
128
|
}
|
|
131
129
|
else {
|
|
132
130
|
subscriptions.push(Object.assign(Object.assign({}, current), { subIds: [current.subId] }));
|
|
@@ -192,10 +190,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
192
190
|
*/
|
|
193
191
|
parseSubscriptionsFromApi(records, options) {
|
|
194
192
|
const filtered = (options === null || options === void 0 ? void 0 : options.enabledOnly) ? records.filter((record) => record.is_enabled) : records;
|
|
195
|
-
let subscriptions = filtered.map((record) =>
|
|
196
|
-
const position = this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId));
|
|
197
|
-
return position && Object.assign(Object.assign({}, position), { status: record.status });
|
|
198
|
-
});
|
|
193
|
+
let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
|
|
199
194
|
if (options === null || options === void 0 ? void 0 : options.mergeSubs) {
|
|
200
195
|
subscriptions = this.mergeSubs(subscriptions);
|
|
201
196
|
}
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Web3 from 'web3';
|
|
11
11
|
import { expect } from 'chai';
|
|
12
|
-
import { ChainId
|
|
12
|
+
import { ChainId } from '../../types/enums';
|
|
13
13
|
import '../../configuration';
|
|
14
14
|
import StrategiesAutomation from './StrategiesAutomation';
|
|
15
15
|
require('dotenv').config({ path: '.env' });
|
|
@@ -707,8 +707,6 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
707
707
|
wallet: owner,
|
|
708
708
|
wallet_type: 'safe',
|
|
709
709
|
is_enabled: true,
|
|
710
|
-
invalid: false,
|
|
711
|
-
status: SubscriptionStatus.Active,
|
|
712
710
|
is_bundle: true,
|
|
713
711
|
strategy_or_bundle_id: 8,
|
|
714
712
|
strategy_ids: [34, 35],
|
|
@@ -718,21 +716,19 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
718
716
|
block_number: 18015756,
|
|
719
717
|
additional_triggers: null,
|
|
720
718
|
};
|
|
721
|
-
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false,
|
|
722
|
-
it('Given API records should return parsed positions
|
|
719
|
+
const boost = Object.assign(Object.assign({}, repay), { id: 380, is_enabled: false, strategy_or_bundle_id: 9, sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111', trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'] });
|
|
720
|
+
it('Given API records should return parsed positions', () => {
|
|
723
721
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
724
722
|
expect(positions).to.have.length(2);
|
|
725
723
|
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
724
|
expect(positions.map((p) => p === null || p === void 0 ? void 0 : p.isEnabled)).to.eql([true, false]);
|
|
728
725
|
});
|
|
729
|
-
it('Given mergeSubs option should merge the repay and boost pair
|
|
730
|
-
var _a, _b
|
|
726
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
727
|
+
var _a, _b;
|
|
731
728
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
732
729
|
expect(positions).to.have.length(1);
|
|
733
730
|
expect((_a = positions[0]) === null || _a === void 0 ? void 0 : _a.subIds).to.eql([379, 380]);
|
|
734
731
|
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
732
|
});
|
|
737
733
|
it('Given enabledOnly option should drop disabled records before parsing', () => {
|
|
738
734
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { enabledOnly: true });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import { ChainId
|
|
2
|
+
import { ChainId } from '../types/enums';
|
|
3
3
|
import '../configuration';
|
|
4
4
|
import { parseDataFromApiSubscription } from './apiSubscriptionsService';
|
|
5
5
|
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
@@ -11,8 +11,6 @@ describe('Feature: apiSubscriptionsService.ts', () => {
|
|
|
11
11
|
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
12
12
|
wallet_type: 'safe',
|
|
13
13
|
is_enabled: true,
|
|
14
|
-
invalid: false,
|
|
15
|
-
status: SubscriptionStatus.Active,
|
|
16
14
|
is_bundle: true,
|
|
17
15
|
strategy_or_bundle_id: 8,
|
|
18
16
|
strategy_ids: [34, 35],
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -4,12 +4,6 @@ export declare enum ChainId {
|
|
|
4
4
|
Arbitrum = 42161,
|
|
5
5
|
Base = 8453
|
|
6
6
|
}
|
|
7
|
-
export declare enum SubscriptionStatus {
|
|
8
|
-
Active = "active",
|
|
9
|
-
Disabled = "disabled",
|
|
10
|
-
Finished = "finished",
|
|
11
|
-
Invalid = "invalid"
|
|
12
|
-
}
|
|
13
7
|
export declare enum RatioState {
|
|
14
8
|
OVER = 0,
|
|
15
9
|
UNDER = 1
|
package/esm/types/enums.js
CHANGED
|
@@ -5,13 +5,6 @@ export var ChainId;
|
|
|
5
5
|
ChainId[ChainId["Arbitrum"] = 42161] = "Arbitrum";
|
|
6
6
|
ChainId[ChainId["Base"] = 8453] = "Base";
|
|
7
7
|
})(ChainId || (ChainId = {}));
|
|
8
|
-
export var SubscriptionStatus;
|
|
9
|
-
(function (SubscriptionStatus) {
|
|
10
|
-
SubscriptionStatus["Active"] = "active";
|
|
11
|
-
SubscriptionStatus["Disabled"] = "disabled";
|
|
12
|
-
SubscriptionStatus["Finished"] = "finished";
|
|
13
|
-
SubscriptionStatus["Invalid"] = "invalid";
|
|
14
|
-
})(SubscriptionStatus || (SubscriptionStatus = {}));
|
|
15
8
|
export var RatioState;
|
|
16
9
|
(function (RatioState) {
|
|
17
10
|
RatioState[RatioState["OVER"] = 0] = "OVER";
|
package/esm/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Web3 from 'web3';
|
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
4
|
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
|
-
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType
|
|
5
|
+
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
8
8
|
export type BlockNumber = BlockType;
|
|
@@ -59,8 +59,6 @@ export interface ApiSubscriptionRecord {
|
|
|
59
59
|
wallet: EthereumAddress;
|
|
60
60
|
wallet_type: string;
|
|
61
61
|
is_enabled: boolean;
|
|
62
|
-
invalid: boolean;
|
|
63
|
-
status: SubscriptionStatus;
|
|
64
62
|
is_bundle: boolean;
|
|
65
63
|
strategy_or_bundle_id: number;
|
|
66
64
|
strategy_ids: number[];
|
|
@@ -255,8 +253,6 @@ export declare namespace Position {
|
|
|
255
253
|
subId: number;
|
|
256
254
|
subIds?: number[];
|
|
257
255
|
isEnabled?: boolean;
|
|
258
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
259
|
-
status?: SubscriptionStatus;
|
|
260
256
|
subHash: string;
|
|
261
257
|
blockNumber: BlockNumber;
|
|
262
258
|
protocol: Interfaces.Protocol;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Web3 from 'web3';
|
|
2
2
|
import { expect } from 'chai';
|
|
3
3
|
|
|
4
|
-
import { ChainId
|
|
4
|
+
import { ChainId } from '../../types/enums';
|
|
5
5
|
import type { ApiSubscriptionRecord } from '../../types';
|
|
6
6
|
|
|
7
7
|
import '../../configuration';
|
|
@@ -722,8 +722,6 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
722
722
|
wallet: owner,
|
|
723
723
|
wallet_type: 'safe',
|
|
724
724
|
is_enabled: true,
|
|
725
|
-
invalid: false,
|
|
726
|
-
status: SubscriptionStatus.Active,
|
|
727
725
|
is_bundle: true,
|
|
728
726
|
strategy_or_bundle_id: 8,
|
|
729
727
|
strategy_ids: [34, 35],
|
|
@@ -737,26 +735,23 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
737
735
|
...repay,
|
|
738
736
|
id: 380,
|
|
739
737
|
is_enabled: false,
|
|
740
|
-
status: SubscriptionStatus.Disabled,
|
|
741
738
|
strategy_or_bundle_id: 9,
|
|
742
739
|
sub_data_hash: '0x1111111111111111111111111111111111111111111111111111111111111111',
|
|
743
740
|
trigger_data: ['0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002386f26fc10000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
744
741
|
};
|
|
745
742
|
|
|
746
|
-
it('Given API records should return parsed positions
|
|
743
|
+
it('Given API records should return parsed positions', () => {
|
|
747
744
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost]);
|
|
748
745
|
expect(positions).to.have.length(2);
|
|
749
746
|
expect(positions.map((p) => p?.subId)).to.eql([379, 380]);
|
|
750
|
-
expect(positions.map((p) => p?.status)).to.eql([SubscriptionStatus.Active, SubscriptionStatus.Disabled]);
|
|
751
747
|
expect(positions.map((p) => p?.isEnabled)).to.eql([true, false]);
|
|
752
748
|
});
|
|
753
749
|
|
|
754
|
-
it('Given mergeSubs option should merge the repay and boost pair
|
|
750
|
+
it('Given mergeSubs option should merge the repay and boost pair', () => {
|
|
755
751
|
const positions = strategiesAutomation.parseSubscriptionsFromApi([repay, boost], { mergeSubs: true });
|
|
756
752
|
expect(positions).to.have.length(1);
|
|
757
753
|
expect(positions[0]?.subIds).to.eql([379, 380]);
|
|
758
754
|
expect(positions[0]?.isEnabled).to.equal(true);
|
|
759
|
-
expect(positions[0]?.status).to.equal(SubscriptionStatus.Active);
|
|
760
755
|
});
|
|
761
756
|
|
|
762
757
|
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';
|
|
@@ -169,10 +169,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
169
169
|
blockNumber: Dec.max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
170
170
|
subIds: [current.subId, mergePair.subId],
|
|
171
171
|
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
172
|
-
// status is set only for subscriptions parsed from the automation API
|
|
173
|
-
...addToObjectIf(isDefined(current.status), {
|
|
174
|
-
status: mergePair.status === SubscriptionStatus.Active ? SubscriptionStatus.Active : current.status,
|
|
175
|
-
}),
|
|
176
172
|
specific: {
|
|
177
173
|
...mergePair.specific,
|
|
178
174
|
...current.specific,
|
|
@@ -271,10 +267,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
271
267
|
public parseSubscriptionsFromApi(records: ApiSubscriptionRecord[], options?: SubscriptionOptions): (Position.Automated | null)[] {
|
|
272
268
|
const filtered = options?.enabledOnly ? records.filter((record) => record.is_enabled) : records;
|
|
273
269
|
|
|
274
|
-
let subscriptions
|
|
275
|
-
const position = this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId));
|
|
276
|
-
return position && { ...position, status: record.status };
|
|
277
|
-
});
|
|
270
|
+
let subscriptions = filtered.map((record) => this.getParsedSubscriptions(parseDataFromApiSubscription(record, this.chainId)));
|
|
278
271
|
|
|
279
272
|
if (options?.mergeSubs) {
|
|
280
273
|
subscriptions = this.mergeSubs(subscriptions);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
3
|
import type { ApiSubscriptionRecord, ParseData } from '../types';
|
|
4
|
-
import { ChainId
|
|
4
|
+
import { ChainId } from '../types/enums';
|
|
5
5
|
|
|
6
6
|
import '../configuration';
|
|
7
7
|
import { parseDataFromApiSubscription } from './apiSubscriptionsService';
|
|
@@ -15,8 +15,6 @@ describe('Feature: apiSubscriptionsService.ts', () => {
|
|
|
15
15
|
wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
16
16
|
wallet_type: 'safe',
|
|
17
17
|
is_enabled: true,
|
|
18
|
-
invalid: false,
|
|
19
|
-
status: SubscriptionStatus.Active,
|
|
20
18
|
is_bundle: true,
|
|
21
19
|
strategy_or_bundle_id: 8,
|
|
22
20
|
strategy_ids: [34, 35],
|
package/src/types/enums.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -6,7 +6,6 @@ import type {
|
|
|
6
6
|
ChainId, Strategies, Bundles, ProtocolIdentifiers,
|
|
7
7
|
RatioState,
|
|
8
8
|
CloseToAssetType,
|
|
9
|
-
SubscriptionStatus,
|
|
10
9
|
} from './enums';
|
|
11
10
|
|
|
12
11
|
export type PlaceholderType = any; // TODO - fix any types
|
|
@@ -79,8 +78,6 @@ export interface ApiSubscriptionRecord {
|
|
|
79
78
|
wallet: EthereumAddress,
|
|
80
79
|
wallet_type: string,
|
|
81
80
|
is_enabled: boolean,
|
|
82
|
-
invalid: boolean,
|
|
83
|
-
status: SubscriptionStatus,
|
|
84
81
|
is_bundle: boolean,
|
|
85
82
|
strategy_or_bundle_id: number,
|
|
86
83
|
strategy_ids: number[],
|
|
@@ -320,8 +317,6 @@ export declare namespace Position {
|
|
|
320
317
|
subId: number,
|
|
321
318
|
subIds?: number[],
|
|
322
319
|
isEnabled?: boolean,
|
|
323
|
-
/** Set only for subscriptions parsed from the automation API */
|
|
324
|
-
status?: SubscriptionStatus,
|
|
325
320
|
subHash: string,
|
|
326
321
|
blockNumber: BlockNumber,
|
|
327
322
|
protocol: Interfaces.Protocol,
|