@defisaver/automation-sdk 3.3.18 → 3.3.19-sub-fetching-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 +5 -1
- package/cjs/automation/private/StrategiesAutomation.js +19 -2
- package/cjs/automation/private/StrategiesAutomation.test.js +55 -0
- package/cjs/constants/index.js +35 -0
- 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 +69 -0
- package/cjs/services/ethereumService.test.js +4 -7
- package/cjs/services/strategiesService.js +40 -9
- package/cjs/services/strategiesService.test.js +0 -1
- package/cjs/services/strategySubService.d.ts +4 -0
- package/cjs/services/strategySubService.js +24 -0
- package/cjs/services/strategySubService.test.js +295 -0
- package/cjs/services/subDataService.d.ts +38 -0
- package/cjs/services/subDataService.js +76 -2
- package/cjs/services/subDataService.test.js +494 -4
- package/cjs/types/enums.d.ts +15 -2
- package/cjs/types/enums.js +15 -1
- package/cjs/types/index.d.ts +29 -3
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
- package/esm/automation/private/StrategiesAutomation.js +20 -3
- package/esm/automation/private/StrategiesAutomation.test.js +56 -1
- package/esm/constants/index.js +35 -0
- 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 +67 -0
- package/esm/services/ethereumService.test.js +4 -7
- package/esm/services/strategiesService.js +40 -9
- package/esm/services/strategiesService.test.js +0 -1
- package/esm/services/strategySubService.d.ts +4 -0
- package/esm/services/strategySubService.js +24 -0
- package/esm/services/strategySubService.test.js +295 -0
- package/esm/services/subDataService.d.ts +38 -0
- package/esm/services/subDataService.js +74 -0
- package/esm/services/subDataService.test.js +494 -4
- package/esm/types/enums.d.ts +15 -2
- package/esm/types/enums.js +14 -0
- package/esm/types/index.d.ts +29 -3
- package/package.json +1 -1
- package/src/automation/private/StrategiesAutomation.test.ts +70 -1
- package/src/automation/private/StrategiesAutomation.ts +25 -1
- package/src/constants/index.ts +35 -0
- package/src/services/apiSubscriptionsService.test.ts +75 -0
- package/src/services/apiSubscriptionsService.ts +33 -0
- package/src/services/ethereumService.test.ts +5 -8
- package/src/services/strategiesService.test.ts +0 -1
- package/src/services/strategiesService.ts +43 -10
- package/src/services/strategySubService.test.ts +382 -0
- package/src/services/strategySubService.ts +87 -0
- package/src/services/subDataService.test.ts +608 -4
- package/src/services/subDataService.ts +107 -0
- package/src/types/enums.ts +14 -0
- package/src/types/index.ts +31 -2
|
@@ -1249,6 +1249,27 @@ export const sparkLeverageManagementSubData = {
|
|
|
1249
1249
|
|
|
1250
1250
|
export const sparkLiquidationProtectionSubData = sparkLeverageManagementSubData;
|
|
1251
1251
|
|
|
1252
|
+
export const sparkGenericLeverageManagementSubData = {
|
|
1253
|
+
encode(
|
|
1254
|
+
targetRatio: number,
|
|
1255
|
+
ratioState: RatioState,
|
|
1256
|
+
market: EthereumAddress,
|
|
1257
|
+
user: EthereumAddress,
|
|
1258
|
+
): SubData {
|
|
1259
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1260
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1261
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
1262
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
1263
|
+
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
1264
|
+
},
|
|
1265
|
+
decode(subData: SubData): { targetRatio: number, ratioState: RatioState } {
|
|
1266
|
+
const targetRatio = weiToRatioPercentage(String(AbiCoder.decodeParameter('uint256', subData[0])));
|
|
1267
|
+
const ratioState = Number(AbiCoder.decodeParameter('uint8', subData[1])) as RatioState;
|
|
1268
|
+
return { targetRatio, ratioState };
|
|
1269
|
+
},
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
export const sparkGenericLiquidationProtectionSubData = sparkGenericLeverageManagementSubData;
|
|
1252
1273
|
|
|
1253
1274
|
export const sparkCloseGenericSubData = {
|
|
1254
1275
|
encode(
|
|
@@ -1339,6 +1360,41 @@ export const sparkLeverageManagementOnPriceSubData = {
|
|
|
1339
1360
|
};
|
|
1340
1361
|
},
|
|
1341
1362
|
};
|
|
1363
|
+
export const sparkLeverageManagementOnPriceGenericSubData = {
|
|
1364
|
+
encode(
|
|
1365
|
+
collAsset: EthereumAddress,
|
|
1366
|
+
collAssetId: number,
|
|
1367
|
+
debtAsset: EthereumAddress,
|
|
1368
|
+
debtAssetId: number,
|
|
1369
|
+
marketAddr: EthereumAddress,
|
|
1370
|
+
targetRatio: number,
|
|
1371
|
+
user: EthereumAddress,
|
|
1372
|
+
): SubData {
|
|
1373
|
+
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
1374
|
+
const encodedCollId = AbiCoder.encodeParameter('uint16', collAssetId);
|
|
1375
|
+
const encodedDebt = AbiCoder.encodeParameter('address', debtAsset);
|
|
1376
|
+
const encodedDebtId = AbiCoder.encodeParameter('uint16', debtAssetId);
|
|
1377
|
+
const encodedMarket = AbiCoder.encodeParameter('address', marketAddr);
|
|
1378
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1379
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
1380
|
+
return [
|
|
1381
|
+
encodedColl, encodedCollId, encodedDebt, encodedDebtId,
|
|
1382
|
+
encodedMarket, encodedTargetRatio, encodedUser,
|
|
1383
|
+
];
|
|
1384
|
+
},
|
|
1385
|
+
decode(subData: SubData) {
|
|
1386
|
+
const collAsset = AbiCoder.decodeParameter('address', subData[0]) as any as EthereumAddress;
|
|
1387
|
+
const collAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
1388
|
+
const debtAsset = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
1389
|
+
const debtAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
1390
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as any as EthereumAddress;
|
|
1391
|
+
const targetRatio = weiToRatioPercentage(String(AbiCoder.decodeParameter('uint256', subData[5])));
|
|
1392
|
+
const user = AbiCoder.decodeParameter('address', subData[6]) as any as EthereumAddress;
|
|
1393
|
+
return {
|
|
1394
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user,
|
|
1395
|
+
};
|
|
1396
|
+
},
|
|
1397
|
+
};
|
|
1342
1398
|
export const sparkCollateralSwitchSubData = {
|
|
1343
1399
|
encode(
|
|
1344
1400
|
fromAsset: EthereumAddress,
|
|
@@ -1388,6 +1444,57 @@ export const sparkCollateralSwitchSubData = {
|
|
|
1388
1444
|
},
|
|
1389
1445
|
};
|
|
1390
1446
|
|
|
1447
|
+
export const sparkGenericFLCollateralSwitchSubData = {
|
|
1448
|
+
encode(
|
|
1449
|
+
fromAsset: EthereumAddress,
|
|
1450
|
+
fromAssetId: number,
|
|
1451
|
+
toAsset: EthereumAddress,
|
|
1452
|
+
toAssetId: number,
|
|
1453
|
+
marketAddr: EthereumAddress,
|
|
1454
|
+
amountToSwitch: string,
|
|
1455
|
+
user: EthereumAddress,
|
|
1456
|
+
): SubData {
|
|
1457
|
+
const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
|
|
1458
|
+
const encodedFromAssetId = AbiCoder.encodeParameter('uint16', fromAssetId);
|
|
1459
|
+
const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
|
|
1460
|
+
const encodedToAssetId = AbiCoder.encodeParameter('uint16', toAssetId);
|
|
1461
|
+
const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
|
|
1462
|
+
const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
|
|
1463
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
1464
|
+
|
|
1465
|
+
return [
|
|
1466
|
+
encodedFromAsset,
|
|
1467
|
+
encodedFromAssetId,
|
|
1468
|
+
encodedToAsset,
|
|
1469
|
+
encodedToAssetId,
|
|
1470
|
+
encodedMarketAddr,
|
|
1471
|
+
encodedAmountToSwitch,
|
|
1472
|
+
encodedUser,
|
|
1473
|
+
];
|
|
1474
|
+
},
|
|
1475
|
+
decode(subData: SubData): {
|
|
1476
|
+
fromAsset: EthereumAddress,
|
|
1477
|
+
fromAssetId: number,
|
|
1478
|
+
toAsset: EthereumAddress,
|
|
1479
|
+
toAssetId: number,
|
|
1480
|
+
marketAddr: EthereumAddress,
|
|
1481
|
+
amountToSwitch: string,
|
|
1482
|
+
user: EthereumAddress,
|
|
1483
|
+
} {
|
|
1484
|
+
const fromAsset = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1485
|
+
const fromAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
|
|
1486
|
+
const toAsset = AbiCoder.decodeParameter('address', subData[2]) as unknown as EthereumAddress;
|
|
1487
|
+
const toAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
|
|
1488
|
+
const marketAddr = AbiCoder.decodeParameter('address', subData[4]) as unknown as EthereumAddress;
|
|
1489
|
+
const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]) as unknown as string;
|
|
1490
|
+
const user = AbiCoder.decodeParameter('address', subData[6]) as unknown as EthereumAddress;
|
|
1491
|
+
|
|
1492
|
+
return {
|
|
1493
|
+
fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
|
|
1494
|
+
};
|
|
1495
|
+
},
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1391
1498
|
|
|
1392
1499
|
/**
|
|
1393
1500
|
______ .______ ____ ____ __ __ _______. _______
|
package/src/types/enums.ts
CHANGED
|
@@ -5,6 +5,13 @@ export enum ChainId {
|
|
|
5
5
|
Base = 8453,
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export enum SubscriptionStatus {
|
|
9
|
+
Active = 'active',
|
|
10
|
+
Disabled = 'disabled',
|
|
11
|
+
Finished = 'finished',
|
|
12
|
+
Invalid = 'invalid',
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export enum RatioState {
|
|
9
16
|
OVER = 0,
|
|
10
17
|
UNDER = 1,
|
|
@@ -101,6 +108,7 @@ export namespace Strategies {
|
|
|
101
108
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
102
109
|
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
103
110
|
SPARK_COLLATERAL_SWITCH = 156,
|
|
111
|
+
SPARK_GENERIC_FL_COLLATERAL_SWITCH = 167,
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
export enum OptimismIds {
|
|
@@ -259,6 +267,12 @@ export namespace Bundles {
|
|
|
259
267
|
MORPHO_BLUE_EOA_BOOST_ON_PRICE = 85,
|
|
260
268
|
MORPHO_BLUE_EOA_REPAY_ON_PRICE = 86,
|
|
261
269
|
MORPHO_BLUE_EOA_CLOSE = 87,
|
|
270
|
+
SPARK_EOA_REPAY = 88,
|
|
271
|
+
SPARK_EOA_BOOST = 89,
|
|
272
|
+
SPARK_EOA_REPAY_ON_PRICE = 90,
|
|
273
|
+
SPARK_EOA_BOOST_ON_PRICE = 91,
|
|
274
|
+
SPARK_EOA_CLOSE = 92,
|
|
275
|
+
SPARK_EOA_LIQUIDATION_PROTECTION = 93,
|
|
262
276
|
}
|
|
263
277
|
|
|
264
278
|
export enum OptimismIds {
|
package/src/types/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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,
|
|
8
8
|
CloseToAssetType,
|
|
9
|
+
SubscriptionStatus,
|
|
9
10
|
} from './enums';
|
|
10
11
|
|
|
11
12
|
export type PlaceholderType = any; // TODO - fix any types
|
|
@@ -72,6 +73,24 @@ interface _SubscriptionOptions {
|
|
|
72
73
|
|
|
73
74
|
export type SubscriptionOptions = Partial<_SubscriptionOptions>;
|
|
74
75
|
|
|
76
|
+
/** Subscription record as returned by the automation API (GET /v1/subscriptions) */
|
|
77
|
+
export interface ApiSubscriptionRecord {
|
|
78
|
+
id: number,
|
|
79
|
+
wallet: EthereumAddress,
|
|
80
|
+
wallet_type: string,
|
|
81
|
+
is_enabled: boolean,
|
|
82
|
+
invalid: boolean,
|
|
83
|
+
status: SubscriptionStatus,
|
|
84
|
+
is_bundle: boolean,
|
|
85
|
+
strategy_or_bundle_id: number,
|
|
86
|
+
strategy_ids: number[],
|
|
87
|
+
sub_data_hash: string,
|
|
88
|
+
trigger_data: string[],
|
|
89
|
+
sub_data: string[],
|
|
90
|
+
block_number: number,
|
|
91
|
+
additional_triggers: string[] | null,
|
|
92
|
+
}
|
|
93
|
+
|
|
75
94
|
export declare namespace Interfaces {
|
|
76
95
|
interface ProtocolBase {
|
|
77
96
|
id: ProtocolIdentifiers.StrategiesAutomation | ProtocolIdentifiers.LegacyAutomation,
|
|
@@ -301,6 +320,8 @@ export declare namespace Position {
|
|
|
301
320
|
subId: number,
|
|
302
321
|
subIds?: number[],
|
|
303
322
|
isEnabled?: boolean,
|
|
323
|
+
/** Set only for subscriptions parsed from the automation API */
|
|
324
|
+
status?: SubscriptionStatus,
|
|
304
325
|
subHash: string,
|
|
305
326
|
blockNumber: BlockNumber,
|
|
306
327
|
protocol: Interfaces.Protocol,
|
|
@@ -369,10 +390,18 @@ export type StrategyOrBundleIds =
|
|
|
369
390
|
| typeof Bundles.ArbitrumIds[keyof typeof Bundles.ArbitrumIds]
|
|
370
391
|
| typeof Bundles.BaseIds[keyof typeof Bundles.BaseIds];
|
|
371
392
|
|
|
393
|
+
/** Fields of the Subscribe event that parsing relies on */
|
|
394
|
+
export interface SubscriptionEventData {
|
|
395
|
+
subId: string,
|
|
396
|
+
proxy: EthereumAddress,
|
|
397
|
+
subHash: string,
|
|
398
|
+
subStruct: StrategyModel.StrategySubStructOutputStruct,
|
|
399
|
+
}
|
|
400
|
+
|
|
372
401
|
export interface ParseData {
|
|
373
402
|
chainId: ChainId,
|
|
374
403
|
blockNumber: BlockNumber,
|
|
375
|
-
subscriptionEventData:
|
|
404
|
+
subscriptionEventData: SubscriptionEventData,
|
|
376
405
|
strategiesSubsData: StrategyModel.StoredSubDataStructOutputStruct,
|
|
377
406
|
}
|
|
378
407
|
|