@defisaver/automation-sdk 2.0.1 → 2.0.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.
- package/.eslintrc.js +1 -0
- package/esm/abis/index.js +27 -15
- package/esm/automation/private/Automation.js +9 -6
- package/esm/automation/private/LegacyAutomation.d.ts +5 -5
- package/esm/automation/private/LegacyAutomation.js +30 -23
- package/esm/automation/private/LegacyProtocol.js +4 -1
- package/esm/automation/private/Protocol.js +4 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -2
- package/esm/automation/private/StrategiesAutomation.js +27 -21
- package/esm/automation/public/ArbitrumStrategies.js +10 -4
- package/esm/automation/public/EthereumStrategies.js +10 -4
- package/esm/automation/public/OptimismStrategies.js +10 -4
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +13 -7
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +13 -7
- package/esm/configuration.js +8 -5
- package/esm/constants/index.js +281 -265
- package/esm/index.js +57 -17
- package/esm/services/contractService.js +22 -14
- package/esm/services/ethereumService.js +18 -10
- package/esm/services/strategiesService.js +144 -100
- package/esm/services/strategySubService.d.ts +2 -0
- package/esm/services/strategySubService.js +100 -55
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +165 -127
- package/esm/services/triggerService.d.ts +8 -8
- package/esm/services/triggerService.js +125 -95
- package/esm/services/utils.js +82 -33
- package/esm/services/utils.test.d.ts +1 -0
- package/esm/services/utils.test.js +362 -0
- package/esm/types/contracts/generated/Erc20.js +2 -1
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +2 -1
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +2 -1
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +2 -1
- package/esm/types/contracts/generated/SubStorage.js +2 -1
- package/esm/types/contracts/generated/UniMulticall.js +2 -1
- package/esm/types/contracts/generated/index.js +2 -1
- package/esm/types/contracts/generated/types.js +2 -1
- package/esm/types/enums.d.ts +9 -1
- package/esm/types/enums.js +24 -12
- package/esm/types/index.js +2 -1
- package/package.json +12 -8
- package/src/automation/private/LegacyAutomation.ts +11 -10
- package/src/automation/private/StrategiesAutomation.ts +5 -6
- package/src/configuration.ts +0 -3
- package/src/constants/index.ts +10 -0
- package/src/index.ts +0 -1
- package/src/services/ethereumService.ts +6 -6
- package/src/services/strategiesService.ts +24 -0
- package/src/services/strategySubService.ts +30 -0
- package/src/services/subDataService.ts +104 -67
- package/src/services/triggerService.ts +86 -85
- package/src/services/utils.test.ts +414 -0
- package/src/services/utils.ts +6 -7
- package/src/types/enums.ts +9 -0
- package/tsconfig.json +1 -1
- package/umd/index.js +7142 -4138
- package/src/types/typings/process.d.ts +0 -9
- package/yarn-error.log +0 -7233
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const chai_1 = require("chai");
|
|
30
|
+
const web3Utils = __importStar(require("web3-utils"));
|
|
31
|
+
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
32
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
33
|
+
const enums_1 = require("../types/enums");
|
|
34
|
+
const strategySubService_1 = require("./strategySubService");
|
|
35
|
+
const utils_1 = require("./utils");
|
|
36
|
+
describe('Feature: utils.ts', () => {
|
|
37
|
+
describe('When testing utils.isDefined()', () => {
|
|
38
|
+
const examples = [
|
|
39
|
+
[true, 'something'],
|
|
40
|
+
[true, NaN],
|
|
41
|
+
[true, 0],
|
|
42
|
+
[false, undefined],
|
|
43
|
+
[false, null],
|
|
44
|
+
];
|
|
45
|
+
examples.forEach(([expected, actual]) => {
|
|
46
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
47
|
+
(0, chai_1.expect)((0, utils_1.isDefined)(actual)).to.equal(expected);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
describe('When testing utils.isUndefined()', () => {
|
|
52
|
+
const examples = [
|
|
53
|
+
[false, 'something'],
|
|
54
|
+
[false, NaN],
|
|
55
|
+
[false, 0],
|
|
56
|
+
[true, undefined],
|
|
57
|
+
[true, null],
|
|
58
|
+
];
|
|
59
|
+
examples.forEach(([expected, actual]) => {
|
|
60
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
61
|
+
(0, chai_1.expect)((0, utils_1.isUndefined)(actual)).to.equal(expected);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
describe('When testing utils.compareAddresses()', () => {
|
|
66
|
+
const examples = [
|
|
67
|
+
[true, ['nesto', 'nesto']],
|
|
68
|
+
[true, ['', '']],
|
|
69
|
+
[false, ['something', 'nesto']],
|
|
70
|
+
[false, ['', 'nesto']],
|
|
71
|
+
];
|
|
72
|
+
examples.forEach(([expected, actual]) => {
|
|
73
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
74
|
+
(0, chai_1.expect)((0, utils_1.compareAddresses)(...actual)).to.equal(expected);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
describe('When testing utils.isAddress()', () => {
|
|
79
|
+
const examples = [
|
|
80
|
+
[true, '0x996bc83fa1b947cca00e5dcf776c438096549062'],
|
|
81
|
+
[true, '0x0000000000000000000000000000000000000000'],
|
|
82
|
+
[false, '0x996bc83fa147cca00e5dcf776c438096549062'],
|
|
83
|
+
[false, '0x996bc83fa147cca00e5dcf776c438096549062xx'],
|
|
84
|
+
[false, ''],
|
|
85
|
+
[false, 'majmune.eth'],
|
|
86
|
+
];
|
|
87
|
+
examples.forEach(([expected, actual]) => {
|
|
88
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
89
|
+
(0, chai_1.expect)((0, utils_1.isAddress)(actual)).to.equal(expected);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('When testing utils.addToArrayIf()', () => {
|
|
94
|
+
const exampleOne = [1, ...(0, utils_1.addToArrayIf)(true, 2)];
|
|
95
|
+
const actualOne = [1, 2];
|
|
96
|
+
it(`Given ${actualOne.join(', ')} should return expected value: [${exampleOne.join(', ')}]`, () => {
|
|
97
|
+
(0, chai_1.expect)(actualOne).to.eql(exampleOne);
|
|
98
|
+
});
|
|
99
|
+
const exampleTwo = [1, ...(0, utils_1.addToArrayIf)(false, 2)];
|
|
100
|
+
const actualTwo = [1];
|
|
101
|
+
it(`Given ${actualTwo.join(', ')} should return expected value: [${exampleTwo.join(', ')}]`, () => {
|
|
102
|
+
(0, chai_1.expect)(actualTwo).to.eql(exampleTwo);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('When testing utils.addToObjectIf()', () => {
|
|
106
|
+
const exampleOne = Object.assign({ a: 1 }, (0, utils_1.addToObjectIf)(true, { b: 2 }));
|
|
107
|
+
const actualOne = { a: 1, b: 2 };
|
|
108
|
+
it(`Given ${JSON.stringify(actualOne)} should return expected value: ${JSON.stringify(exampleOne)}`, () => {
|
|
109
|
+
(0, chai_1.expect)(actualOne).to.eql(exampleOne);
|
|
110
|
+
});
|
|
111
|
+
const exampleTwo = Object.assign({ a: 1 }, (0, utils_1.addToObjectIf)(false, { b: 2 }));
|
|
112
|
+
const actualTwo = { a: 1 };
|
|
113
|
+
it(`Given ${JSON.stringify(actualTwo)} should return expected value: ${JSON.stringify(exampleTwo)}`, () => {
|
|
114
|
+
(0, chai_1.expect)(actualTwo).to.eql(exampleTwo);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe('When testing utils.ethToWeth()', () => {
|
|
118
|
+
const examples = [
|
|
119
|
+
['WETH', 'ETH'],
|
|
120
|
+
['rETH', 'rETH'],
|
|
121
|
+
['ETH.c', 'ETH.c'],
|
|
122
|
+
['cETHx2', 'cETHx2'],
|
|
123
|
+
['WETH', 'WETH'],
|
|
124
|
+
['DAI', 'DAI'],
|
|
125
|
+
];
|
|
126
|
+
examples.forEach(([expected, actual]) => {
|
|
127
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
128
|
+
(0, chai_1.expect)((0, utils_1.ethToWeth)(actual)).to.equal(expected);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('When testing utils.wethToEth()', () => {
|
|
133
|
+
const examples = [
|
|
134
|
+
['ETH', 'ETH'],
|
|
135
|
+
['rETH', 'rETH'],
|
|
136
|
+
['ETH.c', 'ETH.c'],
|
|
137
|
+
['cETHx2', 'cETHx2'],
|
|
138
|
+
['ETH', 'WETH'],
|
|
139
|
+
['DAI', 'DAI'],
|
|
140
|
+
];
|
|
141
|
+
examples.forEach(([expected, actual]) => {
|
|
142
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
143
|
+
(0, chai_1.expect)((0, utils_1.wethToEth)(actual)).to.equal(expected);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('When testing utils.wethToEthByAddress()', () => {
|
|
148
|
+
/**
|
|
149
|
+
* @dev wethToEthByAddress will return empty string when asset doesn't exist in assets array of @defisaver/tokens
|
|
150
|
+
* This is @defisaver/tokens problem, but still seems like a wierd behaviour
|
|
151
|
+
*/
|
|
152
|
+
const examples = [
|
|
153
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 1]],
|
|
154
|
+
['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407', ['0xb3319f5d18bc0d84dd1b4825dcde5d5f7266d407', 1]],
|
|
155
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 1]],
|
|
156
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0x4200000000000000000000000000000000000006', 10]],
|
|
157
|
+
['0xab7badef82e9fe11f6f33f87bc9bc2aa27f2fcb5', ['0xab7badef82e9fe11f6f33f87bc9bc2aa27f2fcb5', 10]],
|
|
158
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 10]],
|
|
159
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0x82aF49447D8a07e3bd95BD0d56f35241523fBab1', 42161]],
|
|
160
|
+
['0xaf88d065e77c8cC2239327C5EDb3A432268e5831', ['0xaf88d065e77c8cC2239327C5EDb3A432268e5831', 42161]],
|
|
161
|
+
['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', ['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', 42161]],
|
|
162
|
+
];
|
|
163
|
+
examples.forEach(([expected, actual]) => {
|
|
164
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
165
|
+
(0, chai_1.expect)((0, utils_1.wethToEthByAddress)(...actual)).to.equal(expected);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe('When testing utils.compareSubHashes()', () => {
|
|
170
|
+
const subDataToEncodeOne = [
|
|
171
|
+
12,
|
|
172
|
+
false,
|
|
173
|
+
{
|
|
174
|
+
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
175
|
+
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
176
|
+
price: 100,
|
|
177
|
+
ratioState: 1,
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
181
|
+
collAssetId: 2,
|
|
182
|
+
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
183
|
+
debtAssetId: 3,
|
|
184
|
+
},
|
|
185
|
+
];
|
|
186
|
+
const subDataToEncodeTwo = [
|
|
187
|
+
13,
|
|
188
|
+
true,
|
|
189
|
+
{
|
|
190
|
+
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
191
|
+
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
192
|
+
price: 100,
|
|
193
|
+
ratioState: 2,
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
197
|
+
collAssetId: 2,
|
|
198
|
+
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
199
|
+
debtAssetId: 3,
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
const encodedSubDataOne = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeOne);
|
|
204
|
+
// @ts-ignore
|
|
205
|
+
const encodedSubDataTwo = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeTwo);
|
|
206
|
+
const encodedParams = web3Utils.keccak256(web3_eth_abi_1.default.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
|
|
207
|
+
const examples = [
|
|
208
|
+
[true, [encodedParams, encodedSubDataOne]],
|
|
209
|
+
[false, [encodedParams, encodedSubDataTwo]],
|
|
210
|
+
];
|
|
211
|
+
examples.forEach(([expected, actual]) => {
|
|
212
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
213
|
+
(0, chai_1.expect)((0, utils_1.compareSubHashes)(...actual)).to.equal(expected);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
describe('When testing utils.encodeSubId()', () => {
|
|
218
|
+
const examples = [
|
|
219
|
+
['00000001', '1'],
|
|
220
|
+
['00000002', '2'],
|
|
221
|
+
['0021c503', '2213123']
|
|
222
|
+
];
|
|
223
|
+
examples.forEach(([expected, actual]) => {
|
|
224
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
225
|
+
(0, chai_1.expect)((0, utils_1.encodeSubId)(actual)).to.equal(expected);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
describe('When testing utils.ratioPercentageToWei()', () => {
|
|
230
|
+
const examples = [
|
|
231
|
+
['1200000000000000000', 120],
|
|
232
|
+
['2400000000000000000', 240],
|
|
233
|
+
['870000000000000000', 87],
|
|
234
|
+
];
|
|
235
|
+
examples.forEach(([expected, actual]) => {
|
|
236
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
237
|
+
(0, chai_1.expect)((0, utils_1.ratioPercentageToWei)(actual)).to.equal(expected);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
describe('When testing utils.weiToRatioPercentage()', () => {
|
|
242
|
+
const examples = [
|
|
243
|
+
[120, '1200000000000000000'],
|
|
244
|
+
[240, '2400000000000000000'],
|
|
245
|
+
[87, '870000000000000000'],
|
|
246
|
+
];
|
|
247
|
+
examples.forEach(([expected, actual]) => {
|
|
248
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
249
|
+
(0, chai_1.expect)((0, utils_1.weiToRatioPercentage)(actual)).to.equal(expected);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
describe('When testing utils.isRatioStateOver()', () => {
|
|
254
|
+
const examples = [
|
|
255
|
+
[true, enums_1.RatioState.OVER],
|
|
256
|
+
[false, enums_1.RatioState.UNDER],
|
|
257
|
+
[false, NaN],
|
|
258
|
+
[false, 3],
|
|
259
|
+
[false, Infinity],
|
|
260
|
+
];
|
|
261
|
+
examples.forEach(([expected, actual]) => {
|
|
262
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
263
|
+
(0, chai_1.expect)((0, utils_1.isRatioStateOver)(actual)).to.equal(expected);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
describe('When testing utils.isRatioStateUnder()', () => {
|
|
268
|
+
const examples = [
|
|
269
|
+
[true, enums_1.RatioState.UNDER],
|
|
270
|
+
[false, enums_1.RatioState.OVER],
|
|
271
|
+
[false, NaN],
|
|
272
|
+
[false, 3],
|
|
273
|
+
[false, Infinity],
|
|
274
|
+
];
|
|
275
|
+
examples.forEach(([expected, actual]) => {
|
|
276
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
277
|
+
(0, chai_1.expect)((0, utils_1.isRatioStateUnder)(actual)).to.equal(expected);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
describe('When testing utils.isEmptyBytes()', () => {
|
|
282
|
+
const examples = [
|
|
283
|
+
[true, '0x0000000000000000000000000000000000000000'],
|
|
284
|
+
[false, '0x0000000000000000000000000000000000000001'],
|
|
285
|
+
[false, '0x00000000000000000000000000000000000000000000'],
|
|
286
|
+
[false, '0x000000000000000000000000000000000000000'],
|
|
287
|
+
[false, ''],
|
|
288
|
+
];
|
|
289
|
+
examples.forEach(([expected, actual]) => {
|
|
290
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
291
|
+
(0, chai_1.expect)((0, utils_1.isEmptyBytes)(actual)).to.equal(expected);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
describe('When testing utils.requireAddress()', () => {
|
|
296
|
+
const examples = [
|
|
297
|
+
[true, '0x1e5698681E03326d783215adfB3173acF3Cf2B6'],
|
|
298
|
+
[true, 1312],
|
|
299
|
+
[true, ''],
|
|
300
|
+
[true, '0x0000000000000000000000000000000000000000'],
|
|
301
|
+
[true, '0xZe5698681E03326d783215adfB3173acF3Cf2B6'],
|
|
302
|
+
[true, 'Ze5698681E03326d783215adfB3173acF3Cf2B6'],
|
|
303
|
+
[false, '0x1e5698681E03326d783215adfB3173acF3Cf2B61'],
|
|
304
|
+
];
|
|
305
|
+
examples.forEach(([expected, actual]) => {
|
|
306
|
+
if (expected) {
|
|
307
|
+
it(`Given ${actual} should throw an error`, () => {
|
|
308
|
+
(0, chai_1.expect)(() => (0, utils_1.requireAddress)(actual)).to.throw(Error);
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
it(`Given ${actual} should not throw an error`, () => {
|
|
313
|
+
(0, chai_1.expect)(() => (0, utils_1.requireAddress)(actual)).not.to.throw(Error);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe('When testing utils.requireAddresses()', () => {
|
|
319
|
+
const examples = [
|
|
320
|
+
[true, '0x1e5698681E03326d783215adfB3173acF3Cf2B6'],
|
|
321
|
+
[true, [1312, '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
|
|
322
|
+
[true, ['', '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
|
|
323
|
+
[true, ['0x0000000000000000000000000000000000000000', '0x1e5698481E03326d783215adfB3173acF3Cf2B61']],
|
|
324
|
+
[true, ['0xZe5698681E03326d783215adfB3173acF3Cf2B6', '0x1e5698681E03326d783215adfB3173acF3Cc2B61']],
|
|
325
|
+
[true, ['Ze5698681E03326d783215adfB3173acF3Cf2B6', '', '0x1e5698681E03326d783215adfB3173acF3Cf2B61']],
|
|
326
|
+
[false, ['0x1e5698681E03326d783215adfB3173acF3Cf2B61', '0x2e5698681E03326d783215adfB3173acF3Cf2B61']],
|
|
327
|
+
];
|
|
328
|
+
examples.forEach(([expected, actual]) => {
|
|
329
|
+
if (expected) {
|
|
330
|
+
it(`Given ${actual} should throw an error`, () => {
|
|
331
|
+
(0, chai_1.expect)(() => (0, utils_1.requireAddresses)(actual)).to.throw(Error);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
it(`Given ${actual} should not throw an error`, () => {
|
|
336
|
+
(0, chai_1.expect)(() => (0, utils_1.requireAddresses)(actual)).not.to.throw(Error);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
describe('When testing utils.getRatioStateInfoForAaveCloseStrategy()', () => {
|
|
342
|
+
const examples = [
|
|
343
|
+
[
|
|
344
|
+
{ shouldFlip: true, ratioState: enums_1.RatioState.UNDER },
|
|
345
|
+
[enums_1.RatioState.OVER, (0, tokens_1.getAssetInfo)('DAI').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Ethereum]
|
|
346
|
+
],
|
|
347
|
+
[
|
|
348
|
+
{ shouldFlip: false, ratioState: enums_1.RatioState.UNDER },
|
|
349
|
+
[enums_1.RatioState.UNDER, (0, tokens_1.getAssetInfo)('DAI').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Arbitrum]
|
|
350
|
+
],
|
|
351
|
+
[
|
|
352
|
+
{ shouldFlip: false, ratioState: enums_1.RatioState.OVER },
|
|
353
|
+
[enums_1.RatioState.OVER, (0, tokens_1.getAssetInfo)('ETH').address, (0, tokens_1.getAssetInfo)('ETH').address, enums_1.ChainId.Optimism]
|
|
354
|
+
],
|
|
355
|
+
];
|
|
356
|
+
examples.forEach(([expected, actual]) => {
|
|
357
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
358
|
+
(0, chai_1.expect)((0, utils_1.getRatioStateInfoForAaveCloseStrategy)(...actual)).to.eql(expected);
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare enum RatioState {
|
|
|
7
7
|
OVER = 0,
|
|
8
8
|
UNDER = 1
|
|
9
9
|
}
|
|
10
|
+
export declare enum OrderType {
|
|
11
|
+
TAKE_PROFIT = 0,
|
|
12
|
+
STOP_LOSS = 1
|
|
13
|
+
}
|
|
10
14
|
export declare enum BundleProtocols {
|
|
11
15
|
MStable = "mstable",
|
|
12
16
|
Yearn = "yearn",
|
|
@@ -49,7 +53,9 @@ export declare namespace Strategies {
|
|
|
49
53
|
LIQUITY_CLOSE_ON_PRICE_TO_COLL = 14,
|
|
50
54
|
CHICKEN_BONDS_REBOND = 31,
|
|
51
55
|
EXCHANGE_DCA = 46,
|
|
52
|
-
EXCHANGE_LIMIT_ORDER = 51
|
|
56
|
+
EXCHANGE_LIMIT_ORDER = 51,
|
|
57
|
+
LIQUITY_DSR_PAYBACK = 69,
|
|
58
|
+
LIQUITY_DSR_SUPPLY = 70
|
|
53
59
|
}
|
|
54
60
|
enum OptimismIds {
|
|
55
61
|
EXCHANGE_DCA = 8,
|
|
@@ -61,6 +67,8 @@ export declare namespace Strategies {
|
|
|
61
67
|
}
|
|
62
68
|
enum Identifiers {
|
|
63
69
|
SavingsLiqProtection = "smart-savings-liquidation-protection",
|
|
70
|
+
SavingsDsrPayback = "smart-savings-dsr-payback",
|
|
71
|
+
SavingsDsrSupply = "smart-savings-dsr-supply",
|
|
64
72
|
Repay = "repay",
|
|
65
73
|
EoaRepay = "eoa-repay",
|
|
66
74
|
Boost = "boost",
|
package/esm/types/enums.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bundles = exports.Strategies = exports.ProtocolIdentifiers = exports.BundleProtocols = exports.OrderType = exports.RatioState = exports.ChainId = void 0;
|
|
4
|
+
var ChainId;
|
|
2
5
|
(function (ChainId) {
|
|
3
6
|
ChainId[ChainId["Ethereum"] = 1] = "Ethereum";
|
|
4
7
|
ChainId[ChainId["Optimism"] = 10] = "Optimism";
|
|
5
8
|
ChainId[ChainId["Arbitrum"] = 42161] = "Arbitrum";
|
|
6
|
-
})(ChainId || (ChainId = {}));
|
|
7
|
-
|
|
9
|
+
})(ChainId = exports.ChainId || (exports.ChainId = {}));
|
|
10
|
+
var RatioState;
|
|
8
11
|
(function (RatioState) {
|
|
9
12
|
RatioState[RatioState["OVER"] = 0] = "OVER";
|
|
10
13
|
RatioState[RatioState["UNDER"] = 1] = "UNDER";
|
|
11
|
-
})(RatioState || (RatioState = {}));
|
|
12
|
-
|
|
14
|
+
})(RatioState = exports.RatioState || (exports.RatioState = {}));
|
|
15
|
+
var OrderType;
|
|
16
|
+
(function (OrderType) {
|
|
17
|
+
OrderType[OrderType["TAKE_PROFIT"] = 0] = "TAKE_PROFIT";
|
|
18
|
+
OrderType[OrderType["STOP_LOSS"] = 1] = "STOP_LOSS";
|
|
19
|
+
})(OrderType = exports.OrderType || (exports.OrderType = {}));
|
|
20
|
+
var BundleProtocols;
|
|
13
21
|
(function (BundleProtocols) {
|
|
14
22
|
BundleProtocols["MStable"] = "mstable";
|
|
15
23
|
BundleProtocols["Yearn"] = "yearn";
|
|
16
24
|
BundleProtocols["Rari"] = "rari";
|
|
17
|
-
})(BundleProtocols || (BundleProtocols = {}));
|
|
25
|
+
})(BundleProtocols = exports.BundleProtocols || (exports.BundleProtocols = {}));
|
|
18
26
|
/**
|
|
19
27
|
* @dev Follow the naming convention:
|
|
20
28
|
* - Enum name consists of two parts, name and version
|
|
@@ -22,7 +30,7 @@ export var BundleProtocols;
|
|
|
22
30
|
* - Version should be separated from the name with double underscores `__` (If there is no version leave it out)
|
|
23
31
|
* - Example `Name of ThePROTOCOL__v1` (Without version `Name of ThePROTOCOL`)
|
|
24
32
|
*/
|
|
25
|
-
|
|
33
|
+
var ProtocolIdentifiers;
|
|
26
34
|
(function (ProtocolIdentifiers) {
|
|
27
35
|
let StrategiesAutomation;
|
|
28
36
|
(function (StrategiesAutomation) {
|
|
@@ -43,8 +51,8 @@ export var ProtocolIdentifiers;
|
|
|
43
51
|
LegacyAutomation["CompoundV2"] = "Compound__V2";
|
|
44
52
|
LegacyAutomation["AaveV2"] = "Aave__V2";
|
|
45
53
|
})(LegacyAutomation = ProtocolIdentifiers.LegacyAutomation || (ProtocolIdentifiers.LegacyAutomation = {}));
|
|
46
|
-
})(ProtocolIdentifiers || (ProtocolIdentifiers = {}));
|
|
47
|
-
|
|
54
|
+
})(ProtocolIdentifiers = exports.ProtocolIdentifiers || (exports.ProtocolIdentifiers = {}));
|
|
55
|
+
var Strategies;
|
|
48
56
|
(function (Strategies) {
|
|
49
57
|
let MainnetIds;
|
|
50
58
|
(function (MainnetIds) {
|
|
@@ -58,6 +66,8 @@ export var Strategies;
|
|
|
58
66
|
MainnetIds[MainnetIds["CHICKEN_BONDS_REBOND"] = 31] = "CHICKEN_BONDS_REBOND";
|
|
59
67
|
MainnetIds[MainnetIds["EXCHANGE_DCA"] = 46] = "EXCHANGE_DCA";
|
|
60
68
|
MainnetIds[MainnetIds["EXCHANGE_LIMIT_ORDER"] = 51] = "EXCHANGE_LIMIT_ORDER";
|
|
69
|
+
MainnetIds[MainnetIds["LIQUITY_DSR_PAYBACK"] = 69] = "LIQUITY_DSR_PAYBACK";
|
|
70
|
+
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
61
71
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
62
72
|
let OptimismIds;
|
|
63
73
|
(function (OptimismIds) {
|
|
@@ -72,6 +82,8 @@ export var Strategies;
|
|
|
72
82
|
let Identifiers;
|
|
73
83
|
(function (Identifiers) {
|
|
74
84
|
Identifiers["SavingsLiqProtection"] = "smart-savings-liquidation-protection";
|
|
85
|
+
Identifiers["SavingsDsrPayback"] = "smart-savings-dsr-payback";
|
|
86
|
+
Identifiers["SavingsDsrSupply"] = "smart-savings-dsr-supply";
|
|
75
87
|
Identifiers["Repay"] = "repay";
|
|
76
88
|
Identifiers["EoaRepay"] = "eoa-repay";
|
|
77
89
|
Identifiers["Boost"] = "boost";
|
|
@@ -95,8 +107,8 @@ export var Strategies;
|
|
|
95
107
|
IdOverrides["LeverageManagement"] = "leverage-management";
|
|
96
108
|
IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
|
|
97
109
|
})(IdOverrides = Strategies.IdOverrides || (Strategies.IdOverrides = {}));
|
|
98
|
-
})(Strategies || (Strategies = {}));
|
|
99
|
-
|
|
110
|
+
})(Strategies = exports.Strategies || (exports.Strategies = {}));
|
|
111
|
+
var Bundles;
|
|
100
112
|
(function (Bundles) {
|
|
101
113
|
let MainnetIds;
|
|
102
114
|
(function (MainnetIds) {
|
|
@@ -141,4 +153,4 @@ export var Bundles;
|
|
|
141
153
|
ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_DEBT"] = 2] = "AAVE_V3_CLOSE_TO_DEBT";
|
|
142
154
|
ArbitrumIds[ArbitrumIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 3] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
143
155
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
144
|
-
})(Bundles || (Bundles = {}));
|
|
156
|
+
})(Bundles = exports.Bundles || (exports.Bundles = {}));
|
package/esm/types/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./umd/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -14,7 +14,8 @@
|
|
|
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"
|
|
17
|
+
"prepare": "husky install && npm run gtc",
|
|
18
|
+
"test": "mocha \"./src/**/*.test.ts\" --loader=ts-node/esm --extension ts"
|
|
18
19
|
},
|
|
19
20
|
"author": "DeFi Saver",
|
|
20
21
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"@ethersproject/solidity": "^5.0.9",
|
|
28
29
|
"decimal.js": "^10.4.3",
|
|
29
30
|
"lodash": "^4.17.21",
|
|
30
|
-
"web3": "^1.10.
|
|
31
|
+
"web3-eth-abi": "^1.10.2",
|
|
32
|
+
"web3-utils": "^1.10.2"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@babel/core": "^7.12.10",
|
|
@@ -35,13 +37,14 @@
|
|
|
35
37
|
"@babel/preset-env": "^7.12.11",
|
|
36
38
|
"@babel/preset-typescript": "^7.12.7",
|
|
37
39
|
"@typechain/web3-v1": "https://gitpkg.now.sh/mihai9-lab/TypeChain/packages/target-web3-v1?temp",
|
|
40
|
+
"@types/chai": "^4.3.6",
|
|
38
41
|
"@types/lodash": "^4.14.191",
|
|
42
|
+
"@types/mocha": "^10.0.1",
|
|
39
43
|
"@types/node": "^18.11.15",
|
|
40
|
-
"@types/web3": "^1.2.2",
|
|
41
44
|
"@typescript-eslint/eslint-plugin": "^5.42.0",
|
|
42
45
|
"@typescript-eslint/parser": "^5.42.0",
|
|
43
46
|
"babel-loader": "^8.2.2",
|
|
44
|
-
"chai": "^4.
|
|
47
|
+
"chai": "^4.3.8",
|
|
45
48
|
"dotenv": "^10.0.0",
|
|
46
49
|
"eslint": "8.22.0",
|
|
47
50
|
"eslint-config-airbnb": "^18.0.2",
|
|
@@ -52,16 +55,17 @@
|
|
|
52
55
|
"eslint-plugin-react": "^7.31.11",
|
|
53
56
|
"husky": "^8.0.0",
|
|
54
57
|
"jsdoc-to-markdown": "^6.0.1",
|
|
58
|
+
"mocha": "^10.2.0",
|
|
55
59
|
"react": "^18.2.0",
|
|
56
60
|
"ts-node": "^10.9.1",
|
|
57
61
|
"typechain": "^8.1.0",
|
|
58
62
|
"typedoc": "^0.23.20",
|
|
59
63
|
"typedoc-plugin-markdown": "^3.13.6",
|
|
60
64
|
"typescript": "^4.8.4",
|
|
61
|
-
"web3
|
|
65
|
+
"web3": "^1.10.2",
|
|
62
66
|
"web3-eth-contract": "^1.8.1",
|
|
63
|
-
"web3-
|
|
64
|
-
"webpack": "^5.
|
|
67
|
+
"web3-types": "^1.1.1",
|
|
68
|
+
"webpack": "^5.76.0",
|
|
65
69
|
"webpack-cli": "^4.10.0"
|
|
66
70
|
}
|
|
67
71
|
}
|