@defisaver/automation-sdk 2.1.5 → 3.0.0
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 -4
- package/.env.dev +1 -1
- package/.yarn/releases/yarn-1.22.1.cjs +147386 -0
- package/.yarnrc.yml +3 -0
- package/esm/automation/private/StrategiesAutomation.d.ts +1 -0
- package/esm/automation/private/StrategiesAutomation.js +29 -26
- package/esm/services/strategiesService.js +18 -9
- package/esm/services/strategiesService.test.js +1 -1
- package/esm/services/subDataService.js +0 -1
- package/esm/types/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.ts +52 -50
- package/src/services/strategiesService.test.ts +1 -1
- package/src/services/strategiesService.ts +18 -9
- package/src/services/subDataService.ts +0 -1
- package/src/types/index.ts +2 -1
- package/umd/index.js +68 -58
package/umd/index.js
CHANGED
|
@@ -1517,6 +1517,11 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_6__["def
|
|
|
1517
1517
|
return true;
|
|
1518
1518
|
});
|
|
1519
1519
|
}
|
|
1520
|
+
_mergeCheck(s, current) {
|
|
1521
|
+
return s.owner === current.owner && s.strategy.strategyId === current.strategy.strategyId && s.protocol.id === current.protocol.id && s.specific.mergeId === current.specific.mergeWithId && (s.protocol.id !== _types_enums__WEBPACK_IMPORTED_MODULE_1__.ProtocolIdentifiers.StrategiesAutomation.MakerDAO // reflexer needs to get added if we have it
|
|
1522
|
+
|| s.strategyData.decoded.subData.vaultId === current.strategyData.decoded.triggerData.vaultId) && (s.protocol.id !== _types_enums__WEBPACK_IMPORTED_MODULE_1__.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
|
|
1523
|
+
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase());
|
|
1524
|
+
}
|
|
1520
1525
|
_getSubscriptions(addresses, options) {
|
|
1521
1526
|
var _this5 = this;
|
|
1522
1527
|
return _asyncToGenerator(function* () {
|
|
@@ -1562,38 +1567,35 @@ class StrategiesAutomation extends _Automation__WEBPACK_IMPORTED_MODULE_6__["def
|
|
|
1562
1567
|
};
|
|
1563
1568
|
}()));
|
|
1564
1569
|
if (options !== null && options !== void 0 && options.mergeWithSameId) {
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
});
|
|
1585
|
-
return copyList;
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
}
|
|
1570
|
+
var mergeBase = subscriptions.filter(s => (0,_services_utils__WEBPACK_IMPORTED_MODULE_2__.isDefined)(s) && s.specific.mergeWithId);
|
|
1571
|
+
var mergeExtension = subscriptions.filter(s => (0,_services_utils__WEBPACK_IMPORTED_MODULE_2__.isDefined)(s) && s.specific.mergeId);
|
|
1572
|
+
subscriptions = subscriptions.filter(s => (0,_services_utils__WEBPACK_IMPORTED_MODULE_2__.isDefined)(s) && !(s !== null && s !== void 0 && s.specific.mergeWithId) && !(s !== null && s !== void 0 && s.specific.mergeId)).map(s => _objectSpread(_objectSpread({}, s), {}, {
|
|
1573
|
+
subIds: [s.subId]
|
|
1574
|
+
}));
|
|
1575
|
+
mergeBase.forEach(current => {
|
|
1576
|
+
var mergePairIndexWithEnabledCheck = mergeExtension.findIndex(s => _this5._mergeCheck(s, current) && s.isEnabled === current.isEnabled);
|
|
1577
|
+
var mergePairIndexWithoutEnabledCheck = mergeExtension.findIndex(s => _this5._mergeCheck(s, current));
|
|
1578
|
+
var mergePairIndex = mergePairIndexWithEnabledCheck !== -1 ? mergePairIndexWithEnabledCheck : mergePairIndexWithoutEnabledCheck;
|
|
1579
|
+
if (mergePairIndex !== -1) {
|
|
1580
|
+
var mergePair = mergeExtension[mergePairIndex];
|
|
1581
|
+
mergeExtension.splice(mergePairIndex, 1);
|
|
1582
|
+
subscriptions.push(_objectSpread(_objectSpread(_objectSpread({}, mergePair), current), {}, {
|
|
1583
|
+
// @ts-ignore
|
|
1584
|
+
blockNumber: decimal_js__WEBPACK_IMPORTED_MODULE_0___default().max(mergePair.blockNumber, current.blockNumber).toNumber(),
|
|
1585
|
+
subIds: [current.subId, mergePair.subId],
|
|
1586
|
+
isEnabled: mergePair.isEnabled || current.isEnabled,
|
|
1587
|
+
specific: _objectSpread(_objectSpread({}, mergePair.specific), current.specific)
|
|
1588
|
+
}));
|
|
1589
1589
|
} else {
|
|
1590
|
-
|
|
1590
|
+
subscriptions.push(current);
|
|
1591
1591
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1592
|
+
});
|
|
1593
|
+
if (mergeExtension.length > 0) {
|
|
1594
|
+
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
1595
|
+
subscriptions = [...subscriptions, ...mergeExtension.map(s => _objectSpread(_objectSpread({}, s), {}, {
|
|
1596
|
+
subIds: [s.subId]
|
|
1597
|
+
}))];
|
|
1598
|
+
}
|
|
1597
1599
|
}
|
|
1598
1600
|
}
|
|
1599
1601
|
return _options.unexpiredOnly ? _this5.removeExpiredSubscriptions(subscriptions) : subscriptions;
|
|
@@ -1725,18 +1727,19 @@ function parseMakerLeverageManagement(position, parseData) {
|
|
|
1725
1727
|
triggerRepayRatio: triggerData.ratio,
|
|
1726
1728
|
targetRepayRatio: subData.targetRatio,
|
|
1727
1729
|
repayEnabled: true,
|
|
1728
|
-
subId1: Number(subId)
|
|
1730
|
+
subId1: Number(subId),
|
|
1731
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1729
1732
|
};
|
|
1730
1733
|
} else {
|
|
1731
1734
|
_position.specific = {
|
|
1732
1735
|
triggerBoostRatio: triggerData.ratio,
|
|
1733
1736
|
targetBoostRatio: subData.targetRatio,
|
|
1734
1737
|
boostEnabled: isEnabled,
|
|
1735
|
-
subId2: Number(subId)
|
|
1738
|
+
subId2: Number(subId),
|
|
1739
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1736
1740
|
};
|
|
1737
1741
|
}
|
|
1738
1742
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
1739
|
-
_position.specific.mergeWithSameId = true;
|
|
1740
1743
|
return _position;
|
|
1741
1744
|
}
|
|
1742
1745
|
function parseLiquityCloseOnPrice(position, parseData) {
|
|
@@ -1795,18 +1798,19 @@ function parseAaveV2LeverageManagement(position, parseData) {
|
|
|
1795
1798
|
triggerRepayRatio: triggerData.ratio,
|
|
1796
1799
|
targetRepayRatio: subData.targetRatio,
|
|
1797
1800
|
repayEnabled: true,
|
|
1798
|
-
subId1: Number(subId)
|
|
1801
|
+
subId1: Number(subId),
|
|
1802
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1799
1803
|
};
|
|
1800
1804
|
} else {
|
|
1801
1805
|
_position.specific = {
|
|
1802
1806
|
triggerBoostRatio: triggerData.ratio,
|
|
1803
1807
|
targetBoostRatio: subData.targetRatio,
|
|
1804
1808
|
boostEnabled: isEnabled,
|
|
1805
|
-
subId2: Number(subId)
|
|
1809
|
+
subId2: Number(subId),
|
|
1810
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1806
1811
|
};
|
|
1807
1812
|
}
|
|
1808
1813
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
1809
|
-
_position.specific.mergeWithSameId = true;
|
|
1810
1814
|
return _position;
|
|
1811
1815
|
}
|
|
1812
1816
|
function parseAaveV3LeverageManagement(position, parseData) {
|
|
@@ -1829,18 +1833,19 @@ function parseAaveV3LeverageManagement(position, parseData) {
|
|
|
1829
1833
|
triggerRepayRatio: triggerData.ratio,
|
|
1830
1834
|
targetRepayRatio: subData.targetRatio,
|
|
1831
1835
|
repayEnabled: true,
|
|
1832
|
-
subId1: Number(subId)
|
|
1836
|
+
subId1: Number(subId),
|
|
1837
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1833
1838
|
};
|
|
1834
1839
|
} else {
|
|
1835
1840
|
_position.specific = {
|
|
1836
1841
|
triggerBoostRatio: triggerData.ratio,
|
|
1837
1842
|
targetBoostRatio: subData.targetRatio,
|
|
1838
1843
|
boostEnabled: isEnabled,
|
|
1839
|
-
subId2: Number(subId)
|
|
1844
|
+
subId2: Number(subId),
|
|
1845
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1840
1846
|
};
|
|
1841
1847
|
}
|
|
1842
1848
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
1843
|
-
_position.specific.mergeWithSameId = true;
|
|
1844
1849
|
return _position;
|
|
1845
1850
|
}
|
|
1846
1851
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
@@ -1863,18 +1868,19 @@ function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
|
1863
1868
|
triggerRepayRatio: triggerData.ratio,
|
|
1864
1869
|
targetRepayRatio: subData.targetRatio,
|
|
1865
1870
|
repayEnabled: true,
|
|
1866
|
-
subId1: Number(subId)
|
|
1871
|
+
subId1: Number(subId),
|
|
1872
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1867
1873
|
};
|
|
1868
1874
|
} else {
|
|
1869
1875
|
_position.specific = {
|
|
1870
1876
|
triggerBoostRatio: triggerData.ratio,
|
|
1871
1877
|
targetBoostRatio: subData.targetRatio,
|
|
1872
1878
|
boostEnabled: isEnabled,
|
|
1873
|
-
subId2: Number(subId)
|
|
1879
|
+
subId2: Number(subId),
|
|
1880
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1874
1881
|
};
|
|
1875
1882
|
}
|
|
1876
1883
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
1877
|
-
_position.specific.mergeWithSameId = true;
|
|
1878
1884
|
return _position;
|
|
1879
1885
|
}
|
|
1880
1886
|
function parseAaveV3CloseOnPrice(position, parseData) {
|
|
@@ -1951,18 +1957,19 @@ function parseCompoundV2LeverageManagement(position, parseData) {
|
|
|
1951
1957
|
triggerRepayRatio: triggerData.ratio,
|
|
1952
1958
|
targetRepayRatio: subData.targetRatio,
|
|
1953
1959
|
repayEnabled: true,
|
|
1954
|
-
subId1: Number(subId)
|
|
1960
|
+
subId1: Number(subId),
|
|
1961
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1955
1962
|
};
|
|
1956
1963
|
} else {
|
|
1957
1964
|
_position.specific = {
|
|
1958
1965
|
triggerBoostRatio: triggerData.ratio,
|
|
1959
1966
|
targetBoostRatio: subData.targetRatio,
|
|
1960
1967
|
boostEnabled: isEnabled,
|
|
1961
|
-
subId2: Number(subId)
|
|
1968
|
+
subId2: Number(subId),
|
|
1969
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1962
1970
|
};
|
|
1963
1971
|
}
|
|
1964
1972
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
1965
|
-
_position.specific.mergeWithSameId = true;
|
|
1966
1973
|
return _position;
|
|
1967
1974
|
}
|
|
1968
1975
|
function parseCompoundV3LeverageManagement(position, parseData) {
|
|
@@ -1987,19 +1994,20 @@ function parseCompoundV3LeverageManagement(position, parseData) {
|
|
|
1987
1994
|
triggerRepayRatio: triggerData.ratio,
|
|
1988
1995
|
targetRepayRatio: subData.targetRatio,
|
|
1989
1996
|
repayEnabled: true,
|
|
1990
|
-
subId1: Number(subId)
|
|
1997
|
+
subId1: Number(subId),
|
|
1998
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1991
1999
|
};
|
|
1992
2000
|
} else {
|
|
1993
2001
|
_position.specific = {
|
|
1994
2002
|
triggerBoostRatio: triggerData.ratio,
|
|
1995
2003
|
targetBoostRatio: subData.targetRatio,
|
|
1996
2004
|
boostEnabled: isEnabled,
|
|
1997
|
-
subId2: Number(subId)
|
|
2005
|
+
subId2: Number(subId),
|
|
2006
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
1998
2007
|
};
|
|
1999
2008
|
}
|
|
2000
2009
|
var isEOA = _position.strategy.strategyId.includes('eoa');
|
|
2001
2010
|
_position.strategy.strategyId = isEOA ? _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.EoaLeverageManagement : _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
2002
|
-
_position.specific.mergeWithSameId = true;
|
|
2003
2011
|
return _position;
|
|
2004
2012
|
}
|
|
2005
2013
|
function parseChickenBondsRebond(position, parseData) {
|
|
@@ -2071,18 +2079,19 @@ function parseLiquityLeverageManagement(position, parseData) {
|
|
|
2071
2079
|
triggerRepayRatio: triggerData.ratio,
|
|
2072
2080
|
targetRepayRatio: subData.targetRatio,
|
|
2073
2081
|
repayEnabled: true,
|
|
2074
|
-
subId1: Number(subId)
|
|
2082
|
+
subId1: Number(subId),
|
|
2083
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2075
2084
|
};
|
|
2076
2085
|
} else {
|
|
2077
2086
|
_position.specific = {
|
|
2078
2087
|
triggerBoostRatio: triggerData.ratio,
|
|
2079
2088
|
targetBoostRatio: subData.targetRatio,
|
|
2080
2089
|
boostEnabled: isEnabled,
|
|
2081
|
-
subId2: Number(subId)
|
|
2090
|
+
subId2: Number(subId),
|
|
2091
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2082
2092
|
};
|
|
2083
2093
|
}
|
|
2084
2094
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
2085
|
-
_position.specific.mergeWithSameId = true;
|
|
2086
2095
|
return _position;
|
|
2087
2096
|
}
|
|
2088
2097
|
function parseSparkLeverageManagement(position, parseData) {
|
|
@@ -2105,18 +2114,19 @@ function parseSparkLeverageManagement(position, parseData) {
|
|
|
2105
2114
|
triggerRepayRatio: triggerData.ratio,
|
|
2106
2115
|
targetRepayRatio: subData.targetRatio,
|
|
2107
2116
|
repayEnabled: true,
|
|
2108
|
-
subId1: Number(subId)
|
|
2117
|
+
subId1: Number(subId),
|
|
2118
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2109
2119
|
};
|
|
2110
2120
|
} else {
|
|
2111
2121
|
_position.specific = {
|
|
2112
2122
|
triggerBoostRatio: triggerData.ratio,
|
|
2113
2123
|
targetBoostRatio: subData.targetRatio,
|
|
2114
2124
|
boostEnabled: isEnabled,
|
|
2115
|
-
subId2: Number(subId)
|
|
2125
|
+
subId2: Number(subId),
|
|
2126
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2116
2127
|
};
|
|
2117
2128
|
}
|
|
2118
2129
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
2119
|
-
_position.specific.mergeWithSameId = true;
|
|
2120
2130
|
return _position;
|
|
2121
2131
|
}
|
|
2122
2132
|
function parseSparkCloseOnPrice(position, parseData) {
|
|
@@ -2200,7 +2210,8 @@ function parseCrvUSDLeverageManagement(position, parseData) {
|
|
|
2200
2210
|
targetRepayRatio: subData.targetRatio,
|
|
2201
2211
|
repayEnabled: isEnabled,
|
|
2202
2212
|
subId1: Number(subId),
|
|
2203
|
-
subHashRepay: subHash
|
|
2213
|
+
subHashRepay: subHash,
|
|
2214
|
+
mergeWithId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2204
2215
|
};
|
|
2205
2216
|
} else {
|
|
2206
2217
|
_position.specific = {
|
|
@@ -2208,12 +2219,12 @@ function parseCrvUSDLeverageManagement(position, parseData) {
|
|
|
2208
2219
|
targetBoostRatio: subData.targetRatio,
|
|
2209
2220
|
boostEnabled: isEnabled,
|
|
2210
2221
|
subId2: Number(subId),
|
|
2211
|
-
subHashBoost: subHash
|
|
2222
|
+
subHashBoost: subHash,
|
|
2223
|
+
mergeId: _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.Identifiers.Boost
|
|
2212
2224
|
};
|
|
2213
2225
|
}
|
|
2214
2226
|
_position.positionId = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
|
|
2215
2227
|
_position.strategy.strategyId = _types_enums__WEBPACK_IMPORTED_MODULE_3__.Strategies.IdOverrides.LeverageManagement;
|
|
2216
|
-
_position.specific.mergeWithSameId = true;
|
|
2217
2228
|
return _position;
|
|
2218
2229
|
}
|
|
2219
2230
|
var parsingMethodsMapping = {
|
|
@@ -19780,7 +19791,6 @@ var compoundV3L2LeverageManagementSubData = {
|
|
|
19780
19791
|
return subInput;
|
|
19781
19792
|
},
|
|
19782
19793
|
decode(subData) {
|
|
19783
|
-
console.log(subData);
|
|
19784
19794
|
var ratioWei = web3_eth_abi__WEBPACK_IMPORTED_MODULE_1___default().decodeParameter('uint256', subData[3]);
|
|
19785
19795
|
var targetRatio = (0,_utils__WEBPACK_IMPORTED_MODULE_6__.weiToRatioPercentage)(ratioWei);
|
|
19786
19796
|
return {
|