@defisaver/automation-sdk 1.2.1 → 1.2.3

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.
@@ -6,16 +6,19 @@ import Automation from './Automation';
6
6
  import type { ChainId } from '../../types/enums';
7
7
  interface IStrategiesAutomation extends Interfaces.Automation {
8
8
  chainId: ChainId;
9
+ providerFork: Web3;
9
10
  }
10
11
  export default class StrategiesAutomation extends Automation {
11
12
  protected chainId: ChainId;
12
13
  protected web3: Web3;
14
+ protected web3Fork: Web3;
13
15
  protected subStorageContract: Contract.WithMeta<SubStorage>;
16
+ protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
14
17
  constructor(args: IStrategiesAutomation);
15
- protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
18
+ protected getEventFromSubStorage(event: string, options?: PastEventOptions): Promise<any[]>;
16
19
  protected getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]>;
17
- protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
18
- protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
20
+ protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
21
+ protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
19
22
  protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
20
23
  protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
21
24
  getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
@@ -17,24 +17,37 @@ export default class StrategiesAutomation extends Automation {
17
17
  constructor(args) {
18
18
  super();
19
19
  this.web3 = args.provider;
20
+ this.web3Fork = args.providerFork;
20
21
  this.chainId = args.chainId;
21
22
  this.subStorageContract = makeSubStorageContract(this.web3, this.chainId);
23
+ this.subStorageContractFork = this.web3Fork ? makeSubStorageContract(this.web3Fork, this.chainId) : null;
22
24
  this.assert();
23
25
  }
24
26
  getEventFromSubStorage(event, options) {
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
- return getEventsFromContract(this.subStorageContract, event, options);
28
+ return getEventsFromContract(this.subStorageContract, this.subStorageContractFork, event, options);
27
29
  });
28
30
  }
29
31
  getStrategiesSubs(subIds) {
30
32
  return __awaiter(this, void 0, void 0, function* () {
31
- const subStorageContract = this.subStorageContract;
32
- const defaultOptions = {
33
- target: subStorageContract.address,
34
- abiItem: getAbiItem(subStorageContract.abi, 'strategiesSubs'),
35
- };
36
- const multicallCalls = subIds.map((subId) => (Object.assign(Object.assign({}, defaultOptions), { params: [subId] })));
37
- return multicall(this.web3, this.chainId, multicallCalls);
33
+ let options;
34
+ let web3;
35
+ if (this.web3Fork && this.subStorageContractFork) {
36
+ options = {
37
+ target: this.subStorageContractFork.address,
38
+ abiItem: getAbiItem(this.subStorageContractFork.abi, 'strategiesSubs'),
39
+ };
40
+ web3 = this.web3Fork;
41
+ }
42
+ else {
43
+ options = {
44
+ target: this.subStorageContract.address,
45
+ abiItem: getAbiItem(this.subStorageContract.abi, 'strategiesSubs'),
46
+ };
47
+ web3 = this.web3;
48
+ }
49
+ const multicallCalls = subIds.map((subId) => (Object.assign(Object.assign({}, options), { params: [subId] })));
50
+ return multicall(web3, this.chainId, multicallCalls);
38
51
  });
39
52
  }
40
53
  getSubscriptionEventsFromSubStorage(options) {
@@ -4,4 +4,4 @@ import type { BlockNumber, Multicall, Contract } from '../types';
4
4
  import type { BaseContract } from '../types/contracts/generated/types';
5
5
  import type { ChainId } from '../types/enums';
6
6
  export declare function multicall(web3: Web3, chainId: ChainId, calls: Multicall.Calls[], block?: BlockNumber): Promise<Multicall.Payload>;
7
- export declare function getEventsFromContract<T extends BaseContract>(contractWithMeta: Contract.WithMeta<T>, event: string, options?: PastEventOptions): Promise<import("web3-eth-contract").EventData[]>;
7
+ export declare function getEventsFromContract<T extends BaseContract>(contractWithMeta: Contract.WithMeta<T>, contractWithMetaFork: Contract.WithMeta<T> | null, event: string, options?: PastEventOptions): Promise<any[]>;
@@ -29,6 +29,13 @@ export function multicall(web3, chainId, calls, block = 'latest') {
29
29
  return formattedResult;
30
30
  });
31
31
  }
