@defisaver/automation-sdk 1.0.1

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.
Files changed (123) hide show
  1. package/.babelrc +3 -0
  2. package/.editorconfig +9 -0
  3. package/.eslintignore +7 -0
  4. package/.eslintrc.js +104 -0
  5. package/esm/abis/Erc20.json +223 -0
  6. package/esm/abis/SubStorage.json +17 -0
  7. package/esm/abis/UniMulticall.json +14 -0
  8. package/esm/abis/index.d.ts +9 -0
  9. package/esm/abis/index.js +18 -0
  10. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -0
  11. package/esm/abis/legacy_AuthCheck.json +8 -0
  12. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -0
  13. package/esm/abis/legacy_MakerSubscriptions.json +9 -0
  14. package/esm/automation/private/Automation.d.ts +12 -0
  15. package/esm/automation/private/Automation.js +39 -0
  16. package/esm/automation/private/LegacyAutomation.d.ts +25 -0
  17. package/esm/automation/private/LegacyAutomation.js +102 -0
  18. package/esm/automation/private/LegacyProtocol.d.ts +20 -0
  19. package/esm/automation/private/LegacyProtocol.js +34 -0
  20. package/esm/automation/private/Protocol.d.ts +20 -0
  21. package/esm/automation/private/Protocol.js +34 -0
  22. package/esm/automation/private/StrategiesAutomation.d.ts +24 -0
  23. package/esm/automation/private/StrategiesAutomation.js +111 -0
  24. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -0
  25. package/esm/automation/public/ArbitrumStrategies.js +7 -0
  26. package/esm/automation/public/EthereumStrategies.d.ts +5 -0
  27. package/esm/automation/public/EthereumStrategies.js +7 -0
  28. package/esm/automation/public/OptimismStrategies.d.ts +5 -0
  29. package/esm/automation/public/OptimismStrategies.js +7 -0
  30. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -0
  31. package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -0
  32. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -0
  33. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -0
  34. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -0
  35. package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -0
  36. package/esm/configuration.d.ts +1 -0
  37. package/esm/configuration.js +9 -0
  38. package/esm/constants/index.d.ts +23 -0
  39. package/esm/constants/index.js +153 -0
  40. package/esm/index.d.ts +20 -0
  41. package/esm/index.js +22 -0
  42. package/esm/services/contractService.d.ts +11 -0
  43. package/esm/services/contractService.js +40 -0
  44. package/esm/services/ethereumService.d.ts +7 -0
  45. package/esm/services/ethereumService.js +34 -0
  46. package/esm/services/strategiesService.d.ts +2 -0
  47. package/esm/services/strategiesService.js +244 -0
  48. package/esm/services/strategySubService.d.ts +32 -0
  49. package/esm/services/strategySubService.js +91 -0
  50. package/esm/services/subDataService.d.ts +62 -0
  51. package/esm/services/subDataService.js +148 -0
  52. package/esm/services/triggerService.d.ts +89 -0
  53. package/esm/services/triggerService.js +141 -0
  54. package/esm/services/utils.d.ts +24 -0
  55. package/esm/services/utils.js +78 -0
  56. package/esm/types/contracts/generated/Erc20.d.ts +53 -0
  57. package/esm/types/contracts/generated/Erc20.js +4 -0
  58. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -0
  59. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -0
  60. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -0
  61. package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -0
  62. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -0
  63. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -0
  64. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -0
  65. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -0
  66. package/esm/types/contracts/generated/SubStorage.d.ts +114 -0
  67. package/esm/types/contracts/generated/SubStorage.js +4 -0
  68. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -0
  69. package/esm/types/contracts/generated/UniMulticall.js +4 -0
  70. package/esm/types/contracts/generated/index.d.ts +7 -0
  71. package/esm/types/contracts/generated/index.js +1 -0
  72. package/esm/types/contracts/generated/types.d.ts +54 -0
  73. package/esm/types/contracts/generated/types.js +1 -0
  74. package/esm/types/enums.d.ts +97 -0
  75. package/esm/types/enums.js +113 -0
  76. package/esm/types/index.d.ts +180 -0
  77. package/esm/types/index.js +1 -0
  78. package/package.json +66 -0
  79. package/scripts/generateContractTypes.js +39 -0
  80. package/src/abis/Erc20.json +223 -0
  81. package/src/abis/SubStorage.json +17 -0
  82. package/src/abis/UniMulticall.json +14 -0
  83. package/src/abis/index.ts +28 -0
  84. package/src/abis/legacy_AaveV2Subscriptions.json +8 -0
  85. package/src/abis/legacy_AuthCheck.json +8 -0
  86. package/src/abis/legacy_CompoundV2Subscriptions.json +9 -0
  87. package/src/abis/legacy_MakerSubscriptions.json +9 -0
  88. package/src/automation/private/Automation.ts +44 -0
  89. package/src/automation/private/LegacyAutomation.ts +124 -0
  90. package/src/automation/private/LegacyProtocol.ts +45 -0
  91. package/src/automation/private/Protocol.ts +45 -0
  92. package/src/automation/private/StrategiesAutomation.ts +157 -0
  93. package/src/automation/public/ArbitrumStrategies.ts +10 -0
  94. package/src/automation/public/EthereumStrategies.ts +10 -0
  95. package/src/automation/public/OptimismStrategies.ts +10 -0
  96. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -0
  97. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -0
  98. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -0
  99. package/src/configuration.ts +11 -0
  100. package/src/constants/index.ts +173 -0
  101. package/src/index.ts +38 -0
  102. package/src/services/contractService.ts +65 -0
  103. package/src/services/ethereumService.ts +55 -0
  104. package/src/services/strategiesService.ts +336 -0
  105. package/src/services/strategySubService.ts +202 -0
  106. package/src/services/subDataService.ts +212 -0
  107. package/src/services/triggerService.ts +173 -0
  108. package/src/services/utils.ts +101 -0
  109. package/src/types/contracts/generated/Erc20.ts +95 -0
  110. package/src/types/contracts/generated/Legacy_AaveV2Subscriptions.ts +207 -0
  111. package/src/types/contracts/generated/Legacy_AuthCheck.ts +41 -0
  112. package/src/types/contracts/generated/Legacy_CompoundV2Subscriptions.ts +205 -0
  113. package/src/types/contracts/generated/Legacy_MakerSubscriptions.ts +338 -0
  114. package/src/types/contracts/generated/SubStorage.ts +196 -0
  115. package/src/types/contracts/generated/UniMulticall.ts +83 -0
  116. package/src/types/contracts/generated/index.ts +10 -0
  117. package/src/types/contracts/generated/types.ts +73 -0
  118. package/src/types/enums.ts +108 -0
  119. package/src/types/index.ts +217 -0
  120. package/src/types/typings/process.d.ts +9 -0
  121. package/tsconfig.json +79 -0
  122. package/umd/web3.d.ts +28961 -0
  123. package/webpack.umd.js +52 -0
