@defisaver/automation-sdk 3.3.6 → 3.3.7-morpho-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/constants/index.js +20 -10
- package/cjs/services/strategiesService.js +41 -14
- package/cjs/services/strategySubService.d.ts +2 -11
- package/cjs/services/strategySubService.js +12 -5
- package/cjs/services/strategySubService.test.js +38 -72
- package/cjs/services/subDataService.d.ts +24 -9
- package/cjs/services/subDataService.js +63 -20
- package/cjs/services/subDataService.test.js +52 -72
- package/cjs/services/triggerService.d.ts +19 -9
- package/cjs/services/triggerService.js +40 -19
- package/cjs/services/triggerService.test.js +48 -46
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +7 -5
- package/cjs/types/enums.js +4 -2
- package/esm/constants/index.js +20 -10
- package/esm/services/strategiesService.js +41 -14
- package/esm/services/strategySubService.d.ts +2 -11
- package/esm/services/strategySubService.js +12 -5
- package/esm/services/strategySubService.test.js +39 -73
- package/esm/services/subDataService.d.ts +24 -9
- package/esm/services/subDataService.js +62 -19
- package/esm/services/subDataService.test.js +52 -72
- package/esm/services/triggerService.d.ts +19 -9
- package/esm/services/triggerService.js +39 -18
- package/esm/services/triggerService.test.js +49 -47
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +7 -5
- package/esm/types/enums.js +4 -2
- package/package.json +1 -1
- package/src/constants/index.ts +20 -12
- package/src/services/strategiesService.ts +55 -22
- package/src/services/strategySubService.test.ts +59 -94
- package/src/services/strategySubService.ts +36 -16
- package/src/services/subDataService.test.ts +60 -78
- package/src/services/subDataService.ts +92 -31
- package/src/services/triggerService.test.ts +53 -51
- package/src/services/triggerService.ts +61 -26
- package/src/services/utils.test.ts +0 -59
- package/src/types/enums.ts +4 -2
|
@@ -4,12 +4,11 @@ import { getAssetInfo } from '@defisaver/tokens';
|
|
|
4
4
|
import * as web3Utils from 'web3-utils';
|
|
5
5
|
import { MAXUINT } from '@defisaver/tokens';
|
|
6
6
|
|
|
7
|
-
import { ChainId, CloseStrategyType,
|
|
7
|
+
import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
|
|
8
8
|
import type { EthereumAddress, SubData } from '../types';
|
|
9
9
|
|
|
10
10
|
import '../configuration';
|
|
11
11
|
import * as subDataService from './subDataService';
|
|
12
|
-
import { AAVE_V3_VARIABLE_BORROW_RATE } from '../constants';
|
|
13
12
|
|
|
14
13
|
describe('Feature: subDataService.ts', () => {
|
|
15
14
|
|
|
@@ -941,82 +940,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
941
940
|
});
|
|
942
941
|
});
|
|
943
942
|
|
|
944
|
-
describe('When testing subDataService.sparkQuotePriceSubData', () => {
|
|
945
|
-
describe('encode()', () => {
|
|
946
|
-
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
|
|
947
|
-
[
|
|
948
|
-
[
|
|
949
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
950
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
951
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
952
|
-
],
|
|
953
|
-
[
|
|
954
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
955
|
-
2,
|
|
956
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
957
|
-
4,
|
|
958
|
-
]
|
|
959
|
-
],
|
|
960
|
-
[
|
|
961
|
-
[
|
|
962
|
-
'0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
963
|
-
'0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
964
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
965
|
-
],
|
|
966
|
-
[
|
|
967
|
-
web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
|
|
968
|
-
6,
|
|
969
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
970
|
-
2,
|
|
971
|
-
]
|
|
972
|
-
],
|
|
973
|
-
];
|
|
974
|
-
|
|
975
|
-
examples.forEach(([expected, actual]) => {
|
|
976
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
977
|
-
expect(subDataService.sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
|
|
978
|
-
});
|
|
979
|
-
});
|
|
980
|
-
});
|
|
981
|
-
|
|
982
|
-
describe('decode()', () => {
|
|
983
|
-
const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
|
|
984
|
-
[
|
|
985
|
-
{
|
|
986
|
-
collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
987
|
-
collAssetId: 2,
|
|
988
|
-
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
989
|
-
debtAssetId: 4,
|
|
990
|
-
},
|
|
991
|
-
[
|
|
992
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
993
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
|
|
994
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
995
|
-
],
|
|
996
|
-
],
|
|
997
|
-
[
|
|
998
|
-
{
|
|
999
|
-
collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
|
|
1000
|
-
collAssetId: 6,
|
|
1001
|
-
debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
1002
|
-
debtAssetId: 2,
|
|
1003
|
-
},
|
|
1004
|
-
[
|
|
1005
|
-
'0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1006
|
-
'0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1007
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1008
|
-
],
|
|
1009
|
-
],
|
|
1010
|
-
];
|
|
1011
|
-
|
|
1012
|
-
examples.forEach(([expected, actual]) => {
|
|
1013
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1014
|
-
expect(subDataService.sparkQuotePriceSubData.decode(actual)).to.eql(expected);
|
|
1015
|
-
});
|
|
1016
|
-
});
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
943
|
describe('When testing subDataService.liquityDsrPaybackSubData', () => {
|
|
1021
944
|
describe('encode()', () => {
|
|
1022
945
|
const examples: Array<[SubData, [targetRatio: number]]> = [
|
|
@@ -1445,6 +1368,65 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1445
1368
|
});
|
|
1446
1369
|
});
|
|
1447
1370
|
|
|
1371
|
+
describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
|
|
1372
|
+
describe('encode()', () => {
|
|
1373
|
+
const examples: Array<[
|
|
1374
|
+
SubData,
|
|
1375
|
+
[loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType],
|
|
1376
|
+
]> = [
|
|
1377
|
+
[
|
|
1378
|
+
[
|
|
1379
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1380
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1381
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1382
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1383
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1384
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1385
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1386
|
+
],
|
|
1387
|
+
[web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
|
|
1388
|
+
],
|
|
1389
|
+
];
|
|
1390
|
+
|
|
1391
|
+
examples.forEach(([expected, actual]) => {
|
|
1392
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1393
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
describe('decode()', () => {
|
|
1399
|
+
const examples: Array<[{ loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType }, SubData]> = [
|
|
1400
|
+
[
|
|
1401
|
+
{
|
|
1402
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1403
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1404
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1405
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1406
|
+
lltv: '945000000000000000',
|
|
1407
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1408
|
+
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1409
|
+
},
|
|
1410
|
+
[
|
|
1411
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1412
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1413
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1414
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1415
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1416
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1417
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1418
|
+
],
|
|
1419
|
+
],
|
|
1420
|
+
];
|
|
1421
|
+
|
|
1422
|
+
examples.forEach(([expected, actual]) => {
|
|
1423
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1424
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1448
1430
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1449
1431
|
describe('encode()', () => {
|
|
1450
1432
|
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]]> = [
|
|
@@ -593,37 +593,6 @@ export const sparkLeverageManagementSubData = { // TODO encode?
|
|
|
593
593
|
},
|
|
594
594
|
};
|
|
595
595
|
|
|
596
|
-
export const sparkQuotePriceSubData = {
|
|
597
|
-
encode(
|
|
598
|
-
collAsset: EthereumAddress,
|
|
599
|
-
collAssetId: number,
|
|
600
|
-
debtAsset: EthereumAddress,
|
|
601
|
-
debtAssetId: number,
|
|
602
|
-
nullAddress: EthereumAddress = ZERO_ADDRESS,
|
|
603
|
-
): SubData {
|
|
604
|
-
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
605
|
-
const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
|
|
606
|
-
|
|
607
|
-
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
608
|
-
const encodedDebtId = AbiCoder.encodeParameter('uint8', debtAssetId);
|
|
609
|
-
|
|
610
|
-
const encodedNullAddress = AbiCoder.encodeParameter('address', nullAddress);
|
|
611
|
-
|
|
612
|
-
return [encodedColl, encodedCollId, encodedDebt, encodedDebtId, encodedNullAddress];
|
|
613
|
-
},
|
|
614
|
-
decode(subData: SubData): { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number } {
|
|
615
|
-
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
616
|
-
const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
617
|
-
|
|
618
|
-
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
619
|
-
const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
620
|
-
|
|
621
|
-
return {
|
|
622
|
-
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
623
|
-
};
|
|
624
|
-
},
|
|
625
|
-
};
|
|
626
|
-
|
|
627
596
|
export const liquityDsrPaybackSubData = {
|
|
628
597
|
encode: (targetRatio: number) => {
|
|
629
598
|
const daiAddress = getAssetInfo('DAI').address;
|
|
@@ -1191,3 +1160,95 @@ export const compoundV3CloseSubData = {
|
|
|
1191
1160
|
};
|
|
1192
1161
|
},
|
|
1193
1162
|
};
|
|
1163
|
+
|
|
1164
|
+
export const sparkCloseGenericSubData = {
|
|
1165
|
+
encode(
|
|
1166
|
+
collAsset: EthereumAddress,
|
|
1167
|
+
collAssetId: number,
|
|
1168
|
+
debtAsset: EthereumAddress,
|
|
1169
|
+
debtAssetId: number,
|
|
1170
|
+
closeType: CloseStrategyType,
|
|
1171
|
+
marketAddr: EthereumAddress,
|
|
1172
|
+
user: EthereumAddress,
|
|
1173
|
+
): SubData {
|
|
1174
|
+
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
1175
|
+
const encodedCollId = AbiCoder.encodeParameter('uint8', collAssetId);
|
|
1176
|
+
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
1177
|
+
const encodedDebtId = AbiCoder.encodeParameter('uint8', debtAssetId);
|
|
1178
|
+
const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
|
|
1179
|
+
const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
|
|
1180
|
+
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1181
|
+
|
|
1182
|
+
return [
|
|
1183
|
+
encodedColl,
|
|
1184
|
+
encodedCollId,
|
|
1185
|
+
encodedDebt,
|
|
1186
|
+
encodedDebtId,
|
|
1187
|
+
encodedCloseType,
|
|
1188
|
+
encodedMarket,
|
|
1189
|
+
userEncoded,
|
|
1190
|
+
];
|
|
1191
|
+
},
|
|
1192
|
+
|
|
1193
|
+
decode(subData: SubData): {
|
|
1194
|
+
collAsset: EthereumAddress,
|
|
1195
|
+
collAssetId: number,
|
|
1196
|
+
debtAsset: EthereumAddress,
|
|
1197
|
+
debtAssetId: number,
|
|
1198
|
+
closeType: CloseStrategyType,
|
|
1199
|
+
marketAddr: EthereumAddress,
|
|
1200
|
+
owner: EthereumAddress,
|
|
1201
|
+
} {
|
|
1202
|
+
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1203
|
+
const collAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
|
|
1204
|
+
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
1205
|
+
const debtAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
|
|
1206
|
+
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
|
|
1207
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
|
|
1208
|
+
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
1209
|
+
|
|
1210
|
+
return {
|
|
1211
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner,
|
|
1212
|
+
};
|
|
1213
|
+
},
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
export const morphoBlueCloseOnPriceSubData = {
|
|
1217
|
+
encode(
|
|
1218
|
+
loanToken: EthereumAddress,
|
|
1219
|
+
collToken: EthereumAddress,
|
|
1220
|
+
oracle: EthereumAddress,
|
|
1221
|
+
irm: EthereumAddress,
|
|
1222
|
+
lltv: string,
|
|
1223
|
+
user: EthereumAddress,
|
|
1224
|
+
closeType: CloseStrategyType,
|
|
1225
|
+
): SubData {
|
|
1226
|
+
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
1227
|
+
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
1228
|
+
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
1229
|
+
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
1230
|
+
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
1231
|
+
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1232
|
+
const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
|
|
1233
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
|
|
1234
|
+
},
|
|
1235
|
+
decode(subData: SubData) {
|
|
1236
|
+
const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1237
|
+
const collToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
1238
|
+
const oracle = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
1239
|
+
const irm = AbiCoder.decodeParameter('address', subData[3]) as any as EthereumAddress;
|
|
1240
|
+
const lltv = AbiCoder.decodeParameter('uint256', subData[4]) as any as EthereumAddress;
|
|
1241
|
+
const user = AbiCoder.decodeParameter('address', subData[5]) as any as EthereumAddress;
|
|
1242
|
+
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[6])) as CloseStrategyType;
|
|
1243
|
+
|
|
1244
|
+
return {
|
|
1245
|
+
loanToken,
|
|
1246
|
+
collToken,
|
|
1247
|
+
oracle,
|
|
1248
|
+
irm,
|
|
1249
|
+
lltv,
|
|
1250
|
+
user,
|
|
1251
|
+
closeType,
|
|
1252
|
+
};
|
|
1253
|
+
},
|
|
1254
|
+
};
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
liquityDebtInFrontTrigger,
|
|
24
24
|
makerRatioTrigger,
|
|
25
25
|
morphoAaveV2RatioTrigger,
|
|
26
|
-
sparkQuotePriceTrigger,
|
|
27
26
|
sparkRatioTrigger,
|
|
28
27
|
trailingStopTrigger,
|
|
29
28
|
liquityDebtInFrontWithLimitTrigger,
|
|
@@ -32,6 +31,7 @@ import {
|
|
|
32
31
|
crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger,
|
|
33
32
|
compoundV3PriceRangeTrigger,
|
|
34
33
|
aaveV3QuotePriceRangeTrigger,
|
|
34
|
+
morphoBluePriceRangeTrigger,
|
|
35
35
|
} from './triggerService';
|
|
36
36
|
|
|
37
37
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -879,56 +879,6 @@ describe('Feature: triggerService.ts', () => {
|
|
|
879
879
|
});
|
|
880
880
|
});
|
|
881
881
|
|
|
882
|
-
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
883
|
-
describe('encode()', () => {
|
|
884
|
-
const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
|
|
885
|
-
[
|
|
886
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
887
|
-
[getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
|
|
888
|
-
],
|
|
889
|
-
[
|
|
890
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
891
|
-
[getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
|
|
892
|
-
],
|
|
893
|
-
];
|
|
894
|
-
|
|
895
|
-
examples.forEach(([expected, actual]) => {
|
|
896
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
897
|
-
expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
898
|
-
});
|
|
899
|
-
});
|
|
900
|
-
});
|
|
901
|
-
|
|
902
|
-
describe('decode()', () => {
|
|
903
|
-
const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
|
|
904
|
-
[
|
|
905
|
-
{
|
|
906
|
-
baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
907
|
-
quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
|
|
908
|
-
price: '0.0004321',
|
|
909
|
-
ratioState: RatioState.UNDER,
|
|
910
|
-
},
|
|
911
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
912
|
-
],
|
|
913
|
-
[
|
|
914
|
-
{
|
|
915
|
-
baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
|
|
916
|
-
quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
|
|
917
|
-
price: '0.00100023',
|
|
918
|
-
ratioState: RatioState.OVER,
|
|
919
|
-
},
|
|
920
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
921
|
-
]
|
|
922
|
-
];
|
|
923
|
-
|
|
924
|
-
examples.forEach(([expected, actual]) => {
|
|
925
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
926
|
-
expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
927
|
-
});
|
|
928
|
-
});
|
|
929
|
-
});
|
|
930
|
-
});
|
|
931
|
-
|
|
932
882
|
describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
|
|
933
883
|
describe('encode()', () => {
|
|
934
884
|
const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
|
|
@@ -1281,4 +1231,56 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1281
1231
|
});
|
|
1282
1232
|
});
|
|
1283
1233
|
});
|
|
1234
|
+
|
|
1235
|
+
describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
|
|
1236
|
+
describe('encode()', () => {
|
|
1237
|
+
const examples: Array<[[string], [oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: number, upperPrice: number]]> = [
|
|
1238
|
+
[
|
|
1239
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1240
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1241
|
+
],
|
|
1242
|
+
[
|
|
1243
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1244
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1245
|
+
],
|
|
1246
|
+
];
|
|
1247
|
+
|
|
1248
|
+
examples.forEach(([expected, actual]) => {
|
|
1249
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1250
|
+
expect(morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1251
|
+
});
|
|
1252
|
+
});
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
describe('decode()', () => {
|
|
1256
|
+
const examples: Array<[{ oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: string, upperPrice: string }, TriggerData]> = [
|
|
1257
|
+
[
|
|
1258
|
+
{
|
|
1259
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1260
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1261
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1262
|
+
lowerPrice: '1500',
|
|
1263
|
+
upperPrice: '4000',
|
|
1264
|
+
},
|
|
1265
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1266
|
+
],
|
|
1267
|
+
[
|
|
1268
|
+
{
|
|
1269
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1270
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1271
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1272
|
+
lowerPrice: '0',
|
|
1273
|
+
upperPrice: '5000',
|
|
1274
|
+
},
|
|
1275
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1276
|
+
],
|
|
1277
|
+
];
|
|
1278
|
+
|
|
1279
|
+
examples.forEach(([expected, actual]) => {
|
|
1280
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1281
|
+
expect(morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
});
|
|
1285
|
+
});
|
|
1284
1286
|
});
|
|
@@ -328,32 +328,6 @@ export const sparkRatioTrigger = {
|
|
|
328
328
|
},
|
|
329
329
|
};
|
|
330
330
|
|
|
331
|
-
export const sparkQuotePriceTrigger = {
|
|
332
|
-
encode(
|
|
333
|
-
baseTokenAddress: EthereumAddress,
|
|
334
|
-
quoteTokenAddress: EthereumAddress,
|
|
335
|
-
price: number,
|
|
336
|
-
ratioState: RatioState,
|
|
337
|
-
) {
|
|
338
|
-
// Price is always in 8 decimals
|
|
339
|
-
const _price = new Dec(price.toString()).mul(10 ** 8).floor().toString();
|
|
340
|
-
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
|
|
341
|
-
},
|
|
342
|
-
decode(
|
|
343
|
-
triggerData: TriggerData,
|
|
344
|
-
): { baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState } {
|
|
345
|
-
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
346
|
-
// Price is always in 8 decimals
|
|
347
|
-
const price = new Dec(decodedData[2] as string).div(10 ** 8).toDP(8).toString();
|
|
348
|
-
return {
|
|
349
|
-
price,
|
|
350
|
-
baseTokenAddress: decodedData[0] as EthereumAddress,
|
|
351
|
-
quoteTokenAddress: decodedData[1] as EthereumAddress,
|
|
352
|
-
ratioState: +decodedData[3]!,
|
|
353
|
-
};
|
|
354
|
-
},
|
|
355
|
-
};
|
|
356
|
-
|
|
357
331
|
export const curveUsdBorrowRateTrigger = {
|
|
358
332
|
encode(
|
|
359
333
|
market: EthereumAddress,
|
|
@@ -685,4 +659,65 @@ export const aaveV3QuotePriceRangeTrigger = {
|
|
|
685
659
|
upperPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
|
|
686
660
|
};
|
|
687
661
|
},
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
export const sparkQuotePriceRangeTrigger = {
|
|
665
|
+
encode(
|
|
666
|
+
collToken: EthereumAddress,
|
|
667
|
+
debtToken: EthereumAddress,
|
|
668
|
+
lowerPrice: number,
|
|
669
|
+
upperPrice: number,
|
|
670
|
+
) {
|
|
671
|
+
// Price is scaled to 1e8
|
|
672
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
673
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
674
|
+
return [
|
|
675
|
+
AbiCoder.encodeParameters(
|
|
676
|
+
['address', 'address', 'uint256', 'uint256'],
|
|
677
|
+
[collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
|
|
678
|
+
];
|
|
679
|
+
},
|
|
680
|
+
decode(
|
|
681
|
+
triggerData: TriggerData,
|
|
682
|
+
) {
|
|
683
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
684
|
+
return {
|
|
685
|
+
collToken: decodedData[0] as EthereumAddress,
|
|
686
|
+
debtToken: decodedData[1] as EthereumAddress,
|
|
687
|
+
lowerPrice: new Dec(decodedData[2] as string).div(1e8).toString(),
|
|
688
|
+
upperPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
|
|
689
|
+
};
|
|
690
|
+
},
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
export const morphoBluePriceRangeTrigger = {
|
|
694
|
+
encode(
|
|
695
|
+
oracle: EthereumAddress,
|
|
696
|
+
collateralToken: EthereumAddress,
|
|
697
|
+
loanToken: EthereumAddress,
|
|
698
|
+
lowerPrice: number,
|
|
699
|
+
upperPrice: number,
|
|
700
|
+
) {
|
|
701
|
+
// Price is scaled to 1e8
|
|
702
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
703
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
704
|
+
return [
|
|
705
|
+
AbiCoder.encodeParameters(
|
|
706
|
+
['address', 'address', 'address', 'uint256', 'uint256'],
|
|
707
|
+
[oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted],
|
|
708
|
+
),
|
|
709
|
+
];
|
|
710
|
+
},
|
|
711
|
+
decode(
|
|
712
|
+
triggerData: TriggerData,
|
|
713
|
+
) {
|
|
714
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
715
|
+
return {
|
|
716
|
+
oracle: decodedData[0] as EthereumAddress,
|
|
717
|
+
collateralToken: decodedData[1] as EthereumAddress,
|
|
718
|
+
loanToken: decodedData[2] as EthereumAddress,
|
|
719
|
+
lowerPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
|
|
720
|
+
upperPrice: new Dec(decodedData[4] as string).div(1e8).toString(),
|
|
721
|
+
};
|
|
722
|
+
},
|
|
688
723
|
};
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import * as web3Utils from 'web3-utils';
|
|
3
|
-
import AbiCoder from 'web3-eth-abi';
|
|
4
2
|
import { getAssetInfo } from '@defisaver/tokens';
|
|
5
3
|
|
|
6
4
|
import type { EthereumAddress } from '../types';
|
|
7
5
|
import { ChainId, ProtocolIdentifiers, RatioState } from '../types/enums';
|
|
8
6
|
|
|
9
|
-
import { sparkEncode } from './strategySubService';
|
|
10
|
-
|
|
11
7
|
import '../configuration';
|
|
12
8
|
import {
|
|
13
9
|
addToArrayIf,
|
|
14
10
|
addToObjectIf,
|
|
15
11
|
compareAddresses,
|
|
16
|
-
compareSubHashes,
|
|
17
12
|
encodeSubId,
|
|
18
13
|
ethToWeth,
|
|
19
14
|
getRatioStateInfoForAaveCloseStrategy,
|
|
@@ -199,60 +194,6 @@ describe('Feature: utils.ts', () => {
|
|
|
199
194
|
});
|
|
200
195
|
});
|
|
201
196
|
|
|
202
|
-
describe('When testing utils.compareSubHashes()', () => {
|
|
203
|
-
|
|
204
|
-
const subDataToEncodeOne = [
|
|
205
|
-
12,
|
|
206
|
-
false,
|
|
207
|
-
{
|
|
208
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
209
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
210
|
-
price: 100,
|
|
211
|
-
ratioState: 1,
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
215
|
-
collAssetId: 2,
|
|
216
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
217
|
-
debtAssetId: 3,
|
|
218
|
-
},
|
|
219
|
-
]
|
|
220
|
-
|
|
221
|
-
const subDataToEncodeTwo = [
|
|
222
|
-
13,
|
|
223
|
-
true,
|
|
224
|
-
{
|
|
225
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
226
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
227
|
-
price: 100,
|
|
228
|
-
ratioState: 2,
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
232
|
-
collAssetId: 2,
|
|
233
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
234
|
-
debtAssetId: 3,
|
|
235
|
-
},
|
|
236
|
-
]
|
|
237
|
-
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
const encodedSubDataOne = sparkEncode.closeToAsset(...subDataToEncodeOne);
|
|
240
|
-
// @ts-ignore
|
|
241
|
-
const encodedSubDataTwo = sparkEncode.closeToAsset(...subDataToEncodeTwo);
|
|
242
|
-
const encodedParams = web3Utils.keccak256(AbiCoder.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
|
|
243
|
-
|
|
244
|
-
const examples: Array<[boolean, [string, any[]]]> = [
|
|
245
|
-
[true, [encodedParams, encodedSubDataOne]],
|
|
246
|
-
[false, [encodedParams, encodedSubDataTwo]],
|
|
247
|
-
];
|
|
248
|
-
|
|
249
|
-
examples.forEach(([expected, actual]) => {
|
|
250
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
251
|
-
expect(compareSubHashes(...actual)).to.equal(expected);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
197
|
describe('When testing utils.encodeSubId()', () => {
|
|
257
198
|
const examples: Array<[string, string]> = [
|
|
258
199
|
['00000001', '1'],
|
package/src/types/enums.ts
CHANGED
|
@@ -186,8 +186,6 @@ export namespace Bundles {
|
|
|
186
186
|
LIQUITY_BOOST = 17,
|
|
187
187
|
SPARK_REPAY = 18,
|
|
188
188
|
SPARK_BOOST = 19,
|
|
189
|
-
SPARK_CLOSE_TO_DEBT = -21231230, // @dev This was never deployed
|
|
190
|
-
SPARK_CLOSE_TO_COLLATERAL = -21231231, // @dev This was never deployed
|
|
191
189
|
AAVE_V2_REPAY = 22,
|
|
192
190
|
AAVE_V2_BOOST = 23,
|
|
193
191
|
COMP_V2_REPAY = 20,
|
|
@@ -223,6 +221,8 @@ export namespace Bundles {
|
|
|
223
221
|
AAVE_V3_EOA_REPAY_ON_PRICE = 54,
|
|
224
222
|
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
225
223
|
AAVE_V3_EOA_CLOSE = 56,
|
|
224
|
+
SPARK_CLOSE = 57,
|
|
225
|
+
MORPHO_BLUE_CLOSE = 58,
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
export enum OptimismIds {
|
|
@@ -266,6 +266,7 @@ export namespace Bundles {
|
|
|
266
266
|
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
267
267
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
268
268
|
AAVE_V3_EOA_CLOSE = 27,
|
|
269
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
269
270
|
}
|
|
270
271
|
|
|
271
272
|
export enum ArbitrumIds {
|
|
@@ -297,6 +298,7 @@ export namespace Bundles {
|
|
|
297
298
|
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
298
299
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
299
300
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
301
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
300
302
|
}
|
|
301
303
|
}
|
|
302
304
|
|