32
- export function getEventsFromContract(contractWithMeta, event, options) {
33
- return contractWithMeta.contract.getPastEvents(event, Object.assign({ fromBlock: contractWithMeta.createdBlock }, addToObjectIf(isDefined(options), options)));
32
+ export function getEventsFromContract(contractWithMeta, contractWithMetaFork, event, options) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const events = yield contractWithMeta.contract.getPastEvents(event, Object.assign({}, addToObjectIf(isDefined(options), Object.assign(Object.assign({}, options), { fromBlock: contractWithMeta.createdBlock }))));
35
+ let eventsFork = [];
36
+ if (contractWithMetaFork) {
37
+ eventsFork = yield contractWithMetaFork.contract.getPastEvents(event, Object.assign({}, addToObjectIf(isDefined(options), Object.assign(Object.assign({}, options), { toBlock: 'latest' }))));
38
+ }
39
+ return [...events, ...eventsFork];
40
+ });
34
41
  }
@@ -166,6 +166,7 @@ function parseCompoundV3LeverageManagement(position, parseData) {
166
166
  const subData = subDataService.compoundV3LeverageManagementSubData.decode(subStruct.subData);
167
167
  _position.strategyData.decoded.triggerData = triggerData;
168
168
  _position.strategyData.decoded.subData = subData;
169
+ _position.owner = triggerData.owner;
169
170
  const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
170
171
  if (isRepay) {
171
172
  _position.specific = {
@@ -66,6 +66,7 @@ export declare namespace Interfaces {
66
66
  }
67
67
  interface Automation {
68
68
  provider: Web3;
69
+ providerFork: Web3;
69
70
  }
70
71
  interface LegacyAutomation<T extends BaseContract> {
71
72
  provider: Web3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/index.js",
@@ -14,8 +14,7 @@
14
14
  "document": "npx typedoc --out docs/default",
15
15
  "lint": "node_modules/.bin/eslint ./src",
16
16
  "gtc": "node scripts/generateContractTypes.js",
17
- "prepare": "husky install && npm run gtc",
18
- "cpublish": "yarn build && yarn publish"
17
+ "prepare": "husky install && npm run gtc"
19
18
  },
20
19
  "author": "DeFi Saver",
21
20
  "repository": "https://github.com/defisaver/automation-sdk",
@@ -19,6 +19,7 @@ import type { ChainId } from '../../types/enums';
19
19
 
20
20
  interface IStrategiesAutomation extends Interfaces.Automation {
21
21
  chainId: ChainId,
22
+ providerFork: Web3,
22
23
  }
23
24
 
24
25
  export default class StrategiesAutomation extends Automation {
@@ -26,33 +27,48 @@ export default class StrategiesAutomation extends Automation {
26
27
 
27
28
  protected web3: Web3;
28
29
 
30
+ protected web3Fork: Web3;
31
+
29
32
  protected subStorageContract: Contract.WithMeta<SubStorage>;
30
33
 
34
+ protected subStorageContractFork: Contract.WithMeta<SubStorage> | null;
35
+
31
36
  constructor(args: IStrategiesAutomation) {
32
37
  super();
33
38
 
34
39
  this.web3 = args.provider;
40
+ this.web3Fork = args.providerFork;
35
41
  this.chainId = args.chainId;
36
42
  this.subStorageContract = makeSubStorageContract(this.web3, this.chainId);
43
+ this.subStorageContractFork = this.web3Fork ? makeSubStorageContract(this.web3Fork, this.chainId) : null;
37
44
 
38
45
  this.assert();
39
46
  }
40
47
 
41
48
  protected async getEventFromSubStorage(event: string, options?: PastEventOptions) {
42
- return getEventsFromContract<SubStorage>(this.subStorageContract, event, options);
49
+ return getEventsFromContract<SubStorage>(this.subStorageContract, this.subStorageContractFork, event, options);
43
50
  }
44
51
 
45
52
  protected async getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]> {
46
- const subStorageContract = this.subStorageContract;
47
-
48
- const defaultOptions = {
49
- target: subStorageContract.address,
50
- abiItem: getAbiItem(subStorageContract.abi, 'strategiesSubs'),
51
- };
52
-
53
- const multicallCalls = subIds.map((subId) => ({ ...defaultOptions, params: [subId] }));
53
+ let options : any;
54
+ let web3: Web3;
55
+
56
+ if (this.web3Fork && this.subStorageContractFork) {
57
+ options = {
58
+ target: this.subStorageContractFork.address,
59
+ abiItem: getAbiItem(this.subStorageContractFork.abi, 'strategiesSubs'),
60
+ };
61
+ web3 = this.web3Fork;
62
+ } else {
63
+ options = {
64
+ target: this.subStorageContract.address,
65
+ abiItem: getAbiItem(this.subStorageContract.abi, 'strategiesSubs'),
66
+ };
67
+ web3 = this.web3;
68
+ }
54
69
 
55
- return multicall(this.web3, this.chainId, multicallCalls);
70
+ const multicallCalls = subIds.map((subId) => ({ ...options, params: [subId] }));
71
+ return multicall(web3, this.chainId, multicallCalls);
56
72
  }
57
73
 
58
74
  protected async getSubscriptionEventsFromSubStorage(options?: PastEventOptions) {
@@ -75,6 +91,7 @@ export default class StrategiesAutomation extends Automation {
75
91
  ...addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }),
76
92
  };
77
93
 
94
+
78
95
  const subscriptionEvents = (await this.getSubscriptionEventsFromSubStorage(_options)) as PlaceholderType; // TODO PlaceholderType
79
96
 
80
97
  let subscriptions: (Position.Automated | null)[] = [];
@@ -1,7 +1,7 @@
1
1
  import type Web3 from 'web3';
2
2
  import type { PastEventOptions } from 'web3-eth-contract';
3
3
  import type {
4
- BlockNumber, Multicall, Contract,
4
+ BlockNumber, Multicall, Contract, PlaceholderType,
5
5
  } from '../types';
6
6
 
7
7
  import { makeUniMulticallContract } from './contractService';
@@ -41,15 +41,28 @@ export async function multicall(
41
41
  return formattedResult;
42
42
  }
43
43
 
44
- export function getEventsFromContract<T extends BaseContract>(
44
+ export async function getEventsFromContract<T extends BaseContract>(
45
45
  contractWithMeta: Contract.WithMeta<T>,
46
+ contractWithMetaFork: Contract.WithMeta<T> | null,
46
47
  event: string, options?: PastEventOptions,
47
48
  ) {
48
- return contractWithMeta.contract.getPastEvents(
49
+ const events = await contractWithMeta.contract.getPastEvents(
49
50
  event,
50
51
  {
51
- fromBlock: contractWithMeta.createdBlock,
52
- ...addToObjectIf(isDefined(options), options),
52
+ ...addToObjectIf(isDefined(options), { ...options, fromBlock: contractWithMeta.createdBlock }),
53
53
  },
54
54
  );
55
+
56
+ let eventsFork : PlaceholderType = [];
57
+
58
+ if (contractWithMetaFork) {
59
+ eventsFork = await contractWithMetaFork.contract.getPastEvents(
60
+ event,
61
+ {
62
+ ...addToObjectIf(isDefined(options), { ...options, toBlock: 'latest' }),
63
+ },
64
+ );
65
+ }
66
+
67
+ return [...events, ...eventsFork];
55
68
  }
@@ -236,7 +236,7 @@ function parseCompoundV3LeverageManagement(position: Position.Automated, parseDa
236
236
 
237
237
  _position.strategyData.decoded.triggerData = triggerData;
238
238
  _position.strategyData.decoded.subData = subData;
239
-
239
+ _position.owner = triggerData.owner;
240
240
  const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
241
241
 
242
242
  if (isRepay) {
@@ -86,6 +86,7 @@ export declare namespace Interfaces {
86
86
 
87
87
  interface Automation {
88
88
  provider: Web3,
89
+ providerFork: Web3,
89
90
  }
90
91
  interface LegacyAutomation<T extends BaseContract> {
91
92
  provider: Web3,
package/umd/index.js CHANGED
@@ -1017,10 +1017,23 @@ function _multicall() {
1017
1017
  });
1018
1018
  return _multicall.apply(this, arguments);
1019
1019
  }
1020
- function getEventsFromContract(contractWithMeta, event, options) {
1021
- return contractWithMeta.contract.getPastEvents(event, _objectSpread({
1022
- fromBlock: contractWithMeta.createdBlock
1023
- }, (0,_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(options), options)));
1020
+ function getEventsFromContract(_x4, _x5, _x6, _x7) {
1021
+ return _getEventsFromContract.apply(this, arguments);
1022
+ }
1023
+ function _getEventsFromContract() {
1024
+ _getEventsFromContract = _asyncToGenerator(function* (contractWithMeta, contractWithMetaFork, event, options) {
1025
+ var events = yield contractWithMeta.contract.getPastEvents(event, _objectSpread({}, (0,_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(options), _objectSpread(_objectSpread({}, options), {}, {
1026
+ fromBlock: contractWithMeta.createdBlock
1027
+ }))));
1028
+ var eventsFork = [];
1029
+ if (contractWithMetaFork) {
1030
+ eventsFork = yield contractWithMetaFork.contract.getPastEvents(event, _objectSpread({}, (0,_utils__WEBPACK_IMPORTED_MODULE_1__.addToObjectIf)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.isDefined)(options), _objectSpread(_objectSpread({}, options), {}, {
1031
+ toBlock: 'latest'
1032
+ }))));
1033
+ }
1034
+ return [...events, ...eventsFork];
1035
+ });
1036
+ return _getEventsFromContract.apply(this, arguments);
1024
1037
  }
1025
1038
 
1026
1039
  /***/ }),
@@ -1191,30 +1204,44 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_4__["def
1191
1204
  super();
1192
1205
  _defineProperty(this, "chainId", void 0);
1193
1206
  _defineProperty(this, "web3", void 0);
1207
+ _defineProperty(this, "web3Fork", void 0);
1194
1208
  _defineProperty(this, "subStorageContract", void 0);
1209
+ _defineProperty(this, "subStorageContractFork", void 0);
1195
1210
  this.web3 = args.provider;
1211
+ this.web3Fork = args.providerFork;
1196
1212
  this.chainId = args.chainId;
1197
1213
  this.subStorageContract = (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.makeSubStorageContract)(this.web3, this.chainId);
1214
+ this.subStorageContractFork = this.web3Fork ? (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.makeSubStorageContract)(this.web3Fork, this.chainId) : null;
1198
1215
  this.assert();
1199
1216
  }
1200
1217
  getEventFromSubStorage(event, options) {
1201
1218
  var _this = this;
1202
1219
  return _asyncToGenerator(function* () {
1203
- return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.getEventsFromContract)(_this.subStorageContract, event, options);
1220
+ return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.getEventsFromContract)(_this.subStorageContract, _this.subStorageContractFork, event, options);
1204
1221
  })();
1205
1222
  }
1206
1223
  getStrategiesSubs(subIds) {
1207
1224
  var _this2 = this;
1208
1225
  return _asyncToGenerator(function* () {
1209
- var subStorageContract = _this2.subStorageContract;
1210
- var defaultOptions = {
1211
- target: subStorageContract.address,
1212
- abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.getAbiItem)(subStorageContract.abi, 'strategiesSubs')
1213
- };
1214
- var multicallCalls = subIds.map(subId => _objectSpread(_objectSpread({}, defaultOptions), {}, {
1226
+ var options;
1227
+ var web3;
1228
+ if (_this2.web3Fork && _this2.subStorageContractFork) {
1229
+ options = {
1230
+ target: _this2.subStorageContractFork.address,
1231
+ abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.getAbiItem)(_this2.subStorageContractFork.abi, 'strategiesSubs')
1232
+ };
1233
+ web3 = _this2.web3Fork;
1234
+ } else {
1235
+ options = {
1236
+ target: _this2.subStorageContract.address,
1237
+ abiItem: (0,_services_contractService__WEBPACK_IMPORTED_MODULE_2__.getAbiItem)(_this2.subStorageContract.abi, 'strategiesSubs')
1238
+ };
1239
+ web3 = _this2.web3;
1240
+ }
1241
+ var multicallCalls = subIds.map(subId => _objectSpread(_objectSpread({}, options), {}, {
1215
1242
  params: [subId]
1216
1243
  }));
1217
- return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.multicall)(_this2.web3, _this2.chainId, multicallCalls);
1244
+ return (0,_services_ethereumService__WEBPACK_IMPORTED_MODULE_3__.multicall)(web3, _this2.chainId, multicallCalls);
1218
1245
  })();
1219
1246
  }
1220
1247
  getSubscriptionEventsFromSubStorage(options) {
@@ -1537,6 +1564,7 @@ function parseCompoundV3LeverageManagement(position, parseData) {
1537
1564
  var subData = _subDataService__WEBPACK_IMPORTED_MODULE_4__.compoundV3LeverageManagementSubData.decode(subStruct.subData);
1538
1565
  _position.strategyData.decoded.triggerData = triggerData;
1539
1566
  _position.strategyData.decoded.subData = subData;
1567
+ _position.owner = triggerData.owner;
1540
1568
  var isRepay = [_types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.Identifiers.Repay, _types_enums__WEBPACK_IMPORTED_MODULE_2__.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
1541
1569
  if (isRepay) {
1542
1570
  _position.specific = {