@@ -0,0 +1,124 @@
1
+ import type Web3 from 'web3';
2
+ import type {
3
+ EthereumAddress, Position, Interfaces, Contract, PlaceholderType,
4
+ } from '../../types';
5
+ import type {
6
+ Legacy_AaveV2Subscriptions, Legacy_CompoundV2Subscriptions, Legacy_MakerSubscriptions, Legacy_AuthCheck,
7
+ } from '../../types/contracts/generated';
8
+
9
+ import { getAbiItem, makeAuthCheckerContract } from '../../services/contractService';
10
+ import { multicall } from '../../services/ethereumService';
11
+ import { isAddress, isUndefined } from '../../services/utils';
12
+
13
+ import Automation from './Automation';
14
+ import { ChainId, ProtocolIdentifiers } from '../../types/enums';
15
+
16
+ export default class LegacyAutomation extends Automation {
17
+ protected chainId: ChainId = ChainId.Ethereum;
18
+
19
+ protected web3: Web3;
20
+
21
+ protected monitorAddress: EthereumAddress;
22
+
23
+ protected subscriptionsContract: Contract.WithMeta<Legacy_MakerSubscriptions | Legacy_AaveV2Subscriptions | Legacy_CompoundV2Subscriptions>;
24
+
25
+ protected authCheckerContract: Contract.WithMeta<Legacy_AuthCheck>;
26
+
27
+ protected protocol: Interfaces.LegacyProtocol;
28
+
29
+ constructor(args: Interfaces.LegacyAutomation<Legacy_MakerSubscriptions | Legacy_AaveV2Subscriptions | Legacy_CompoundV2Subscriptions>) {
30
+ super();
31
+
32
+ this.web3 = args.provider;
33
+ this.subscriptionsContract = args.subscriptionsJson;
34
+ this.monitorAddress = args.monitorAddress;
35
+ this.protocol = args.protocol;
36
+ this.authCheckerContract = makeAuthCheckerContract(this.web3, this.chainId);
37
+
38
+ this.assertLegacy();
39
+ }
40
+
41
+ protected assertSubscriptionContract() {
42
+ if (isUndefined(this.subscriptionsContract)) {
43
+ throw new Error(`Assertion for property 'subscriptionsContract' failed. \nGot: '${this.subscriptionsContract}.`);
44
+ }
45
+ }
46
+
47
+ protected assertProtocol() {
48
+ if (isUndefined(this.protocol)) {
49
+ throw new Error(`Assertion for property 'protocol' failed. \nGot: '${this.protocol}.`);
50
+ }
51
+ }
52
+
53
+ protected assertMonitorAddress() {
54
+ if (!isAddress(this.monitorAddress)) {
55
+ throw new Error(`Assertion for property 'monitorAddress' failed. \nGot: '${this.monitorAddress}.`);
56
+ }
57
+ }
58
+
59
+ protected assertLegacy() {
60
+ this.assertProtocol();
61
+ this.assertMonitorAddress();
62
+ this.assertSubscriptionContract();
63
+ this.assert();
64
+ }
65
+
66
+ protected async isMonitorAuthorized(address: EthereumAddress, caller: EthereumAddress): Promise<boolean> {
67
+ return this.authCheckerContract.contract.methods.canCall(caller, address, '0x1cff79cd').call();
68
+ }
69
+
70
+ protected async isMonitorAuthorizedMulticall(addresses: EthereumAddress[], caller: EthereumAddress): Promise<boolean[]> {
71
+ const authCheckerContract = this.authCheckerContract;
72
+
73
+ const defaultOptions = {
74
+ target: authCheckerContract.address,
75
+ abiItem: getAbiItem(authCheckerContract.abi, 'canCall'),
76
+ };
77
+
78
+ const multicallCalls = addresses.map((addr) => ({ ...defaultOptions, params: [caller, addr, '0x1cff79cd'] }));
79
+
80
+ return (await multicall(this.web3, this.chainId, multicallCalls)).map(res => res[0]);
81
+ }
82
+
83
+
84
+ // Aave and Compound use 'user' for property name
85
+ private getOwnerPropName() {
86
+ return this.protocol.id === ProtocolIdentifiers.LegacyAutomation.MakerDAO ? 'owner' : 'user';
87
+ }
88
+
89
+ protected async _getSubscriptions(addresses?: EthereumAddress[]): Promise<PlaceholderType> { // TODO PlaceholderType
90
+ let subscriptions = await this.subscriptionsContract.contract.methods.getSubscribers().call();
91
+
92
+ if (addresses) {
93
+ const _addresses = addresses.map(a => a.toLowerCase());
94
+
95
+ // @ts-ignore
96
+ subscriptions = subscriptions.filter(s => _addresses.includes(s[this.getOwnerPropName()]));
97
+ }
98
+
99
+ return subscriptions;
100
+ }
101
+
102
+ protected async getParsedSubscriptions(addresses?: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
103
+ let subscriptions = await this._getSubscriptions(addresses);
104
+
105
+ // @ts-ignore
106
+ subscriptions = subscriptions.map(sub => ({
107
+ chainId: this.chainId,
108
+ owner: sub[this.getOwnerPropName()],
109
+ isEnabled: true,
110
+ protocol: this.protocol,
111
+ specific: { ...sub },
112
+ }));
113
+
114
+ return subscriptions;
115
+ }
116
+
117
+ public async getSubscriptions(): Promise<Position.LegacyAutomated[]> {
118
+ return this.getParsedSubscriptions();
119
+ }
120
+
121
+ public async getSubscriptionsFor(addresses: EthereumAddress[]): Promise<Position.LegacyAutomated[]> {
122
+ return this.getParsedSubscriptions(addresses);
123
+ }
124
+ }
@@ -0,0 +1,45 @@
1
+ import type { Interfaces } from '../../types';
2
+ import type { ProtocolIdentifiers } from '../../types/enums';
3
+
4
+ export default class Protocol implements Interfaces.LegacyProtocol {
5
+ id: ProtocolIdentifiers.LegacyAutomation;
6
+
7
+ name: string;
8
+
9
+ version: string;
10
+
11
+ fullName: string;
12
+
13
+ #versionSeparator = '__';
14
+
15
+ constructor(args: { id: ProtocolIdentifiers.LegacyAutomation }) {
16
+ this.id = args.id;
17
+
18
+ this.name = this.getName();
19
+ this.version = this.getVersion();
20
+ this.fullName = this.getFullName();
21
+ }
22
+
23
+ private hasVersion() {
24
+ return this.id.indexOf(this.#versionSeparator) !== -1;
25
+ }
26
+
27
+ private splitId() {
28
+ return this.id.split(this.#versionSeparator);
29
+ }
30
+
31
+ /**
32
+ * @dev See naming convention at ProtocolIdentifiers declaration
33
+ */
34
+ private getVersion() {
35
+ return this.hasVersion() ? this.splitId().reverse()[0] : '';
36
+ }
37
+
38
+ private getName() {
39
+ return this.hasVersion() ? this.splitId()[0] : this.id;
40
+ }
41
+
42
+ private getFullName() {
43
+ return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
44
+ }
45
+ }
@@ -0,0 +1,45 @@
1
+ import type { Interfaces } from '../../types';
2
+ import type { ProtocolIdentifiers } from '../../types/enums';
3
+
4
+ export default class Protocol implements Interfaces.Protocol {
5
+ id: ProtocolIdentifiers.StrategiesAutomation;
6
+
7
+ name: string;
8
+
9
+ version: string;
10
+
11
+ fullName: string;
12
+
13
+ #versionSeparator = '__';
14
+
15
+ constructor(args: { id: ProtocolIdentifiers.StrategiesAutomation }) {
16
+ this.id = args.id;
17
+
18
+ this.name = this.getName();
19
+ this.version = this.getVersion();
20
+ this.fullName = this.getFullName();
21
+ }
22
+
23
+ private hasVersion() {
24
+ return this.id.indexOf(this.#versionSeparator) !== -1;
25
+ }
26
+
27
+ private splitId() {
28
+ return this.id.split(this.#versionSeparator);
29
+ }
30
+
31
+ /**
32
+ * @dev See naming convention at ProtocolIdentifiers declaration
33
+ */
34
+ private getVersion() {
35
+ return this.hasVersion() ? this.splitId().reverse()[0] : '';
36
+ }
37
+
38
+ private getName() {
39
+ return this.hasVersion() ? this.splitId()[0] : this.id;
40
+ }
41
+
42
+ private getFullName() {
43
+ return this.hasVersion() ? `${this.name} ${this.version}` : this.name;
44
+ }
45
+ }
@@ -0,0 +1,157 @@
1
+ import type Web3 from 'web3';
2
+ import type { PastEventOptions, Filter } from 'web3-eth-contract';
3
+ import type {
4
+ Position, Interfaces, EthereumAddress,
5
+ SubscriptionOptions, Contract, ParseData, PlaceholderType,
6
+ } from '../../types';
7
+ import type {
8
+ Subscribe, StrategyModel, SubStorage, UpdateData,
9
+ } from '../../types/contracts/generated/SubStorage';
10
+
11
+ import {
12
+ addToArrayIf, addToObjectIf, isDefined,
13
+ } from '../../services/utils';
14
+ import { getAbiItem, makeSubStorageContract } from '../../services/contractService';
15
+ import { getEventsFromContract, multicall } from '../../services/ethereumService';
16
+
17
+ import Automation from './Automation';
18
+ import { parseStrategiesAutomatedPosition } from '../../services/strategiesService';
19
+ import type { ChainId } from '../../types/enums';
20
+
21
+ interface IStrategiesAutomation extends Interfaces.Automation {
22
+ chainId: ChainId,
23
+ }
24
+
25
+ export default class StrategiesAutomation extends Automation {
26
+ protected chainId: ChainId;
27
+
28
+ protected web3: Web3;
29
+
30
+ protected subStorageContract: Contract.WithMeta<SubStorage>;
31
+
32
+ constructor(args: IStrategiesAutomation) {
33
+ super();
34
+
35
+ this.web3 = args.provider;
36
+ this.chainId = args.chainId;
37
+ this.subStorageContract = makeSubStorageContract(this.web3, this.chainId);
38
+
39
+ this.assert();
40
+ }
41
+
42
+ protected async getEventFromSubStorage(event: string, options?: PastEventOptions) {
43
+ return getEventsFromContract<SubStorage>(this.subStorageContract, event, options);
44
+ }
45
+
46
+ protected async getStrategiesSubs(subIds: number[]): Promise<StrategyModel.StoredSubDataStructOutputStruct[]> {
47
+ const subStorageContract = this.subStorageContract;
48
+
49
+ const defaultOptions = {
50
+ target: subStorageContract.address,
51
+ abiItem: getAbiItem(subStorageContract.abi, 'strategiesSubs'),
52
+ };
53
+
54
+ const multicallCalls = subIds.map((subId) => ({ ...defaultOptions, params: [subId] }));
55
+
56
+ return multicall(this.web3, this.chainId, multicallCalls);
57
+ }
58
+
59
+ protected async getSubscriptionEventsFromSubStorage(options?: PastEventOptions) {
60
+ return this.getEventFromSubStorage('Subscribe', options);
61
+ }
62
+
63
+ protected async getUpdateDataEventsFromSubStorage(options?: PastEventOptions) {
64
+ return this.getEventFromSubStorage('UpdateData', options);
65
+ }
66
+
67
+ protected getParsedSubscriptions(parseData: ParseData) {
68
+ return parseStrategiesAutomatedPosition(parseData);
69
+ }
70
+
71
+ protected async _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
72
+ const _options = {
73
+ ...addToObjectIf(isDefined(options), options),
74
+ ...addToObjectIf(isDefined(addresses), { filter: { proxy: addresses } }),
75
+ };
76
+
77
+ const subscriptionEvents = (await this.getSubscriptionEventsFromSubStorage(_options)).map(e => e.returnValues) as PlaceholderType; // TODO PlaceholderType
78
+
79
+ let subscriptions: (Position.Automated | null)[] = [];
80
+
81
+ if (subscriptionEvents) {
82
+ // @ts-ignore
83
+ const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.subId));
84
+
85
+ subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
86
+ let latestUpdate = subscriptionEvents[index];
87
+
88
+ if (latestUpdate.subHash !== sub?.strategySubHash) {
89
+ const updates = await this.getUpdateDataEventsFromSubStorage({ filter: latestUpdate.subId as any as Filter });
90
+ latestUpdate = {
91
+ ...latestUpdate, // Update is missing proxy, hence this
92
+ ...updates?.[updates.length - 1]?.returnValues,
93
+ };
94
+ }
95
+ return this.getParsedSubscriptions({
96
+ chainId: this.chainId,
97
+ subscriptionEventData: latestUpdate,
98
+ strategiesSubsData: sub,
99
+ });
100
+ }));
101
+
102
+ if (options?.mergeWithSameId) {
103
+ subscriptions = subscriptions.reduce((list: (Position.Automated | null)[], current) => {
104
+ const copyList = [...list] as (Position.Automated | null)[];
105
+
106
+ if (isDefined(current)) {
107
+ if (current.specific.mergeWithSameId) {
108
+ const mergePairIndex = copyList.findIndex(s => (
109
+ s && s.specific.mergeWithSameId
110
+ && s.strategy.strategyId === current.strategy.strategyId
111
+ && s.protocol.id === current.protocol.id
112
+ ));
113
+
114
+ if (mergePairIndex !== -1) {
115
+ const mergePair = copyList[mergePairIndex];
116
+ if (isDefined(mergePair)) {
117
+ copyList[mergePairIndex] = {
118
+ ...mergePair,
119
+ ...current,
120
+ isEnabled: mergePair.isEnabled || current.isEnabled,
121
+ subId: mergePair.subId,
122
+ subIds: [...addToArrayIf(isDefined(mergePair.subIds), mergePair.subIds), current.subId],
123
+ specific: {
124
+ ...mergePair.specific,
125
+ ...current.specific,
126
+ mergeWithSameId: false,
127
+ },
128
+ };
129
+ return copyList;
130
+ }
131
+ }
132
+ }
133
+ } else {
134
+ return copyList;
135
+ }
136
+
137
+ copyList.push({
138
+ ...current,
139
+ subIds: [current.subId],
140
+ });
141
+
142
+ return copyList;
143
+ }, []);
144
+ }
145
+ }
146
+
147
+ return subscriptions;
148
+ }
149
+
150
+ public async getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
151
+ return this._getSubscriptions(undefined, options);
152
+ }
153
+
154
+ public async getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]> {
155
+ return this._getSubscriptions(addresses, options);
156
+ }
157
+ }
@@ -0,0 +1,10 @@
1
+ import type { Interfaces } from '../../types';
2
+
3
+ import StrategiesAutomation from '../private/StrategiesAutomation';
4
+ import { ChainId } from '../../types/enums';
5
+
6
+ export default class ArbitrumStrategies extends StrategiesAutomation {
7
+ constructor(args: Interfaces.Automation) {
8
+ super({ ...args, chainId: ChainId.Arbitrum });
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { Interfaces } from '../../types';
2
+
3
+ import StrategiesAutomation from '../private/StrategiesAutomation';
4
+ import { ChainId } from '../../types/enums';
5
+
6
+ export default class EthereumStrategies extends StrategiesAutomation {
7
+ constructor(args: Interfaces.Automation) {
8
+ super({ ...args, chainId: ChainId.Ethereum });
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ import type { Interfaces } from '../../types';
2
+
3
+ import StrategiesAutomation from '../private/StrategiesAutomation';
4
+ import { ChainId } from '../../types/enums';
5
+
6
+ export default class OptimismStrategies extends StrategiesAutomation {
7
+ constructor(args: Interfaces.Automation) {
8
+ super({ ...args, chainId: ChainId.Optimism });
9
+ }
10
+ }
@@ -0,0 +1,20 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_AaveV2Subscriptions } from '../../../types/contracts/generated';
3
+
4
+ import { LEGACY_PROTOCOLS } from '../../../constants';
5
+ import { AaveV2SubscriptionsJson } from '../../../abis';
6
+
7
+ import { makeLegacySubscriptionContract } from '../../../services/contractService';
8
+
9
+ import LegacyAutomation from '../../private/LegacyAutomation';
10
+
11
+ export default class LegacyAaveAutomation extends LegacyAutomation {
12
+ constructor(args: Interfaces.LegacyAutomation<Legacy_AaveV2Subscriptions>) {
13
+ super({
14
+ provider: args.provider,
15
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, AaveV2SubscriptionsJson),
16
+ monitorAddress: '0x380982902872836ceC629171DaeAF42EcC02226e',
17
+ protocol: LEGACY_PROTOCOLS.AaveV2,
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_CompoundV2Subscriptions } from '../../../types/contracts/generated';
3
+
4
+ import { LEGACY_PROTOCOLS } from '../../../constants';
5
+ import { CompoundV2SubscriptionsJson } from '../../../abis';
6
+
7
+ import { makeLegacySubscriptionContract } from '../../../services/contractService';
8
+
9
+ import LegacyAutomation from '../../private/LegacyAutomation';
10
+
11
+ export default class LegacyAaveAutomation extends LegacyAutomation {
12
+ constructor(args: Interfaces.LegacyAutomation<Legacy_CompoundV2Subscriptions>) {
13
+ super({
14
+ provider: args.provider,
15
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, CompoundV2SubscriptionsJson),
16
+ monitorAddress: '0xB1cF8DE8e791E4Ed1Bd86c03E2fc1f14389Cb10a',
17
+ protocol: LEGACY_PROTOCOLS.CompoundV2,
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ import type { Interfaces } from '../../../types';
2
+ import type { Legacy_MakerSubscriptions } from '../../../types/contracts/generated';
3
+
4
+ import { LEGACY_PROTOCOLS } from '../../../constants';
5
+ import { MakerSubscriptionsJson } from '../../../abis';
6
+
7
+ import { makeLegacySubscriptionContract } from '../../../services/contractService';
8
+
9
+ import LegacyAutomation from '../../private/LegacyAutomation';
10
+
11
+ export default class LegacyMakerAutomation extends LegacyAutomation {
12
+ constructor(args: Interfaces.LegacyAutomation<Legacy_MakerSubscriptions>) {
13
+ super({
14
+ provider: args.provider,
15
+ subscriptionsJson: makeLegacySubscriptionContract(args.provider, MakerSubscriptionsJson),
16
+ monitorAddress: '0x1816A86C4DA59395522a42b871bf11A4E96A1C7a',
17
+ protocol: LEGACY_PROTOCOLS.MakerDAO,
18
+ });
19
+ }
20
+ }
@@ -0,0 +1,11 @@
1
+ import Web3 from 'web3';
2
+ import Dec from 'decimal.js';
3
+
4
+ process.mockedWeb3 = new Web3('');
5
+
6
+ Dec.set({
7
+ rounding: Dec.ROUND_DOWN,
8
+ toExpPos: 9e15,
9
+ toExpNeg: -9e15,
10
+ precision: 100,
11
+ });
@@ -0,0 +1,173 @@
1
+ import type {
2
+ ArbitrumBundleInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, StrategiesInfo,
3
+ } from '../types';
4
+
5
+ import {
6
+ ChainId, ProtocolIdentifiers, Strategies, Bundles, BundleProtocols,
7
+ } from '../types/enums';
8
+
9
+ import Protocol from '../automation/private/Protocol';
10
+ import LegacyProtocol from '../automation/private/LegacyProtocol';
11
+
12
+ // General
13
+ export const ZERO_ADDRESS: EthereumAddress = '0x0000000000000000000000000000000000000000';
14
+
15
+ export const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol> = (() => {
16
+ const protocolsMapping: any = {};
17
+ Object.entries(ProtocolIdentifiers.StrategiesAutomation).forEach(([id, value]) => {
18
+ protocolsMapping[id] = new Protocol({ id: value });
19
+ });
20
+ return protocolsMapping;
21
+ })();
22
+
23
+ export const LEGACY_PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.LegacyAutomation, Interfaces.LegacyProtocol> = (() => {
24
+ const protocolsMapping: any = {};
25
+ Object.entries(ProtocolIdentifiers.LegacyAutomation).forEach(([id, value]) => {
26
+ protocolsMapping[id] = new LegacyProtocol({ id: value });
27
+ });
28
+ return protocolsMapping;
29
+ })();
30
+
31
+ // Strategies info
32
+ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
33
+ [Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI]: {
34
+ strategyId: Strategies.Identifiers.CloseOnPriceToDebt,
35
+ protocol: PROTOCOLS.MakerDAO,
36
+ },
37
+ [Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_COLL]: {
38
+ strategyId: Strategies.Identifiers.CloseOnPriceToColl,
39
+ protocol: PROTOCOLS.MakerDAO,
40
+ },
41
+ [Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL_DEPRECATED]: {
42
+ strategyId: Strategies.Identifiers.CloseOnPriceToColl,
43
+ protocol: PROTOCOLS.Liquity,
44
+ },
45
+ [Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL]: {
46
+ strategyId: Strategies.Identifiers.CloseOnPriceToColl,
47
+ protocol: PROTOCOLS.MakerDAO,
48
+ },
49
+ [Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL]: {
50
+ strategyId: Strategies.Identifiers.TrailingStopToColl,
51
+ protocol: PROTOCOLS.MakerDAO,
52
+ },
53
+ [Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI]: {
54
+ strategyId: Strategies.Identifiers.TrailingStopToDebt,
55
+ protocol: PROTOCOLS.MakerDAO,
56
+ },
57
+ [Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL]: {
58
+ strategyId: Strategies.Identifiers.TrailingStopToColl,
59
+ protocol: PROTOCOLS.Liquity,
60
+ },
61
+ [Strategies.MainnetIds.CHICKEN_BONDS_REBOND]: {
62
+ strategyId: Strategies.Identifiers.Rebond,
63
+ protocol: PROTOCOLS.ChickenBonds,
64
+ },
65
+ };
66
+
67
+ export const OPTIMISM_STRATEGIES_INFO = {};
68
+
69
+ export const ARBITRUM_STRATEGIES_INFO = {};
70
+
71
+ export const STRATEGIES_INFO: StrategiesInfo = {
72
+ [ChainId.Ethereum]: MAINNET_STRATEGIES_INFO,
73
+ [ChainId.Optimism]: OPTIMISM_STRATEGIES_INFO,
74
+ [ChainId.Arbitrum]: ARBITRUM_STRATEGIES_INFO,
75
+ };
76
+
77
+ export const STRATEGY_IDS = {
78
+ [ChainId.Ethereum]: Strategies.MainnetIds,
79
+ [ChainId.Optimism]: Strategies.OptimismIds,
80
+ [ChainId.Arbitrum]: Strategies.ArbitrumIds,
81
+ };
82
+
83
+ // Bundles info
84
+ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
85
+ [Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_YEARN]: {
86
+ bundleId: BundleProtocols.Yearn,
87
+ bundleName: 'Yearn',
88
+ strategyId: Strategies.Identifiers.SavingsLiqProtection,
89
+ protocol: PROTOCOLS.MakerDAO,
90
+ },
91
+ [Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_MSTABLE]: {
92
+ bundleId: BundleProtocols.MStable,
93
+ bundleName: 'mStable',
94
+ strategyId: Strategies.Identifiers.SavingsLiqProtection,
95
+ protocol: PROTOCOLS.MakerDAO,
96
+ },
97
+ [Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI]: {
98
+ bundleId: BundleProtocols.Rari,
99
+ bundleName: 'Rari',
100
+ strategyId: Strategies.Identifiers.SavingsLiqProtection,
101
+ protocol: PROTOCOLS.MakerDAO,
102
+ },
103
+ [Bundles.MainnetIds.COMP_V3_SW_REPAY_BUNDLE]: {
104
+ strategyId: Strategies.Identifiers.Repay,
105
+ protocol: PROTOCOLS.CompoundV3,
106
+ },
107
+ [Bundles.MainnetIds.COMP_V3_SW_BOOST_BUNDLE]: {
108
+ strategyId: Strategies.Identifiers.Boost,
109
+ protocol: PROTOCOLS.CompoundV3,
110
+ },
111
+ [Bundles.MainnetIds.COMP_V3_EOA_REPAY_BUNDLE]: {
112
+ strategyId: Strategies.Identifiers.EoaRepay,
113
+ protocol: PROTOCOLS.CompoundV3,
114
+ },
115
+ [Bundles.MainnetIds.COMP_V3_EOA_BOOST_BUNDLE]: {
116
+ strategyId: Strategies.Identifiers.EoaBoost,
117
+ protocol: PROTOCOLS.CompoundV3,
118
+ },
119
+ [Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND]: {
120
+ strategyId: Strategies.Identifiers.BondProtection,
121
+ protocol: PROTOCOLS.Liquity,
122
+ },
123
+ };
124
+
125
+ export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
126
+ [Bundles.OptimismIds.AAVE_V3_REPAY]: {
127
+ strategyId: Strategies.Identifiers.Repay,
128
+ protocol: PROTOCOLS.AaveV3,
129
+ },
130
+ [Bundles.OptimismIds.AAVE_V3_BOOST]: {
131
+ strategyId: Strategies.Identifiers.Boost,
132
+ protocol: PROTOCOLS.AaveV3,
133
+ },
134
+ [Bundles.OptimismIds.AAVE_V3_CLOSE_TO_DEBT]: {
135
+ strategyId: Strategies.Identifiers.CloseToDebt,
136
+ protocol: PROTOCOLS.AaveV3,
137
+ },
138
+ [Bundles.OptimismIds.AAVE_V3_CLOSE_TO_COLLATERAL]: {
139
+ strategyId: Strategies.Identifiers.CloseToCollateral,
140
+ protocol: PROTOCOLS.AaveV3,
141
+ },
142
+ };
143
+
144
+ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
145
+ [Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
146
+ strategyId: Strategies.Identifiers.Repay,
147
+ protocol: PROTOCOLS.AaveV3,
148
+ },
149
+ [Bundles.ArbitrumIds.AAVE_V3_BOOST]: {
150
+ strategyId: Strategies.Identifiers.Boost,
151
+ protocol: PROTOCOLS.AaveV3,
152
+ },
153
+ [Bundles.ArbitrumIds.AAVE_V3_CLOSE_TO_DEBT]: {
154
+ strategyId: Strategies.Identifiers.CloseToDebt,
155
+ protocol: PROTOCOLS.AaveV3,
156
+ },
157
+ [Bundles.ArbitrumIds.AAVE_V3_CLOSE_TO_COLLATERAL]: {
158
+ strategyId: Strategies.Identifiers.CloseToCollateral,
159
+ protocol: PROTOCOLS.AaveV3,
160
+ },
161
+ };
162
+
163
+ export const BUNDLES_INFO: BundlesInfo = {
164
+ [ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
165
+ [ChainId.Optimism]: OPTIMISM_BUNDLES_INFO,
166
+ [ChainId.Arbitrum]: ARBITRUM_BUNDLES_INFO,
167
+ };
168
+
169
+ export const BUNDLE_IDS = {
170
+ [ChainId.Ethereum]: Bundles.MainnetIds,
171
+ [ChainId.Optimism]: Bundles.OptimismIds,
172
+ [ChainId.Arbitrum]: Bundles.ArbitrumIds,
173
+ };