@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-dev
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/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
- package/cjs/automation/private/StrategiesAutomation.js +10 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
- package/esm/automation/private/StrategiesAutomation.js +10 -1
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +11 -0
- package/src/constants/index.ts +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
|
@@ -2089,4 +2089,218 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2089
2089
|
});
|
|
2090
2090
|
});
|
|
2091
2091
|
});
|
|
2092
|
+
describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
|
|
2093
|
+
describe('encode()', () => {
|
|
2094
|
+
const examples = [
|
|
2095
|
+
[
|
|
2096
|
+
[
|
|
2097
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2098
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2099
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2100
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2101
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2102
|
+
'0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
2103
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2104
|
+
],
|
|
2105
|
+
[
|
|
2106
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
2107
|
+
0,
|
|
2108
|
+
web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
2109
|
+
1,
|
|
2110
|
+
web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2111
|
+
200,
|
|
2112
|
+
]
|
|
2113
|
+
]
|
|
2114
|
+
];
|
|
2115
|
+
examples.forEach(([expected, actual]) => {
|
|
2116
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2117
|
+
(0, chai_1.expect)(subDataService.sparkLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
2118
|
+
});
|
|
2119
|
+
});
|
|
2120
|
+
});
|
|
2121
|
+
describe('decode()', () => {
|
|
2122
|
+
const examples = [
|
|
2123
|
+
[
|
|
2124
|
+
{
|
|
2125
|
+
collAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
2126
|
+
collAssetId: 2,
|
|
2127
|
+
debtAsset: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
2128
|
+
debtAssetId: 4,
|
|
2129
|
+
marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
|
|
2130
|
+
targetRatio: 175
|
|
2131
|
+
},
|
|
2132
|
+
[
|
|
2133
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
2134
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
2135
|
+
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
2136
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
2137
|
+
'0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
|
|
2138
|
+
'0x00000000000000000000000000000000000000000000000018493fba64ef0000'
|
|
2139
|
+
]
|
|
2140
|
+
]
|
|
2141
|
+
];
|
|
2142
|
+
examples.forEach(([expected, actual]) => {
|
|
2143
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2144
|
+
(0, chai_1.expect)(subDataService.sparkLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
2145
|
+
});
|
|
2146
|
+
});
|
|
2147
|
+
});
|
|
2148
|
+
});
|
|
2149
|
+
describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
|
|
2150
|
+
describe('encode()', () => {
|
|
2151
|
+
const examples = [
|
|
2152
|
+
[
|
|
2153
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2154
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), enums_1.RatioState.UNDER, 150]
|
|
2155
|
+
],
|
|
2156
|
+
];
|
|
2157
|
+
examples.forEach(([expected, actual]) => {
|
|
2158
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
2159
|
+
(0, chai_1.expect)(subDataService.aaveV4LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
2160
|
+
});
|
|
2161
|
+
});
|
|
2162
|
+
});
|
|
2163
|
+
describe('decode()', () => {
|
|
2164
|
+
const examples = [
|
|
2165
|
+
[
|
|
2166
|
+
{
|
|
2167
|
+
spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2168
|
+
owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2169
|
+
ratioState: enums_1.RatioState.UNDER,
|
|
2170
|
+
targetRatio: 150,
|
|
2171
|
+
},
|
|
2172
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2173
|
+
],
|
|
2174
|
+
];
|
|
2175
|
+
examples.forEach(([expected, actual]) => {
|
|
2176
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2177
|
+
(0, chai_1.expect)(subDataService.aaveV4LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
2178
|
+
});
|
|
2179
|
+
});
|
|
2180
|
+
});
|
|
2181
|
+
});
|
|
2182
|
+
describe('When testing subDataService.aaveV4LeverageManagementOnPriceSubData', () => {
|
|
2183
|
+
describe('encode()', () => {
|
|
2184
|
+
const examples = [
|
|
2185
|
+
[
|
|
2186
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2187
|
+
[
|
|
2188
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2189
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
|
|
2190
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
|
|
2191
|
+
enums_1.RatioState.OVER, 160
|
|
2192
|
+
]
|
|
2193
|
+
],
|
|
2194
|
+
];
|
|
2195
|
+
examples.forEach(([expected, actual]) => {
|
|
2196
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
2197
|
+
(0, chai_1.expect)(subDataService.aaveV4LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
2198
|
+
});
|
|
2199
|
+
});
|
|
2200
|
+
});
|
|
2201
|
+
describe('decode()', () => {
|
|
2202
|
+
const examples = [
|
|
2203
|
+
[
|
|
2204
|
+
{
|
|
2205
|
+
spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2206
|
+
owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2207
|
+
collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2208
|
+
collAssetId: 10,
|
|
2209
|
+
debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2210
|
+
debtAssetId: 20,
|
|
2211
|
+
ratioState: enums_1.RatioState.OVER,
|
|
2212
|
+
targetRatio: 160,
|
|
2213
|
+
},
|
|
2214
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2215
|
+
],
|
|
2216
|
+
];
|
|
2217
|
+
examples.forEach(([expected, actual]) => {
|
|
2218
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2219
|
+
(0, chai_1.expect)(subDataService.aaveV4LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
|
|
2220
|
+
});
|
|
2221
|
+
});
|
|
2222
|
+
});
|
|
2223
|
+
});
|
|
2224
|
+
describe('When testing subDataService.aaveV4CloseSubData', () => {
|
|
2225
|
+
describe('encode()', () => {
|
|
2226
|
+
const examples = [
|
|
2227
|
+
[
|
|
2228
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2229
|
+
[
|
|
2230
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2231
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
|
|
2232
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
|
|
2233
|
+
enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL
|
|
2234
|
+
]
|
|
2235
|
+
],
|
|
2236
|
+
];
|
|
2237
|
+
examples.forEach(([expected, actual]) => {
|
|
2238
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
2239
|
+
(0, chai_1.expect)(subDataService.aaveV4CloseSubData.encode(...actual)).to.eql(expected);
|
|
2240
|
+
});
|
|
2241
|
+
});
|
|
2242
|
+
});
|
|
2243
|
+
describe('decode()', () => {
|
|
2244
|
+
const examples = [
|
|
2245
|
+
[
|
|
2246
|
+
{
|
|
2247
|
+
spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2248
|
+
owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2249
|
+
collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2250
|
+
collAssetId: 10,
|
|
2251
|
+
debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2252
|
+
debtAssetId: 20,
|
|
2253
|
+
closeType: enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
|
|
2254
|
+
},
|
|
2255
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2256
|
+
],
|
|
2257
|
+
];
|
|
2258
|
+
examples.forEach(([expected, actual]) => {
|
|
2259
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2260
|
+
(0, chai_1.expect)(subDataService.aaveV4CloseSubData.decode(actual)).to.eql(expected);
|
|
2261
|
+
});
|
|
2262
|
+
});
|
|
2263
|
+
});
|
|
2264
|
+
});
|
|
2265
|
+
describe('When testing subDataService.aaveV4CollateralSwitchSubData', () => {
|
|
2266
|
+
describe('encode()', () => {
|
|
2267
|
+
const examples = [
|
|
2268
|
+
[
|
|
2269
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2270
|
+
[
|
|
2271
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2272
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
|
|
2273
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
|
|
2274
|
+
'1000000000000000000'
|
|
2275
|
+
]
|
|
2276
|
+
],
|
|
2277
|
+
];
|
|
2278
|
+
examples.forEach(([expected, actual]) => {
|
|
2279
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
2280
|
+
(0, chai_1.expect)(subDataService.aaveV4CollateralSwitchSubData.encode(...actual)).to.eql(expected);
|
|
2281
|
+
});
|
|
2282
|
+
});
|
|
2283
|
+
});
|
|
2284
|
+
describe('decode()', () => {
|
|
2285
|
+
const examples = [
|
|
2286
|
+
[
|
|
2287
|
+
{
|
|
2288
|
+
spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
2289
|
+
owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
2290
|
+
fromAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
2291
|
+
fromAssetId: 10,
|
|
2292
|
+
toAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2293
|
+
toAssetId: 20,
|
|
2294
|
+
amountToSwitch: '1000000000000000000'
|
|
2295
|
+
},
|
|
2296
|
+
["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
|
|
2297
|
+
],
|
|
2298
|
+
];
|
|
2299
|
+
examples.forEach(([expected, actual]) => {
|
|
2300
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2301
|
+
(0, chai_1.expect)(subDataService.aaveV4CollateralSwitchSubData.decode(actual)).to.eql(expected);
|
|
2302
|
+
});
|
|
2303
|
+
});
|
|
2304
|
+
});
|
|
2305
|
+
});
|
|
2092
2306
|
});
|
|
@@ -285,3 +285,41 @@ export declare const morphoBluePriceRangeTrigger: {
|
|
|
285
285
|
upperPrice: string;
|
|
286
286
|
};
|
|
287
287
|
};
|
|
288
|
+
export declare const sparkQuotePriceTrigger: {
|
|
289
|
+
encode(baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState): string[];
|
|
290
|
+
decode(triggerData: string[]): {
|
|
291
|
+
baseTokenAddr: string;
|
|
292
|
+
quoteTokenAddr: string;
|
|
293
|
+
price: string;
|
|
294
|
+
ratioState: number;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
export declare const aaveV4RatioTrigger: {
|
|
298
|
+
encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
|
|
299
|
+
decode(triggerData: string[]): {
|
|
300
|
+
owner: string;
|
|
301
|
+
spoke: string;
|
|
302
|
+
ratio: number;
|
|
303
|
+
ratioState: number;
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
export declare const aaveV4QuotePriceTrigger: {
|
|
307
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState): string[];
|
|
308
|
+
decode(triggerData: string[]): {
|
|
309
|
+
spoke: string;
|
|
310
|
+
baseTokenId: number;
|
|
311
|
+
quoteTokenId: number;
|
|
312
|
+
price: string;
|
|
313
|
+
ratioState: number;
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
export declare const aaveV4QuotePriceRangeTrigger: {
|
|
317
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string): string[];
|
|
318
|
+
decode(triggerData: string[]): {
|
|
319
|
+
spoke: string;
|
|
320
|
+
baseTokenId: number;
|
|
321
|
+
quoteTokenId: number;
|
|
322
|
+
lowerPrice: string;
|
|
323
|
+
upperPrice: string;
|
|
324
|
+
};
|
|
325
|
+
};
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.morphoBluePriceRangeTrigger = exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
29
|
+
exports.aaveV4QuotePriceRangeTrigger = exports.aaveV4QuotePriceTrigger = exports.aaveV4RatioTrigger = exports.sparkQuotePriceTrigger = exports.morphoBluePriceRangeTrigger = exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -547,3 +547,70 @@ exports.morphoBluePriceRangeTrigger = {
|
|
|
547
547
|
};
|
|
548
548
|
},
|
|
549
549
|
};
|
|
550
|
+
exports.sparkQuotePriceTrigger = {
|
|
551
|
+
encode(baseTokenAddr, quoteTokenAddr, price, ratioState) {
|
|
552
|
+
const _price = new decimal_js_1.default(price.toString()).mul(1e8).floor().toString();
|
|
553
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddr, quoteTokenAddr, _price, ratioState])];
|
|
554
|
+
},
|
|
555
|
+
decode(triggerData) {
|
|
556
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
557
|
+
return {
|
|
558
|
+
baseTokenAddr: decodedData[0],
|
|
559
|
+
quoteTokenAddr: decodedData[1],
|
|
560
|
+
price: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
|
|
561
|
+
ratioState: Number(decodedData[3]),
|
|
562
|
+
};
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
exports.aaveV4RatioTrigger = {
|
|
566
|
+
encode(owner, spoke, ratioPercentage, ratioState) {
|
|
567
|
+
const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
|
|
568
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, spoke, ratioWei, ratioState])];
|
|
569
|
+
},
|
|
570
|
+
decode(triggerData) {
|
|
571
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
572
|
+
return {
|
|
573
|
+
owner: decodedData[0],
|
|
574
|
+
spoke: decodedData[1],
|
|
575
|
+
ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
|
|
576
|
+
ratioState: Number(decodedData[3]),
|
|
577
|
+
};
|
|
578
|
+
},
|
|
579
|
+
};
|
|
580
|
+
exports.aaveV4QuotePriceTrigger = {
|
|
581
|
+
encode(spoke, baseTokenId, quoteTokenId, price, ratioState) {
|
|
582
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
583
|
+
const _price = new decimal_js_1.default(price).mul(1e18).floor().toString();
|
|
584
|
+
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
|
|
585
|
+
},
|
|
586
|
+
decode(triggerData) {
|
|
587
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
588
|
+
return {
|
|
589
|
+
spoke: decodedData[0],
|
|
590
|
+
baseTokenId: Number(decodedData[1]),
|
|
591
|
+
quoteTokenId: Number(decodedData[2]),
|
|
592
|
+
price: new decimal_js_1.default(decodedData[3]).div(1e18).toString(),
|
|
593
|
+
ratioState: Number(decodedData[4]),
|
|
594
|
+
};
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
exports.aaveV4QuotePriceRangeTrigger = {
|
|
598
|
+
encode(spoke, baseTokenId, quoteTokenId, lowerPrice, upperPrice) {
|
|
599
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
600
|
+
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e18).floor().toString();
|
|
601
|
+
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e18).floor().toString();
|
|
602
|
+
return [
|
|
603
|
+
web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
|
|
604
|
+
];
|
|
605
|
+
},
|
|
606
|
+
decode(triggerData) {
|
|
607
|
+
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], triggerData[0]);
|
|
608
|
+
return {
|
|
609
|
+
spoke: decodedData[0],
|
|
610
|
+
baseTokenId: Number(decodedData[1]),
|
|
611
|
+
quoteTokenId: Number(decodedData[2]),
|
|
612
|
+
lowerPrice: new decimal_js_1.default(decodedData[3]).div(1e18).toString(),
|
|
613
|
+
upperPrice: new decimal_js_1.default(decodedData[4]).div(1e18).toString(),
|
|
614
|
+
};
|
|
615
|
+
},
|
|
616
|
+
};
|
|
@@ -1184,4 +1184,134 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1184
1184
|
});
|
|
1185
1185
|
});
|
|
1186
1186
|
});
|
|
1187
|
+
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1188
|
+
describe('encode()', () => {
|
|
1189
|
+
const examples = [
|
|
1190
|
+
[
|
|
1191
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1192
|
+
[web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 120, enums_1.RatioState.UNDER]
|
|
1193
|
+
],
|
|
1194
|
+
];
|
|
1195
|
+
examples.forEach(([expected, actual]) => {
|
|
1196
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1197
|
+
(0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.encode(...actual)).to.eql(expected);
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
});
|
|
1201
|
+
describe('decode()', () => {
|
|
1202
|
+
const examples = [
|
|
1203
|
+
[
|
|
1204
|
+
{ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), ratio: 120, ratioState: enums_1.RatioState.UNDER },
|
|
1205
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1206
|
+
],
|
|
1207
|
+
];
|
|
1208
|
+
examples.forEach(([expected, actual]) => {
|
|
1209
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1210
|
+
(0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.decode(actual)).to.eql(expected);
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
|
|
1216
|
+
describe('encode()', () => {
|
|
1217
|
+
const examples = [
|
|
1218
|
+
[
|
|
1219
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1220
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', enums_1.RatioState.OVER]
|
|
1221
|
+
],
|
|
1222
|
+
];
|
|
1223
|
+
examples.forEach(([expected, actual]) => {
|
|
1224
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1225
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1226
|
+
});
|
|
1227
|
+
});
|
|
1228
|
+
});
|
|
1229
|
+
describe('decode()', () => {
|
|
1230
|
+
const examples = [
|
|
1231
|
+
[
|
|
1232
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: enums_1.RatioState.OVER },
|
|
1233
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1234
|
+
],
|
|
1235
|
+
];
|
|
1236
|
+
examples.forEach(([expected, actual]) => {
|
|
1237
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1238
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1239
|
+
});
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
|
|
1244
|
+
describe('encode()', () => {
|
|
1245
|
+
const examples = [
|
|
1246
|
+
[
|
|
1247
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1248
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1249
|
+
],
|
|
1250
|
+
];
|
|
1251
|
+
examples.forEach(([expected, actual]) => {
|
|
1252
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1253
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
describe('decode()', () => {
|
|
1258
|
+
const examples = [
|
|
1259
|
+
[
|
|
1260
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1261
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1262
|
+
],
|
|
1263
|
+
];
|
|
1264
|
+
examples.forEach(([expected, actual]) => {
|
|
1265
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1266
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1267
|
+
});
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
1272
|
+
describe('encode()', () => {
|
|
1273
|
+
const examples = [
|
|
1274
|
+
[
|
|
1275
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1276
|
+
[web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address), web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address), 2500, enums_1.RatioState.UNDER]
|
|
1277
|
+
],
|
|
1278
|
+
[
|
|
1279
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
|
|
1280
|
+
[web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address), web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address), 0.000031, enums_1.RatioState.OVER]
|
|
1281
|
+
],
|
|
1282
|
+
];
|
|
1283
|
+
examples.forEach(([expected, actual]) => {
|
|
1284
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1285
|
+
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1286
|
+
});
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
describe('decode()', () => {
|
|
1290
|
+
const examples = [
|
|
1291
|
+
[
|
|
1292
|
+
{
|
|
1293
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1294
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1295
|
+
price: '2500',
|
|
1296
|
+
ratioState: enums_1.RatioState.UNDER
|
|
1297
|
+
},
|
|
1298
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
|
|
1299
|
+
],
|
|
1300
|
+
[
|
|
1301
|
+
{
|
|
1302
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address),
|
|
1303
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1304
|
+
price: '0.000031',
|
|
1305
|
+
ratioState: enums_1.RatioState.OVER
|
|
1306
|
+
},
|
|
1307
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
|
|
1308
|
+
]
|
|
1309
|
+
];
|
|
1310
|
+
examples.forEach(([expected, actual]) => {
|
|
1311
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1312
|
+
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
1187
1317
|
});
|
package/cjs/services/utils.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function getRatioStateInfoForAaveCloseStrategy(currentRatioState:
|
|
|
23
23
|
ratioState: RatioState;
|
|
24
24
|
};
|
|
25
25
|
export declare function getPositionId(...args: (number | string)[]): string;
|
|
26
|
-
export declare function getCloseStrategyType(stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
26
|
+
export declare function getCloseStrategyType(stopLossPrice: number | string, stopLossType: CloseToAssetType, takeProfitPrice: number | string, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
27
27
|
export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType: CloseStrategyType): {
|
|
28
28
|
stopLossType: CloseToAssetType | undefined;
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
package/cjs/services/utils.js
CHANGED
|
@@ -130,8 +130,16 @@ function getPositionId(...args) {
|
|
|
130
130
|
}
|
|
131
131
|
exports.getPositionId = getPositionId;
|
|
132
132
|
function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
133
|
+
const stopLossPriceDec = new decimal_js_1.default(stopLossPrice);
|
|
134
|
+
const takeProfitPriceDec = new decimal_js_1.default(takeProfitPrice);
|
|
135
|
+
if (!stopLossPriceDec.isFinite() || stopLossPriceDec.isNegative()) {
|
|
136
|
+
throw new Error('CloseOnPrice: stopLossPrice must be a finite non-negative number');
|
|
137
|
+
}
|
|
138
|
+
if (!takeProfitPriceDec.isFinite() || takeProfitPriceDec.isNegative()) {
|
|
139
|
+
throw new Error('CloseOnPrice: takeProfitPrice must be a finite non-negative number');
|
|
140
|
+
}
|
|
141
|
+
const isStopLoss = stopLossPriceDec.gt(0);
|
|
142
|
+
const isTakeProfit = takeProfitPriceDec.gt(0);
|
|
135
143
|
if (!isStopLoss && !isTakeProfit) {
|
|
136
144
|
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
137
145
|
}
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export declare namespace ProtocolIdentifiers {
|
|
|
56
56
|
CompoundV3 = "Compound__V3",
|
|
57
57
|
AaveV2 = "Aave__V2",
|
|
58
58
|
AaveV3 = "Aave__V3",
|
|
59
|
+
AaveV4 = "Aave__V4",
|
|
59
60
|
MorphoAaveV2 = "Morpho-Aave__V2",
|
|
60
61
|
Exchange = "Exchange",
|
|
61
62
|
Spark = "Spark",
|
|
@@ -86,7 +87,9 @@ export declare namespace Strategies {
|
|
|
86
87
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
87
88
|
CURVEUSD_PAYBACK = 92,
|
|
88
89
|
LIQUITY_V2_PAYBACK = 113,
|
|
89
|
-
AAVE_V3_COLLATERAL_SWITCH = 135
|
|
90
|
+
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
91
|
+
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155
|
|
90
93
|
}
|
|
91
94
|
enum OptimismIds {
|
|
92
95
|
EXCHANGE_DCA = 8,
|
|
@@ -133,7 +136,8 @@ export declare namespace Strategies {
|
|
|
133
136
|
RepayOnPrice = "repay-on-price",
|
|
134
137
|
EoaBoostOnPrice = "eoa-boost-on-price",
|
|
135
138
|
EoaRepayOnPrice = "eoa-repay-on-price",
|
|
136
|
-
CollateralSwitch = "collateral-switch"
|
|
139
|
+
CollateralSwitch = "collateral-switch",
|
|
140
|
+
EoaCollateralSwitch = "eoa-collateral-switch"
|
|
137
141
|
}
|
|
138
142
|
enum IdOverrides {
|
|
139
143
|
TakeProfit = "take-profit",
|
|
@@ -207,7 +211,19 @@ export declare namespace Bundles {
|
|
|
207
211
|
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
208
212
|
AAVE_V3_EOA_CLOSE = 56,
|
|
209
213
|
SPARK_CLOSE = 57,
|
|
210
|
-
MORPHO_BLUE_CLOSE = 58
|
|
214
|
+
MORPHO_BLUE_CLOSE = 58,
|
|
215
|
+
SPARK_REPAY_ON_PRICE = 59,
|
|
216
|
+
SPARK_BOOST_ON_PRICE = 60,
|
|
217
|
+
AAVE_V4_REPAY = 61,
|
|
218
|
+
AAVE_V4_BOOST = 62,
|
|
219
|
+
AAVE_V4_REPAY_ON_PRICE = 63,
|
|
220
|
+
AAVE_V4_BOOST_ON_PRICE = 64,
|
|
221
|
+
AAVE_V4_CLOSE = 65,
|
|
222
|
+
AAVE_V4_EOA_REPAY = 66,
|
|
223
|
+
AAVE_V4_EOA_BOOST = 67,
|
|
224
|
+
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
225
|
+
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
226
|
+
AAVE_V4_EOA_CLOSE = 70
|
|
211
227
|
}
|
|
212
228
|
enum OptimismIds {
|
|
213
229
|
AAVE_V3_REPAY = 0,
|
package/cjs/types/enums.js
CHANGED
|
@@ -69,6 +69,7 @@ var ProtocolIdentifiers;
|
|
|
69
69
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
70
70
|
StrategiesAutomation["AaveV2"] = "Aave__V2";
|
|
71
71
|
StrategiesAutomation["AaveV3"] = "Aave__V3";
|
|
72
|
+
StrategiesAutomation["AaveV4"] = "Aave__V4";
|
|
72
73
|
StrategiesAutomation["MorphoAaveV2"] = "Morpho-Aave__V2";
|
|
73
74
|
StrategiesAutomation["Exchange"] = "Exchange";
|
|
74
75
|
StrategiesAutomation["Spark"] = "Spark";
|
|
@@ -103,6 +104,8 @@ var Strategies;
|
|
|
103
104
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
104
105
|
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
105
106
|
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
107
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
|
|
108
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
106
109
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
107
110
|
let OptimismIds;
|
|
108
111
|
(function (OptimismIds) {
|
|
@@ -154,6 +157,7 @@ var Strategies;
|
|
|
154
157
|
Identifiers["EoaBoostOnPrice"] = "eoa-boost-on-price";
|
|
155
158
|
Identifiers["EoaRepayOnPrice"] = "eoa-repay-on-price";
|
|
156
159
|
Identifiers["CollateralSwitch"] = "collateral-switch";
|
|
160
|
+
Identifiers["EoaCollateralSwitch"] = "eoa-collateral-switch";
|
|
157
161
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
158
162
|
let IdOverrides;
|
|
159
163
|
(function (IdOverrides) {
|
|
@@ -231,6 +235,18 @@ var Bundles;
|
|
|
231
235
|
MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
|
|
232
236
|
MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
|
|
233
237
|
MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
|
|
238
|
+
MainnetIds[MainnetIds["SPARK_REPAY_ON_PRICE"] = 59] = "SPARK_REPAY_ON_PRICE";
|
|
239
|
+
MainnetIds[MainnetIds["SPARK_BOOST_ON_PRICE"] = 60] = "SPARK_BOOST_ON_PRICE";
|
|
240
|
+
MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 61] = "AAVE_V4_REPAY";
|
|
241
|
+
MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 62] = "AAVE_V4_BOOST";
|
|
242
|
+
MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 63] = "AAVE_V4_REPAY_ON_PRICE";
|
|
243
|
+
MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 64] = "AAVE_V4_BOOST_ON_PRICE";
|
|
244
|
+
MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 65] = "AAVE_V4_CLOSE";
|
|
245
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 66] = "AAVE_V4_EOA_REPAY";
|
|
246
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 67] = "AAVE_V4_EOA_BOOST";
|
|
247
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 68] = "AAVE_V4_EOA_REPAY_ON_PRICE";
|
|
248
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 69] = "AAVE_V4_EOA_BOOST_ON_PRICE";
|
|
249
|
+
MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 70] = "AAVE_V4_EOA_CLOSE";
|
|
234
250
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
235
251
|
let OptimismIds;
|
|
236
252
|
(function (OptimismIds) {
|