@defisaver/automation-sdk 2.0.6 → 2.0.9
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/.env +4 -0
- package/.env.dev +5 -0
- package/.tests.sh +3 -0
- package/README.md +3 -1
- package/esm/automation/private/LegacyAutomation.js +9 -3
- package/esm/automation/private/LegacyProtocol.test.d.ts +1 -0
- package/esm/automation/private/LegacyProtocol.test.js +25 -0
- package/esm/automation/private/Protocol.test.d.ts +1 -0
- package/esm/automation/private/Protocol.test.js +25 -0
- package/esm/automation/private/StrategiesAutomation.d.ts +4 -0
- package/esm/automation/private/StrategiesAutomation.js +29 -4
- package/esm/constants/index.js +5 -0
- package/esm/services/contractService.d.ts +3 -2
- package/esm/services/contractService.js +7 -1
- package/esm/services/ethereumService.test.d.ts +1 -0
- package/esm/services/ethereumService.test.js +241 -0
- package/esm/services/strategiesService.js +14 -0
- package/esm/services/strategiesService.test.d.ts +1 -0
- package/esm/services/strategiesService.test.js +108 -0
- package/esm/services/strategySubService.d.ts +5 -3
- package/esm/services/strategySubService.js +10 -6
- package/esm/services/strategySubService.test.d.ts +1 -0
- package/esm/services/strategySubService.test.js +692 -0
- package/esm/services/subDataService.d.ts +8 -1
- package/esm/services/subDataService.js +23 -14
- package/esm/services/subDataService.test.d.ts +1 -0
- package/esm/services/subDataService.test.js +993 -0
- package/esm/services/triggerService.d.ts +7 -0
- package/esm/services/triggerService.js +14 -1
- package/esm/services/triggerService.test.js +119 -17
- package/esm/types/enums.d.ts +4 -2
- package/esm/types/enums.js +2 -0
- package/esm/types/index.d.ts +13 -4
- package/package.json +5 -5
- package/src/automation/private/LegacyAutomation.ts +14 -4
- package/src/automation/private/LegacyProtocol.test.ts +24 -0
- package/src/automation/private/Protocol.test.ts +24 -0
- package/src/automation/private/StrategiesAutomation.ts +40 -6
- package/src/constants/index.ts +5 -0
- package/src/services/contractService.ts +17 -4
- package/src/services/ethereumService.test.ts +256 -0
- package/src/services/ethereumService.ts +2 -1
- package/src/services/strategiesService.test.ts +103 -0
- package/src/services/strategiesService.ts +27 -3
- package/src/services/strategySubService.test.ts +835 -0
- package/src/services/strategySubService.ts +28 -15
- package/src/services/subDataService.test.ts +1063 -0
- package/src/services/subDataService.ts +29 -14
- package/src/services/triggerService.test.ts +131 -19
- package/src/services/triggerService.ts +14 -0
- package/src/services/utils.test.ts +1 -1
- package/src/types/enums.ts +2 -0
- package/src/types/index.ts +20 -5
- package/umd/index.js +919 -523
package/.env
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
RPC_1=https://mainnet.infura.io/v3/a3503e4501d040cd9ea2c913c68983a1
|
|
2
|
+
RPC_10=https://opt-mainnet.g.alchemy.com/v2/Pwh-hdbsP7Bf0CP_UMw4_Pw-NfHhSpIA
|
|
3
|
+
RPC_8453=https://base-mainnet.g.alchemy.com/v2/TERsAaPNcA7sgCVHHAMBvd95UtT4wCEf
|
|
4
|
+
RPC_42161=https://arb-mainnet.g.alchemy.com/v2/Pwh-hdbsP7Bf0CP_UMw4_Pw-NfHhSpIA
|
package/.env.dev
ADDED
package/.tests.sh
ADDED
package/README.md
CHANGED
|
@@ -33,4 +33,6 @@ const subscriptions = await ethereumStrategies.getSubscriptionsFor(
|
|
|
33
33
|
- `./src/services/subDataService.ts`
|
|
34
34
|
- `./src/services/triggerService.ts`
|
|
35
35
|
- Write parsing for the strategy in `./src/services/strategeiesService.ts` and add assign it to `const parsingMethodsMapping`
|
|
36
|
-
-
|
|
36
|
+
- Write tests for each method
|
|
37
|
+
- Run tests with `yarn test` or `yarn test fileName` for a specific file (e.g. `yarn test utils`)
|
|
38
|
+
- Congrats! 🥳
|
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
15
16
|
const contractService_1 = require("../../services/contractService");
|
|
16
17
|
const ethereumService_1 = require("../../services/ethereumService");
|
|
17
18
|
const utils_1 = require("../../services/utils");
|
|
@@ -82,13 +83,18 @@ class LegacyAutomation extends Automation_1.default {
|
|
|
82
83
|
}
|
|
83
84
|
getParsedSubscriptions(addresses, options) {
|
|
84
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
// Legacy automation was disabled on block 18213086
|
|
87
|
+
if (!(options === null || options === void 0 ? void 0 : options.fromBlock)
|
|
88
|
+
|| (options === null || options === void 0 ? void 0 : options.fromBlock) === 'latest'
|
|
89
|
+
|| (options === null || options === void 0 ? void 0 : options.fromBlock) === 'pending'
|
|
90
|
+
|| ((options === null || options === void 0 ? void 0 : options.fromBlock) && new decimal_js_1.default(options === null || options === void 0 ? void 0 : options.fromBlock.toString()).lt(18213086))) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
85
93
|
const subscriptions = yield this._getSubscriptions(addresses, options);
|
|
86
|
-
// @ts-ignore
|
|
87
94
|
return subscriptions.map((sub) => ({
|
|
88
95
|
chainId: this.chainId,
|
|
89
96
|
owner: sub[this.getOwnerPropName()],
|
|
90
|
-
isEnabled:
|
|
91
|
-
? (options === null || options === void 0 ? void 0 : options.fromBlock) > 18213086 : false,
|
|
97
|
+
isEnabled: true,
|
|
92
98
|
protocol: this.protocol,
|
|
93
99
|
specific: Object.assign({}, sub),
|
|
94
100
|
strategy: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const enums_1 = require("../../types/enums");
|
|
8
|
+
const LegacyProtocol_1 = __importDefault(require("./LegacyProtocol"));
|
|
9
|
+
describe('Feature: LegacyProtocol.ts', () => {
|
|
10
|
+
describe('When testing class LegacyProtocol', () => {
|
|
11
|
+
const exampleProtocol = new LegacyProtocol_1.default({ id: enums_1.ProtocolIdentifiers.LegacyAutomation.MakerDAO });
|
|
12
|
+
const examples = [
|
|
13
|
+
[exampleProtocol.id, 'MakerDAO'],
|
|
14
|
+
[exampleProtocol.name, 'MakerDAO'],
|
|
15
|
+
[exampleProtocol.slug, 'makerdao'],
|
|
16
|
+
[exampleProtocol.version, ''],
|
|
17
|
+
[exampleProtocol.fullName, 'MakerDAO'],
|
|
18
|
+
];
|
|
19
|
+
examples.forEach(([expected, actual]) => {
|
|
20
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
21
|
+
(0, chai_1.expect)(actual).to.equal(expected);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const enums_1 = require("../../types/enums");
|
|
8
|
+
const Protocol_1 = __importDefault(require("./Protocol"));
|
|
9
|
+
describe('Feature: Protocol.ts', () => {
|
|
10
|
+
describe('When testing class Protocol', () => {
|
|
11
|
+
const exampleProtocol = new Protocol_1.default({ id: enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3 });
|
|
12
|
+
const examples = [
|
|
13
|
+
[exampleProtocol.id, 'Aave__V3'],
|
|
14
|
+
[exampleProtocol.name, 'Aave'],
|
|
15
|
+
[exampleProtocol.slug, 'aave'],
|
|
16
|
+
[exampleProtocol.version, 'V3'],
|
|
17
|
+
[exampleProtocol.fullName, 'Aave V3'],
|
|
18
|
+
];
|
|
19
|
+
examples.forEach(([expected, actual]) => {
|
|
20
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
21
|
+
(0, chai_1.expect)(actual).to.equal(expected);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -20,6 +20,10 @@ export default class StrategiesAutomation extends Automation {
|
|
|
20
20
|
protected getSubscriptionEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
|
|
21
21
|
protected getUpdateDataEventsFromSubStorage(options?: PastEventOptions): Promise<any[]>;
|
|
22
22
|
protected getParsedSubscriptions(parseData: ParseData): Position.Automated | null;
|
|
23
|
+
/**
|
|
24
|
+
* @description Removes expired Limit Order subscriptions
|
|
25
|
+
*/
|
|
26
|
+
protected removeExpiredSubscriptions(subscriptions: (Position.Automated | null)[]): (Position.Automated | null)[];
|
|
23
27
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
24
28
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
25
29
|
getSubscriptionsFor(addresses: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
16
|
+
const enums_1 = require("../../types/enums");
|
|
16
17
|
const utils_1 = require("../../services/utils");
|
|
17
18
|
const contractService_1 = require("../../services/contractService");
|
|
18
19
|
const ethereumService_1 = require("../../services/ethereumService");
|
|
@@ -70,14 +71,38 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
70
71
|
getParsedSubscriptions(parseData) {
|
|
71
72
|
return (0, strategiesService_1.parseStrategiesAutomatedPosition)(parseData);
|
|
72
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* @description Removes expired Limit Order subscriptions
|
|
76
|
+
*/
|
|
77
|
+
removeExpiredSubscriptions(subscriptions) {
|
|
78
|
+
return subscriptions.filter((subscription) => {
|
|
79
|
+
if (!subscription) {
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const { protocol, strategy, strategyData } = subscription;
|
|
83
|
+
if (protocol.id === enums_1.ProtocolIdentifiers.StrategiesAutomation.Exchange
|
|
84
|
+
&& strategy.strategyId === enums_1.Strategies.Identifiers.LimitOrder) {
|
|
85
|
+
return new decimal_js_1.default(strategyData.decoded.triggerData.goodUntil).gt(new decimal_js_1.default(Date.now()).div(1000));
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
});
|
|
89
|
+
}
|
|
73
90
|
_getSubscriptions(addresses, options) {
|
|
74
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
92
|
const _options = Object.assign(Object.assign({}, (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(options), options)), (0, utils_1.addToObjectIf)((0, utils_1.isDefined)(addresses), { filter: { proxy: addresses } }));
|
|
76
|
-
|
|
93
|
+
let subscriptionEvents = (yield this.getSubscriptionEventsFromSubStorage(_options)); // TODO PlaceholderType
|
|
77
94
|
let subscriptions = [];
|
|
78
95
|
if (subscriptionEvents) {
|
|
79
|
-
|
|
80
|
-
|
|
96
|
+
let strategiesSubs = yield this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.toBlock);
|
|
97
|
+
if (_options.enabledOnly) {
|
|
98
|
+
const filteredSubscriptionEvents = [];
|
|
99
|
+
strategiesSubs = strategiesSubs.filter((sub, index) => {
|
|
100
|
+
if (sub === null || sub === void 0 ? void 0 : sub.isEnabled)
|
|
101
|
+
filteredSubscriptionEvents.push(subscriptionEvents[index]);
|
|
102
|
+
return sub === null || sub === void 0 ? void 0 : sub.isEnabled;
|
|
103
|
+
});
|
|
104
|
+
subscriptionEvents = filteredSubscriptionEvents;
|
|
105
|
+
}
|
|
81
106
|
subscriptions = yield Promise.all(strategiesSubs.map((sub, index) => __awaiter(this, void 0, void 0, function* () {
|
|
82
107
|
var _a;
|
|
83
108
|
let latestUpdate = subscriptionEvents[index].returnValues;
|
|
@@ -120,7 +145,7 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
120
145
|
}, []);
|
|
121
146
|
}
|
|
122
147
|
}
|
|
123
|
-
return subscriptions;
|
|
148
|
+
return _options.unexpiredOnly ? this.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
124
149
|
});
|
|
125
150
|
}
|
|
126
151
|
getSubscriptions(options) {
|
package/esm/constants/index.js
CHANGED
|
@@ -85,6 +85,11 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
85
85
|
strategyId: enums_1.Strategies.Identifiers.SavingsDsrSupply,
|
|
86
86
|
protocol: exports.PROTOCOLS.Liquity,
|
|
87
87
|
},
|
|
88
|
+
[enums_1.Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY]: {
|
|
89
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
|
|
90
|
+
strategyId: enums_1.Strategies.Identifiers.DebtInFrontRepay,
|
|
91
|
+
protocol: exports.PROTOCOLS.Liquity,
|
|
92
|
+
},
|
|
88
93
|
};
|
|
89
94
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
90
95
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
|
-
import type { Contract } from '../types';
|
|
3
|
+
import type { Contract, EthereumAddress } from '../types';
|
|
4
4
|
import type { BaseContract } from '../types/contracts/generated/types';
|
|
5
|
-
import type { Legacy_AuthCheck, SubStorage, UniMulticall } from '../types/contracts/generated';
|
|
5
|
+
import type { Legacy_AuthCheck, SubStorage, UniMulticall, Erc20 } from '../types/contracts/generated';
|
|
6
6
|
import { ChainId } from '../types/enums';
|
|
7
7
|
export declare function getAbiItem(abi: AbiItem[], itemName: string): AbiItem;
|
|
8
8
|
export declare function makeUniMulticallContract(web3: Web3, chainId: ChainId): Contract.WithMeta<UniMulticall>;
|
|
9
9
|
export declare function makeSubStorageContract(web3: Web3, chainId: ChainId): Contract.WithMeta<SubStorage>;
|
|
10
10
|
export declare function makeAuthCheckerContract(web3: Web3, chainId: ChainId): Contract.WithMeta<Legacy_AuthCheck>;
|
|
11
11
|
export declare function makeLegacySubscriptionContract<T extends BaseContract>(web3: Web3, contractJson: Contract.Json): Contract.WithMeta<T>;
|
|
12
|
+
export declare function makeErc20Contract(web3: Web3, tokenAddress: EthereumAddress, chainId: ChainId): Contract.WithMeta<Erc20>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeLegacySubscriptionContract = exports.makeAuthCheckerContract = exports.makeSubStorageContract = exports.makeUniMulticallContract = exports.getAbiItem = void 0;
|
|
3
|
+
exports.makeErc20Contract = exports.makeLegacySubscriptionContract = exports.makeAuthCheckerContract = exports.makeSubStorageContract = exports.makeUniMulticallContract = exports.getAbiItem = void 0;
|
|
4
4
|
const abis_1 = require("../abis");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const enums_1 = require("../types/enums");
|
|
@@ -46,3 +46,9 @@ function makeLegacySubscriptionContract(web3, contractJson) {
|
|
|
46
46
|
return makeContract(web3, contractJson, enums_1.ChainId.Ethereum);
|
|
47
47
|
}
|
|
48
48
|
exports.makeLegacySubscriptionContract = makeLegacySubscriptionContract;
|
|
49
|
+
function makeErc20Contract(web3, tokenAddress, chainId) {
|
|
50
|
+
return makeContract(web3, Object.assign(Object.assign({}, abis_1.Erc20Json), { networks: {
|
|
51
|
+
[chainId]: { address: tokenAddress },
|
|
52
|
+
} }), chainId);
|
|
53
|
+
}
|
|
54
|
+
exports.makeErc20Contract = makeErc20Contract;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const web3_1 = __importDefault(require("web3"));
|
|
16
|
+
const chai_1 = require("chai");
|
|
17
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
18
|
+
const enums_1 = require("../types/enums");
|
|
19
|
+
const ethereumService_1 = require("./ethereumService");
|
|
20
|
+
const contractService_1 = require("./contractService");
|
|
21
|
+
require('dotenv').config({ path: '.env' });
|
|
22
|
+
const Web3_1 = new web3_1.default(process.env.RPC_1);
|
|
23
|
+
const Web3_10 = new web3_1.default(process.env.RPC_10);
|
|
24
|
+
const Web3_42161 = new web3_1.default(process.env.RPC_42161);
|
|
25
|
+
describe('Feature: ethereumService.ts', () => {
|
|
26
|
+
describe('When testing ethereumService.multicall', () => {
|
|
27
|
+
const examples = [
|
|
28
|
+
[
|
|
29
|
+
[{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
|
|
30
|
+
[
|
|
31
|
+
Web3_1,
|
|
32
|
+
enums_1.ChainId.Ethereum,
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'name', 'outputs': [{ 'name': '', 'type': 'string' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
36
|
+
target: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
37
|
+
params: [],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'decimals', 'outputs': [{ 'name': '', 'type': 'uint8' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
41
|
+
target: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
42
|
+
params: [],
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
'latest',
|
|
46
|
+
]
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
[{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
|
|
50
|
+
[
|
|
51
|
+
Web3_10,
|
|
52
|
+
enums_1.ChainId.Optimism,
|
|
53
|
+
[
|
|
54
|
+
{
|
|
55
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'name', 'outputs': [{ 'name': '', 'type': 'string' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
56
|
+
target: '0x4200000000000000000000000000000000000006',
|
|
57
|
+
params: [],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'decimals', 'outputs': [{ 'name': '', 'type': 'uint8' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
61
|
+
target: '0x4200000000000000000000000000000000000006',
|
|
62
|
+
params: [],
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
'latest',
|
|
66
|
+
]
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
[{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
|
|
70
|
+
[
|
|
71
|
+
Web3_42161,
|
|
72
|
+
enums_1.ChainId.Arbitrum,
|
|
73
|
+
[
|
|
74
|
+
{
|
|
75
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'name', 'outputs': [{ 'name': '', 'type': 'string' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
76
|
+
target: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
77
|
+
params: [],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
abiItem: { 'constant': true, 'inputs': [], 'name': 'decimals', 'outputs': [{ 'name': '', 'type': 'uint8' }], 'payable': false, 'stateMutability': 'view', 'type': 'function' },
|
|
81
|
+
target: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
|
|
82
|
+
params: [],
|
|
83
|
+
}
|
|
84
|
+
],
|
|
85
|
+
'latest',
|
|
86
|
+
]
|
|
87
|
+
],
|
|
88
|
+
];
|
|
89
|
+
examples.forEach(([expected, actual]) => {
|
|
90
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
(0, chai_1.expect)(yield (0, ethereumService_1.multicall)(...actual)).to.eql(expected);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('When testing ethereumService.getEventsFromContract', () => {
|
|
96
|
+
const examples = [
|
|
97
|
+
[
|
|
98
|
+
[
|
|
99
|
+
{
|
|
100
|
+
'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
|
|
101
|
+
'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
|
|
102
|
+
'blockNumber': 15166163,
|
|
103
|
+
'event': 'Transfer',
|
|
104
|
+
'id': 'log_e2258e3a',
|
|
105
|
+
'logIndex': 385,
|
|
106
|
+
'raw': {
|
|
107
|
+
'data': '0x0000000000000000000000000000000000000000000001b58c2186829983fca9',
|
|
108
|
+
'topics': [
|
|
109
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
110
|
+
'0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
|
|
111
|
+
'0x0000000000000000000000009ccf93089cb14f94baeb8822f8ceffd91bd71649',
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
'removed': false,
|
|
115
|
+
'returnValues': {
|
|
116
|
+
'0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
117
|
+
'1': '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
|
|
118
|
+
'2': '8071324659946094853289',
|
|
119
|
+
'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
120
|
+
'to': '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
|
|
121
|
+
'value': '8071324659946094853289',
|
|
122
|
+
},
|
|
123
|
+
'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
124
|
+
'transactionHash': '0x95b28d8f71719c219e09b428e6ff781d717088784fbf63681446da13de6b0c4a',
|
|
125
|
+
'transactionIndex': 187,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
(0, contractService_1.makeErc20Contract)(Web3_1, (0, tokens_1.getAssetInfo)('LUSD').address, enums_1.ChainId.Ethereum),
|
|
130
|
+
null,
|
|
131
|
+
'Transfer',
|
|
132
|
+
{
|
|
133
|
+
fromBlock: 15166163,
|
|
134
|
+
toBlock: 15166163,
|
|
135
|
+
filter: {
|
|
136
|
+
from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
137
|
+
to: '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
]
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
[
|
|
144
|
+
{
|
|
145
|
+
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
146
|
+
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
147
|
+
'blockNumber': 5353002,
|
|
148
|
+
'event': 'Transfer',
|
|
149
|
+
'id': 'log_f49645b8',
|
|
150
|
+
'logIndex': 1,
|
|
151
|
+
'raw': {
|
|
152
|
+
'data': '0x000000000000000000000000000000000000000000000001158e460913d00000',
|
|
153
|
+
'topics': [
|
|
154
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
155
|
+
'0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
|
|
156
|
+
'0x00000000000000000000000013a22f1bba428eaaf56960530ec11118da916c11',
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
'removed': false,
|
|
160
|
+
'returnValues': {
|
|
161
|
+
'0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
162
|
+
'1': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
|
|
163
|
+
'2': '20000000000000000000',
|
|
164
|
+
'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
165
|
+
'to': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
|
|
166
|
+
'value': '20000000000000000000',
|
|
167
|
+
},
|
|
168
|
+
'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
169
|
+
'transactionHash': '0x37c886a97c938747299c0f6b3e4591304bdd47a938df7c8146454d6fee5a6501',
|
|
170
|
+
'transactionIndex': 0,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
(0, contractService_1.makeErc20Contract)(Web3_10, (0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Optimism).address, enums_1.ChainId.Optimism),
|
|
175
|
+
null,
|
|
176
|
+
'Transfer',
|
|
177
|
+
{
|
|
178
|
+
fromBlock: 5353002,
|
|
179
|
+
toBlock: 5353002,
|
|
180
|
+
filter: {
|
|
181
|
+
from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
182
|
+
to: '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
]
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
[
|
|
189
|
+
{
|
|
190
|
+
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
191
|
+
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
192
|
+
'blockNumber': 5353002,
|
|
193
|
+
'event': 'Transfer',
|
|
194
|
+
'id': 'log_f49645b8',
|
|
195
|
+
'logIndex': 1,
|
|
196
|
+
'raw': {
|
|
197
|
+
'data': '0x000000000000000000000000000000000000000000000001158e460913d00000',
|
|
198
|
+
'topics': [
|
|
199
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
200
|
+
'0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
|
|
201
|
+
'0x00000000000000000000000013a22f1bba428eaaf56960530ec11118da916c11',
|
|
202
|
+
],
|
|
203
|
+
},
|
|
204
|
+
'removed': false,
|
|
205
|
+
'returnValues': {
|
|
206
|
+
'0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
207
|
+
'1': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
|
|
208
|
+
'2': '20000000000000000000',
|
|
209
|
+
'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
210
|
+
'to': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
|
|
211
|
+
'value': '20000000000000000000',
|
|
212
|
+
},
|
|
213
|
+
'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
214
|
+
'transactionHash': '0x37c886a97c938747299c0f6b3e4591304bdd47a938df7c8146454d6fee5a6501',
|
|
215
|
+
'transactionIndex': 0,
|
|
216
|
+
},
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
(0, contractService_1.makeErc20Contract)(Web3_10, (0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Arbitrum).address, enums_1.ChainId.Arbitrum),
|
|
220
|
+
null,
|
|
221
|
+
'Transfer',
|
|
222
|
+
{
|
|
223
|
+
fromBlock: 5353002,
|
|
224
|
+
toBlock: 5353002,
|
|
225
|
+
filter: {
|
|
226
|
+
from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
|
|
227
|
+
to: '0x13a22f1bba428eaaf56960530ec11118da916c11',
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
]
|
|
231
|
+
],
|
|
232
|
+
];
|
|
233
|
+
examples.forEach(([expected, actual]) => {
|
|
234
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
+
const data = yield (0, ethereumService_1.getEventsFromContract)(...actual);
|
|
236
|
+
console.log(data);
|
|
237
|
+
(0, chai_1.expect)(yield (0, ethereumService_1.getEventsFromContract)(...actual)).to.eql(expected);
|
|
238
|
+
}));
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
@@ -458,6 +458,19 @@ function parseLiquitySavingsLiqProtection(position, parseData) {
|
|
|
458
458
|
};
|
|
459
459
|
return _position;
|
|
460
460
|
}
|
|
461
|
+
function parseDebtInFrontRepay(position, parseData) {
|
|
462
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
463
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
464
|
+
const triggerData = triggerService.liquityDebtInFrontWithLimitTrigger.decode(subStruct.triggerData);
|
|
465
|
+
const subData = subDataService.liquityDebtInFrontRepaySubData.decode(subStruct.subData);
|
|
466
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
467
|
+
_position.strategyData.decoded.subData = subData;
|
|
468
|
+
_position.specific = {
|
|
469
|
+
debtInFrontMin: triggerData.debtInFrontMin,
|
|
470
|
+
targetRepayRatioIncrease: subData.targetRatioIncrease,
|
|
471
|
+
};
|
|
472
|
+
return _position;
|
|
473
|
+
}
|
|
461
474
|
const parsingMethodsMapping = {
|
|
462
475
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
463
476
|
[enums_1.Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -476,6 +489,7 @@ const parsingMethodsMapping = {
|
|
|
476
489
|
[enums_1.Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
|
|
477
490
|
[enums_1.Strategies.Identifiers.SavingsDsrPayback]: parseLiquitySavingsLiqProtection,
|
|
478
491
|
[enums_1.Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
492
|
+
[enums_1.Strategies.Identifiers.DebtInFrontRepay]: parseDebtInFrontRepay,
|
|
479
493
|
},
|
|
480
494
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
481
495
|
[enums_1.Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const chai_1 = require("chai");
|
|
13
|
+
const enums_1 = require("../types/enums");
|
|
14
|
+
const strategiesService_1 = require("./strategiesService");
|
|
15
|
+
describe('Feature: strategiesService.ts', () => {
|
|
16
|
+
describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
// TODO: we should probably write this for every strategy?
|
|
18
|
+
const examples = [
|
|
19
|
+
[
|
|
20
|
+
{
|
|
21
|
+
isEnabled: true,
|
|
22
|
+
chainId: 1,
|
|
23
|
+
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
24
|
+
blockNumber: 18015756,
|
|
25
|
+
subId: 379,
|
|
26
|
+
owner: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
27
|
+
protocol: {
|
|
28
|
+
id: enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3,
|
|
29
|
+
name: 'Aave',
|
|
30
|
+
slug: 'aave',
|
|
31
|
+
version: 'V3',
|
|
32
|
+
fullName: 'Aave V3'
|
|
33
|
+
},
|
|
34
|
+
strategy: {
|
|
35
|
+
isBundle: true,
|
|
36
|
+
strategyOrBundleId: 8,
|
|
37
|
+
strategyId: enums_1.Strategies.IdOverrides.LeverageManagement,
|
|
38
|
+
protocol: {
|
|
39
|
+
id: enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV3,
|
|
40
|
+
name: 'Aave',
|
|
41
|
+
slug: 'aave',
|
|
42
|
+
version: 'V3',
|
|
43
|
+
fullName: 'Aave V3'
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
strategyData: {
|
|
47
|
+
encoded: {
|
|
48
|
+
triggerData: [
|
|
49
|
+
'0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
|
|
50
|
+
],
|
|
51
|
+
subData: [
|
|
52
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
53
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
54
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
55
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
decoded: {
|
|
59
|
+
triggerData: {
|
|
60
|
+
owner: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
61
|
+
market: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
62
|
+
ratio: 185,
|
|
63
|
+
ratioState: 1
|
|
64
|
+
},
|
|
65
|
+
subData: { targetRatio: 200 }
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
specific: {
|
|
69
|
+
triggerRepayRatio: 185,
|
|
70
|
+
targetRepayRatio: 200,
|
|
71
|
+
repayEnabled: true,
|
|
72
|
+
subId1: 379,
|
|
73
|
+
mergeWithSameId: true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
chainId: 1,
|
|
78
|
+
blockNumber: 18015756,
|
|
79
|
+
subscriptionEventData: {
|
|
80
|
+
subId: '379',
|
|
81
|
+
proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
|
|
82
|
+
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
subStruct: {
|
|
85
|
+
strategyOrBundleId: '8',
|
|
86
|
+
isBundle: true,
|
|
87
|
+
triggerData: ['0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
|
|
88
|
+
subData: [
|
|
89
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000', '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
90
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
91
|
+
],
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
strategiesSubsData: {
|
|
95
|
+
userProxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
96
|
+
isEnabled: true,
|
|
97
|
+
strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1'
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
];
|
|
102
|
+
examples.forEach(([expected, actual]) => {
|
|
103
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
(0, chai_1.expect)((0, strategiesService_1.parseStrategiesAutomatedPosition)(actual)).to.eql(expected);
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
}));
|
|
108
|
+
});
|