@defisaver/automation-sdk 3.3.21-instant-twap-close-dev → 3.3.21
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 +5 -1
- package/cjs/automation/private/StrategiesAutomation.js +12 -0
- package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
- package/cjs/constants/index.js +0 -10
- package/cjs/services/apiSubscriptionsService.d.ts +7 -0
- package/cjs/services/apiSubscriptionsService.js +33 -0
- package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
- package/cjs/services/apiSubscriptionsService.test.js +67 -0
- package/cjs/services/strategiesService.js +0 -25
- package/cjs/services/strategiesService.test.js +0 -63
- package/cjs/services/strategySubService.d.ts +0 -1
- package/cjs/services/strategySubService.js +0 -7
- package/cjs/services/strategySubService.test.js +0 -111
- package/cjs/services/subDataService.d.ts +0 -14
- package/cjs/services/subDataService.js +2 -40
- package/cjs/services/subDataService.test.js +0 -70
- package/cjs/types/enums.d.ts +1 -5
- package/cjs/types/enums.js +0 -4
- package/cjs/types/index.d.ts +24 -2
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +12 -0
- package/esm/automation/private/StrategiesAutomation.test.js +51 -0
- package/esm/constants/index.js +0 -10
- package/esm/services/apiSubscriptionsService.d.ts +7 -0
- package/esm/services/apiSubscriptionsService.js +29 -0
- package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
- package/esm/services/apiSubscriptionsService.test.js +65 -0
- package/esm/services/strategiesService.js +0 -25
- package/esm/services/strategiesService.test.js +1 -64
- package/esm/services/strategySubService.d.ts +0 -1
- package/esm/services/strategySubService.js +0 -7
- package/esm/services/strategySubService.test.js +0 -111
- package/esm/services/subDataService.d.ts +0 -14
- package/esm/services/subDataService.js +0 -38
- package/esm/services/subDataService.test.js +0 -70
- package/esm/types/enums.d.ts +1 -5
- package/esm/types/enums.js +0 -4
- package/esm/types/index.d.ts +24 -2
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +65 -1
- package/src/automation/private/StrategiesAutomation.ts +17 -0
- package/src/constants/index.ts +0 -10
- package/src/services/apiSubscriptionsService.test.ts +73 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/strategiesService.test.ts +1 -79
- package/src/services/strategiesService.ts +0 -33
- package/src/services/strategySubService.test.ts +0 -130
- package/src/services/strategySubService.ts +0 -26
- package/src/services/subDataService.test.ts +0 -98
- package/src/services/subDataService.ts +0 -61
- package/src/types/enums.ts +0 -4
- package/src/types/index.ts +26 -2
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
Bundles, CloseStrategyType, CloseToAssetType, ProtocolIdentifiers, Strategies,
|
|
5
|
-
} from '../types/enums';
|
|
3
|
+
import { ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
6
4
|
import type { ParseData, Position } from '../types';
|
|
7
5
|
|
|
8
6
|
import '../configuration';
|
|
9
7
|
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
10
|
-
import { aaveV3Encode } from './strategySubService';
|
|
11
8
|
|
|
12
9
|
describe('Feature: strategiesService.ts', () => {
|
|
13
10
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', async () => {
|
|
@@ -79,7 +76,6 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
79
76
|
subId: '379',
|
|
80
77
|
proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
|
|
81
78
|
subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
|
|
82
|
-
// @ts-ignore
|
|
83
79
|
subStruct:
|
|
84
80
|
{
|
|
85
81
|
strategyOrBundleId: '8',
|
|
@@ -106,78 +102,4 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
106
102
|
});
|
|
107
103
|
});
|
|
108
104
|
});
|
|
109
|
-
|
|
110
|
-
describe('When parsing Aave V3 instant close bundles', () => {
|
|
111
|
-
const owner = '0x1234567890123456789012345678901234567890';
|
|
112
|
-
const market = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
113
|
-
const weth = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
114
|
-
const usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
|
115
|
-
|
|
116
|
-
const bundles: Array<[string, Bundles.MainnetIds, Strategies.Identifiers]> = [
|
|
117
|
-
['SW', Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE, Strategies.Identifiers.InstantCloseOnPrice],
|
|
118
|
-
['EOA', Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE, Strategies.Identifiers.EoaInstantCloseOnPrice],
|
|
119
|
-
];
|
|
120
|
-
|
|
121
|
-
bundles.forEach(([walletType, expectedBundleId, expectedStrategyId]) => {
|
|
122
|
-
describe(`${walletType} bundle`, () => {
|
|
123
|
-
const [bundleId, isBundle, triggerData, subData] = aaveV3Encode.instantCloseOnPriceGeneric(
|
|
124
|
-
expectedBundleId,
|
|
125
|
-
weth, 0, usdc, 1, market, owner,
|
|
126
|
-
'1000000000000000000', '10000000000000000',
|
|
127
|
-
1500, CloseToAssetType.DEBT, 5000, CloseToAssetType.COLLATERAL,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const parseData = {
|
|
131
|
-
chainId: 1,
|
|
132
|
-
blockNumber: 1,
|
|
133
|
-
subscriptionEventData: {
|
|
134
|
-
subId: '1',
|
|
135
|
-
proxy: owner,
|
|
136
|
-
subHash: '0xhash',
|
|
137
|
-
subStruct: {
|
|
138
|
-
strategyOrBundleId: String(bundleId), isBundle, triggerData, subData,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
strategiesSubsData: { userProxy: owner, isEnabled: true, strategySubHash: '0xhash' },
|
|
142
|
-
} as unknown as ParseData;
|
|
143
|
-
|
|
144
|
-
const result = parseStrategiesAutomatedPosition(parseData) as Position.Automated;
|
|
145
|
-
|
|
146
|
-
it('should identify the strategy as instant close on price', () => {
|
|
147
|
-
expect(result.strategy.strategyOrBundleId).to.equal(expectedBundleId);
|
|
148
|
-
expect(result.strategy.strategyId).to.equal(expectedStrategyId);
|
|
149
|
-
expect(result.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it('should decode sub data including tsi and slippage', () => {
|
|
153
|
-
expect(result.strategyData.decoded.subData).to.eql({
|
|
154
|
-
collAsset: weth,
|
|
155
|
-
collAssetId: 0,
|
|
156
|
-
debtAsset: usdc,
|
|
157
|
-
debtAssetId: 1,
|
|
158
|
-
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
159
|
-
marketAddr: market,
|
|
160
|
-
owner,
|
|
161
|
-
tsi: '1000000000000000000',
|
|
162
|
-
slippage: '10000000000000000',
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should fill specific with prices and close types', () => {
|
|
167
|
-
expect(result.specific).to.eql({
|
|
168
|
-
collAsset: weth,
|
|
169
|
-
collAssetId: 0,
|
|
170
|
-
debtAsset: usdc,
|
|
171
|
-
debtAssetId: 1,
|
|
172
|
-
baseToken: weth,
|
|
173
|
-
quoteToken: usdc,
|
|
174
|
-
stopLossPrice: '1500',
|
|
175
|
-
takeProfitPrice: '5000',
|
|
176
|
-
stopLossType: CloseToAssetType.DEBT,
|
|
177
|
-
takeProfitType: CloseToAssetType.COLLATERAL,
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
105
|
});
|
|
@@ -433,37 +433,6 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
|
|
|
433
433
|
return _position;
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
function parseAaveV3InstantCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
437
|
-
const _position = cloneDeep(position);
|
|
438
|
-
|
|
439
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
440
|
-
|
|
441
|
-
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
442
|
-
const subData = subDataService.aaveV3InstantCloseGenericSubData.decode(subStruct.subData);
|
|
443
|
-
|
|
444
|
-
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
445
|
-
|
|
446
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
447
|
-
|
|
448
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
449
|
-
_position.strategyData.decoded.subData = subData;
|
|
450
|
-
|
|
451
|
-
_position.specific = {
|
|
452
|
-
collAsset: subData.collAsset,
|
|
453
|
-
collAssetId: subData.collAssetId,
|
|
454
|
-
debtAsset: subData.debtAsset,
|
|
455
|
-
debtAssetId: subData.debtAssetId,
|
|
456
|
-
baseToken: triggerData.collToken,
|
|
457
|
-
quoteToken: triggerData.debtToken,
|
|
458
|
-
stopLossPrice: triggerData.lowerPrice,
|
|
459
|
-
takeProfitPrice: triggerData.upperPrice,
|
|
460
|
-
stopLossType,
|
|
461
|
-
takeProfitType,
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
return _position;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
436
|
function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
468
437
|
const _position = cloneDeep(position);
|
|
469
438
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -1627,8 +1596,6 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1627
1596
|
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1628
1597
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1629
1598
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1630
|
-
[Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1631
|
-
[Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1632
1599
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1633
1600
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1634
1601
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
@@ -887,136 +887,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
887
887
|
});
|
|
888
888
|
});
|
|
889
889
|
|
|
890
|
-
describe('instantCloseOnPriceGeneric()', () => {
|
|
891
|
-
const examples: Array<[
|
|
892
|
-
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
893
|
-
[
|
|
894
|
-
strategyOrBundleId: number,
|
|
895
|
-
collAsset: EthereumAddress,
|
|
896
|
-
collAssetId: number,
|
|
897
|
-
debtAsset: EthereumAddress,
|
|
898
|
-
debtAssetId: number,
|
|
899
|
-
marketAddr: EthereumAddress,
|
|
900
|
-
user: EthereumAddress,
|
|
901
|
-
tsi: string,
|
|
902
|
-
slippage: string,
|
|
903
|
-
stopLossPrice: number,
|
|
904
|
-
stopLossType: CloseToAssetType,
|
|
905
|
-
takeProfitPrice: number,
|
|
906
|
-
takeProfitType: CloseToAssetType
|
|
907
|
-
]
|
|
908
|
-
]> = [
|
|
909
|
-
// Stop loss only (to debt)
|
|
910
|
-
[
|
|
911
|
-
[
|
|
912
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
913
|
-
true,
|
|
914
|
-
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
915
|
-
[
|
|
916
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
917
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
918
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
919
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
920
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
921
|
-
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
922
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
923
|
-
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
924
|
-
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
925
|
-
],
|
|
926
|
-
],
|
|
927
|
-
[
|
|
928
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
929
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
930
|
-
0,
|
|
931
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
932
|
-
1,
|
|
933
|
-
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
934
|
-
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
935
|
-
'1000000000000000000', // tsi
|
|
936
|
-
'10000000000000000', // slippage
|
|
937
|
-
1500, // stopLossPrice
|
|
938
|
-
CloseToAssetType.DEBT, // stopLossType
|
|
939
|
-
0, // takeProfitPrice
|
|
940
|
-
CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
|
|
941
|
-
]
|
|
942
|
-
],
|
|
943
|
-
// Take profit only (to collateral), zero tsi and slippage
|
|
944
|
-
[
|
|
945
|
-
[
|
|
946
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
947
|
-
true,
|
|
948
|
-
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
949
|
-
[
|
|
950
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
951
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
952
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
953
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
954
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
955
|
-
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
956
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
957
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
958
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
959
|
-
],
|
|
960
|
-
],
|
|
961
|
-
[
|
|
962
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
963
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
964
|
-
0,
|
|
965
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
966
|
-
1,
|
|
967
|
-
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
968
|
-
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
969
|
-
'0', // tsi
|
|
970
|
-
'0', // slippage
|
|
971
|
-
0, // stopLossPrice
|
|
972
|
-
CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
|
|
973
|
-
5000, // takeProfitPrice
|
|
974
|
-
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
975
|
-
]
|
|
976
|
-
],
|
|
977
|
-
// Take profit (to debt) and stop loss (to collateral)
|
|
978
|
-
[
|
|
979
|
-
[
|
|
980
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
981
|
-
true,
|
|
982
|
-
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
983
|
-
[
|
|
984
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
985
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
986
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
987
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
988
|
-
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
989
|
-
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
990
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
991
|
-
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
992
|
-
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
993
|
-
],
|
|
994
|
-
],
|
|
995
|
-
[
|
|
996
|
-
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
997
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
998
|
-
0,
|
|
999
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1000
|
-
1,
|
|
1001
|
-
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1002
|
-
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1003
|
-
'50000000000000000', // tsi
|
|
1004
|
-
'5000000000000000', // slippage
|
|
1005
|
-
1500, // stopLossPrice
|
|
1006
|
-
CloseToAssetType.COLLATERAL, // stopLossType
|
|
1007
|
-
4000, // takeProfitPrice
|
|
1008
|
-
CloseToAssetType.DEBT, // takeProfitType
|
|
1009
|
-
]
|
|
1010
|
-
],
|
|
1011
|
-
];
|
|
1012
|
-
|
|
1013
|
-
examples.forEach(([expected, actual]) => {
|
|
1014
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1015
|
-
expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
|
|
1016
|
-
});
|
|
1017
|
-
});
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
890
|
describe('collateralSwitch()', () => {
|
|
1021
891
|
const examples: Array<[
|
|
1022
892
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
@@ -424,32 +424,6 @@ export const aaveV3Encode = {
|
|
|
424
424
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
425
425
|
},
|
|
426
426
|
|
|
427
|
-
instantCloseOnPriceGeneric(
|
|
428
|
-
strategyOrBundleId: number,
|
|
429
|
-
collAsset: EthereumAddress,
|
|
430
|
-
collAssetId: number,
|
|
431
|
-
debtAsset: EthereumAddress,
|
|
432
|
-
debtAssetId: number,
|
|
433
|
-
marketAddr: EthereumAddress,
|
|
434
|
-
user: EthereumAddress,
|
|
435
|
-
tsi: string,
|
|
436
|
-
slippage: string,
|
|
437
|
-
stopLossPrice: number = 0,
|
|
438
|
-
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
439
|
-
takeProfitPrice: number = 0,
|
|
440
|
-
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
441
|
-
) {
|
|
442
|
-
const isBundle = true;
|
|
443
|
-
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
444
|
-
|
|
445
|
-
const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(
|
|
446
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage,
|
|
447
|
-
);
|
|
448
|
-
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
449
|
-
|
|
450
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
451
|
-
},
|
|
452
|
-
|
|
453
427
|
collateralSwitch(
|
|
454
428
|
strategyOrBundleId: number,
|
|
455
429
|
fromAsset: EthereumAddress,
|
|
@@ -2495,104 +2495,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2495
2495
|
});
|
|
2496
2496
|
});
|
|
2497
2497
|
});
|
|
2498
|
-
|
|
2499
|
-
describe("When testing subDataService.aaveV3InstantCloseGenericSubData", () => {
|
|
2500
|
-
const WETH = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
2501
|
-
const USDC = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
2502
|
-
const MARKET = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
2503
|
-
const USER = web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890');
|
|
2504
|
-
|
|
2505
|
-
const examples: Array<
|
|
2506
|
-
[
|
|
2507
|
-
string[],
|
|
2508
|
-
[
|
|
2509
|
-
collAsset: EthereumAddress,
|
|
2510
|
-
collAssetId: number,
|
|
2511
|
-
debtAsset: EthereumAddress,
|
|
2512
|
-
debtAssetId: number,
|
|
2513
|
-
closeType: CloseStrategyType,
|
|
2514
|
-
marketAddr: EthereumAddress,
|
|
2515
|
-
user: EthereumAddress,
|
|
2516
|
-
tsi: string,
|
|
2517
|
-
slippage: string
|
|
2518
|
-
]
|
|
2519
|
-
]
|
|
2520
|
-
> = [
|
|
2521
|
-
// TAKE_PROFIT_IN_COLLATERAL, zero tsi and slippage
|
|
2522
|
-
[
|
|
2523
|
-
[
|
|
2524
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2525
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2526
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2527
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2528
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2529
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2530
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2531
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2532
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2533
|
-
],
|
|
2534
|
-
[WETH, 0, USDC, 1, CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL, MARKET, USER, '0', '0'],
|
|
2535
|
-
],
|
|
2536
|
-
// STOP_LOSS_IN_DEBT
|
|
2537
|
-
[
|
|
2538
|
-
[
|
|
2539
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2540
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
2541
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2542
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
2543
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
2544
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2545
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2546
|
-
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
2547
|
-
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
2548
|
-
],
|
|
2549
|
-
[WETH, 0, USDC, 1, CloseStrategyType.STOP_LOSS_IN_DEBT, MARKET, USER, '1000000000000000000', '10000000000000000'],
|
|
2550
|
-
],
|
|
2551
|
-
// TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, asset ids above uint8 range
|
|
2552
|
-
[
|
|
2553
|
-
[
|
|
2554
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
2555
|
-
'0x000000000000000000000000000000000000000000000000000000000000012c',
|
|
2556
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
2557
|
-
'0x0000000000000000000000000000000000000000000000000000000000000190',
|
|
2558
|
-
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
2559
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
2560
|
-
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
2561
|
-
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
2562
|
-
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
2563
|
-
],
|
|
2564
|
-
[WETH, 300, USDC, 400, CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL, MARKET, USER, '50000000000000000', '5000000000000000'],
|
|
2565
|
-
],
|
|
2566
|
-
];
|
|
2567
|
-
|
|
2568
|
-
describe("encode()", () => {
|
|
2569
|
-
examples.forEach(([expected, actual]) => {
|
|
2570
|
-
it(`Given ${JSON.stringify(
|
|
2571
|
-
actual
|
|
2572
|
-
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2573
|
-
expect(
|
|
2574
|
-
subDataService.aaveV3InstantCloseGenericSubData.encode(...actual)
|
|
2575
|
-
).to.eql(expected);
|
|
2576
|
-
});
|
|
2577
|
-
});
|
|
2578
|
-
});
|
|
2579
|
-
|
|
2580
|
-
describe("decode()", () => {
|
|
2581
|
-
examples.forEach(([encoded, [collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage]]) => {
|
|
2582
|
-
const expected = {
|
|
2583
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner: user, tsi, slippage,
|
|
2584
|
-
};
|
|
2585
|
-
|
|
2586
|
-
it(`Given ${JSON.stringify(
|
|
2587
|
-
encoded
|
|
2588
|
-
)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
2589
|
-
expect(
|
|
2590
|
-
subDataService.aaveV3InstantCloseGenericSubData.decode(encoded)
|
|
2591
|
-
).to.eql(expected);
|
|
2592
|
-
});
|
|
2593
|
-
});
|
|
2594
|
-
});
|
|
2595
|
-
});
|
|
2596
2498
|
describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
|
|
2597
2499
|
describe('encode()', () => {
|
|
2598
2500
|
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]] > =
|
|
@@ -687,67 +687,6 @@ export const aaveV3CloseGenericSubData = {
|
|
|
687
687
|
};
|
|
688
688
|
},
|
|
689
689
|
};
|
|
690
|
-
export const aaveV3InstantCloseGenericSubData = {
|
|
691
|
-
encode(
|
|
692
|
-
collAsset: EthereumAddress,
|
|
693
|
-
collAssetId: number,
|
|
694
|
-
debtAsset: EthereumAddress,
|
|
695
|
-
debtAssetId: number,
|
|
696
|
-
closeType: CloseStrategyType,
|
|
697
|
-
marketAddr: EthereumAddress,
|
|
698
|
-
user: EthereumAddress,
|
|
699
|
-
tsi: string,
|
|
700
|
-
slippage: string,
|
|
701
|
-
): SubData {
|
|
702
|
-
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
703
|
-
const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
|
|
704
|
-
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
705
|
-
const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
|
|
706
|
-
const encodedCloseType = AbiCoder.encodeParameter('uint8', closeType);
|
|
707
|
-
const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
|
|
708
|
-
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
709
|
-
const encodedTsi = AbiCoder.encodeParameter('uint256', tsi);
|
|
710
|
-
const encodedSlippage = AbiCoder.encodeParameter('uint256', slippage);
|
|
711
|
-
|
|
712
|
-
return [
|
|
713
|
-
encodedColl,
|
|
714
|
-
encodedCollId,
|
|
715
|
-
encodedDebt,
|
|
716
|
-
encodedDebtId,
|
|
717
|
-
encodedCloseType,
|
|
718
|
-
encodedMarket,
|
|
719
|
-
encodedUser,
|
|
720
|
-
encodedTsi,
|
|
721
|
-
encodedSlippage,
|
|
722
|
-
];
|
|
723
|
-
},
|
|
724
|
-
|
|
725
|
-
decode(subData: SubData): {
|
|
726
|
-
collAsset: EthereumAddress,
|
|
727
|
-
collAssetId: number,
|
|
728
|
-
debtAsset: EthereumAddress,
|
|
729
|
-
debtAssetId: number,
|
|
730
|
-
closeType: CloseStrategyType,
|
|
731
|
-
marketAddr: EthereumAddress,
|
|
732
|
-
owner: EthereumAddress,
|
|
733
|
-
tsi: string,
|
|
734
|
-
slippage: string,
|
|
735
|
-
} {
|
|
736
|
-
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
737
|
-
const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
738
|
-
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
739
|
-
const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
740
|
-
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[4])) as CloseStrategyType;
|
|
741
|
-
const marketAddr = AbiCoder.decodeParameter('address', subData[5]) as unknown as EthereumAddress;
|
|
742
|
-
const owner = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
743
|
-
const tsi = AbiCoder.decodeParameter('uint256', subData[7]) as unknown as string;
|
|
744
|
-
const slippage = AbiCoder.decodeParameter('uint256', subData[8]) as unknown as string;
|
|
745
|
-
|
|
746
|
-
return {
|
|
747
|
-
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, owner, tsi, slippage,
|
|
748
|
-
};
|
|
749
|
-
},
|
|
750
|
-
};
|
|
751
690
|
export const aaveV3CollateralSwitchSubData = {
|
|
752
691
|
encode(
|
|
753
692
|
fromAsset: EthereumAddress,
|
package/src/types/enums.ts
CHANGED
|
@@ -138,8 +138,6 @@ export namespace Strategies {
|
|
|
138
138
|
CloseOnPriceToColl = 'close-on-price-to-collateral',
|
|
139
139
|
CloseOnPrice = 'close-on-price',
|
|
140
140
|
EoaCloseOnPrice = 'eoa-close-on-price',
|
|
141
|
-
InstantCloseOnPrice = 'instant-close-on-price',
|
|
142
|
-
EoaInstantCloseOnPrice = 'eoa-instant-close-on-price',
|
|
143
141
|
TrailingStopToColl = 'trailing-stop-to-collateral',
|
|
144
142
|
TrailingStopToDebt = 'trailing-stop-to-debt',
|
|
145
143
|
Rebond = 'rebond',
|
|
@@ -268,8 +266,6 @@ export namespace Bundles {
|
|
|
268
266
|
SPARK_EOA_BOOST_ON_PRICE = 91,
|
|
269
267
|
SPARK_EOA_CLOSE = 92,
|
|
270
268
|
SPARK_EOA_LIQUIDATION_PROTECTION = 93,
|
|
271
|
-
AAVE_V3_SW_INSTANT_CLOSE = 94,
|
|
272
|
-
AAVE_V3_EOA_INSTANT_CLOSE = 95,
|
|
273
269
|
}
|
|
274
270
|
|
|
275
271
|
export enum OptimismIds {
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type Web3 from 'web3';
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
|
-
import type {
|
|
4
|
+
import type { StrategyModel } from './contracts/generated/SubStorage';
|
|
5
5
|
import type {
|
|
6
6
|
ChainId, Strategies, Bundles, ProtocolIdentifiers,
|
|
7
7
|
RatioState,
|
|
@@ -72,6 +72,22 @@ interface _SubscriptionOptions {
|
|
|
72
72
|
|
|
73
73
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
74
74
|
|
|
75
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
76
|
+
export interface ApiSubscriptionRecord {
|
|
77
|
+
id: number,
|
|
78
|
+
wallet: EthereumAddress,
|
|
79
|
+
wallet_type: string,
|
|
80
|
+
is_enabled: boolean,
|
|
81
|
+
is_bundle: boolean,
|
|
82
|
+
strategy_or_bundle_id: number,
|
|
83
|
+
strategy_ids: number[],
|
|
84
|
+
sub_data_hash: string,
|
|
85
|
+
trigger_data: string[],
|
|
86
|
+
sub_data: string[],
|
|
87
|
+
block_number: number,
|
|
88
|
+
additional_triggers: string[] | null,
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
export declare namespace Interfaces {
|
|
76
92
|
interface ProtocolBase {
|
|
77
93
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
|
|
@@ -369,10 +385,18 @@ export type StrategyOrBundleIds =
|
|
|
369
385
|
| typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
|
|
370
386
|
| typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
371
387
|
|
|
388
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
389
|
+
export interface SubscriptionEventData {
|
|
390
|
+
subId: string,
|
|
391
|
+
proxy: EthereumAddress,
|
|
392
|
+
subHash: string,
|
|
393
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct,
|
|
394
|
+
}
|
|
395
|
+
|
|
372
396
|
export interface ParseData {
|
|
373
397
|
chainId: ChainId,
|
|
374
398
|
blockNumber: BlockNumber,
|
|
375
|
-
subscriptionEventData:
|
|
399
|
+
subscriptionEventData: SubscriptionEventData,
|
|
376
400
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
377
401
|
}
|
|
378
402
|
|