@gearbox-protocol/sdk 15.1.0-next.6 → 15.1.0-next.8
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/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/cjs/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/cjs/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
- package/dist/cjs/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/cjs/model/charts.js +147 -0
- package/dist/cjs/model/charts.schema.js +240 -0
- package/dist/cjs/model/index.js +28 -22
- package/dist/cjs/model/liquidations.schema.js +1 -1
- package/dist/cjs/model/opportunities.schema.js +1 -1
- package/dist/cjs/model/positions.schema.js +15 -2
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +2 -6
- package/dist/cjs/new-sdk/utils/index.js +0 -1
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/cjs/offchain/positions/OffchainPositions.js +8 -11
- package/dist/cjs/preview/preview/CreditAccountState.js +14 -1
- package/dist/cjs/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/cjs/preview/preview/previewOperation.js +1 -1
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +0 -6
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/cjs/sdk/accounts/intents/testing/sdk-mock.js +31 -4
- package/dist/cjs/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +18 -0
- package/dist/cjs/sdk/accounts/intents/utils/index.js +2 -0
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +0 -3
- package/dist/cjs/sdk/index.js +12 -0
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/cjs/sdk/positions/PositionsService.js +206 -1
- package/dist/cjs/sdk/positions/calcBorrowRate.js +43 -0
- package/dist/cjs/sdk/positions/calcHealthFactor.js +44 -0
- package/dist/cjs/sdk/positions/calcLiquidationPrice.js +23 -0
- package/dist/cjs/sdk/positions/calcLiquidationPriceForTarget.js +30 -0
- package/dist/cjs/sdk/positions/calcTimeToLiquidationMs.js +18 -0
- package/dist/cjs/sdk/positions/index.js +12 -1
- package/dist/cjs/sdk/positions/types.js +31 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/calc-health-factor.js +24 -22
- package/dist/esm/common-utils/utils/creditAccount/calc-quota-borrow-rate.js +2 -0
- package/dist/esm/common-utils/utils/creditAccount/get-time-to-liquidation.js +5 -4
- package/dist/esm/common-utils/utils/creditAccount/liquidation-price.js +21 -11
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/charts.js +140 -0
- package/dist/esm/model/charts.schema.js +226 -0
- package/dist/esm/model/index.js +7 -7
- package/dist/esm/model/liquidations.schema.js +1 -1
- package/dist/esm/model/opportunities.schema.js +1 -1
- package/dist/esm/model/positions.schema.js +16 -4
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +2 -6
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +2 -6
- package/dist/esm/new-sdk/utils/index.js +0 -1
- package/dist/esm/offchain/AbstractOffchainNamespace.js +10 -7
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +4 -8
- package/dist/esm/offchain/positions/OffchainPositions.js +8 -11
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/preview/preview/CreditAccountState.js +14 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +16 -6
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +9 -2
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +11 -3
- package/dist/esm/preview/preview/previewOperation.js +1 -1
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -8
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +2 -90
- package/dist/esm/sdk/accounts/intents/testing/sdk-mock.js +31 -4
- package/dist/esm/sdk/accounts/intents/utils/adjust-state-to-snapshot.js +17 -0
- package/dist/esm/sdk/accounts/intents/utils/index.js +2 -1
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -4
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +3 -3
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/index.js +7 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +10 -3
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/positions/PositionsService.js +206 -1
- package/dist/esm/sdk/positions/calcBorrowRate.js +42 -0
- package/dist/esm/sdk/positions/calcHealthFactor.js +43 -0
- package/dist/esm/sdk/positions/calcLiquidationPrice.js +22 -0
- package/dist/esm/sdk/positions/calcLiquidationPriceForTarget.js +29 -0
- package/dist/esm/sdk/positions/calcTimeToLiquidationMs.js +17 -0
- package/dist/esm/sdk/positions/index.js +7 -2
- package/dist/esm/sdk/positions/types.js +31 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/calc-health-factor.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/calc-quota-borrow-rate.d.ts +2 -0
- package/dist/types/common-utils/utils/creditAccount/get-time-to-liquidation.d.ts +3 -0
- package/dist/types/common-utils/utils/creditAccount/liquidation-price.d.ts +3 -0
- package/dist/types/model/charts.d.ts +349 -0
- package/dist/types/model/charts.schema.d.ts +364 -0
- package/dist/types/model/index.d.ts +6 -6
- package/dist/types/model/positions.d.ts +85 -2
- package/dist/types/model/positions.schema.d.ts +26 -1
- package/dist/types/new-sdk/index.d.ts +1 -2
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -5
- package/dist/types/new-sdk/opportunities/types.d.ts +9 -7
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +4 -5
- package/dist/types/new-sdk/positions/types.d.ts +9 -9
- package/dist/types/new-sdk/utils/index.d.ts +1 -2
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +5 -21
- package/dist/types/offchain/index.d.ts +2 -2
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +8 -4
- package/dist/types/offchain/positions/OffchainPositions.d.ts +11 -5
- package/dist/types/preview/preview/CreditAccountState.d.ts +6 -0
- package/dist/types/preview/preview/buildDelayedPreview.d.ts +5 -1
- package/dist/types/preview/preview/types.d.ts +4 -2
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -7
- package/dist/types/sdk/accounts/credit-account-compressor/CreditAccountCompressor.d.ts +3 -12
- package/dist/types/sdk/accounts/credit-account-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +1 -19
- package/dist/types/sdk/accounts/index.d.ts +2 -2
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +6 -0
- package/dist/types/sdk/accounts/intents/utils/adjust-state-to-snapshot.d.ts +13 -0
- package/dist/types/sdk/accounts/intents/utils/index.d.ts +2 -1
- package/dist/types/sdk/accounts/types.d.ts +1 -12
- package/dist/types/sdk/index.d.ts +8 -3
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
- package/dist/types/sdk/market/oracle/types.d.ts +8 -0
- package/dist/types/sdk/positions/PositionsService.d.ts +31 -2
- package/dist/types/sdk/positions/calcBorrowRate.d.ts +40 -0
- package/dist/types/sdk/positions/calcHealthFactor.d.ts +45 -0
- package/dist/types/sdk/positions/calcLiquidationPrice.d.ts +12 -0
- package/dist/types/sdk/positions/calcLiquidationPriceForTarget.d.ts +43 -0
- package/dist/types/sdk/positions/calcTimeToLiquidationMs.d.ts +15 -0
- package/dist/types/sdk/positions/index.d.ts +7 -2
- package/dist/types/sdk/positions/types.d.ts +58 -1
- package/package.json +1 -1
- package/dist/cjs/model/history.js +0 -53
- package/dist/cjs/model/history.schema.js +0 -128
- package/dist/cjs/new-sdk/utils/history.js +0 -1
- package/dist/esm/model/history.js +0 -49
- package/dist/esm/model/history.schema.js +0 -116
- package/dist/esm/new-sdk/utils/history.js +0 -1
- package/dist/types/model/history.d.ts +0 -153
- package/dist/types/model/history.schema.d.ts +0 -95
- package/dist/types/new-sdk/utils/history.d.ts +0 -18
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
-
const require_model_filters_schema = require("./filters.schema.js");
|
|
4
3
|
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
4
|
+
const require_model_filters_schema = require("./filters.schema.js");
|
|
5
5
|
let zod_v4 = require("zod/v4");
|
|
6
6
|
//#region src/model/liquidations.schema.ts
|
|
7
7
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
+
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
3
4
|
const require_model_curators_schema = require("./curators.schema.js");
|
|
4
5
|
const require_model_filters = require("./filters.js");
|
|
5
6
|
const require_model_filters_schema = require("./filters.schema.js");
|
|
6
|
-
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
7
7
|
let zod_v4 = require("zod/v4");
|
|
8
8
|
//#region src/model/opportunities.schema.ts
|
|
9
9
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_zod = require("../sdk/utils/zod.js");
|
|
3
|
+
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
3
4
|
const require_model_filters = require("./filters.js");
|
|
4
5
|
const require_model_filters_schema = require("./filters.schema.js");
|
|
5
|
-
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
6
|
-
const require_model_opportunities_schema = require("./opportunities.schema.js");
|
|
7
6
|
const require_model_liquidations_schema = require("./liquidations.schema.js");
|
|
7
|
+
const require_model_opportunities_schema = require("./opportunities.schema.js");
|
|
8
8
|
let zod_v4 = require("zod/v4");
|
|
9
9
|
//#region src/model/positions.schema.ts
|
|
10
10
|
/**
|
|
@@ -73,6 +73,15 @@ const poolPositionSchema = zod_v4.z.object({
|
|
|
73
73
|
pnl: pnlBreakdownSchema.optional()
|
|
74
74
|
});
|
|
75
75
|
/**
|
|
76
|
+
* {@link BorrowRateBreakdown}
|
|
77
|
+
**/
|
|
78
|
+
const borrowRateBreakdownSchema = zod_v4.z.object({
|
|
79
|
+
total: require_model_primitives_schema.bpsSchema,
|
|
80
|
+
totalOnDebt: require_model_primitives_schema.bpsSchema,
|
|
81
|
+
base: require_model_primitives_schema.bpsSchema,
|
|
82
|
+
quotas: zod_v4.z.record(require_sdk_utils_zod.ZodAddress(), require_model_primitives_schema.bpsSchema)
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
76
85
|
* {@link StrategyPosition}
|
|
77
86
|
**/
|
|
78
87
|
const strategyPositionSchema = zod_v4.z.object({
|
|
@@ -88,6 +97,9 @@ const strategyPositionSchema = zod_v4.z.object({
|
|
|
88
97
|
totalDebt: require_model_primitives_schema.tokenAmountSchema,
|
|
89
98
|
totalValue: require_model_primitives_schema.tokenAmountSchema,
|
|
90
99
|
healthFactor: require_model_primitives_schema.bpsSchema,
|
|
100
|
+
borrowRate: borrowRateBreakdownSchema.optional(),
|
|
101
|
+
timeToLiquidation: require_sdk_utils_zod.ZodBigInt().nullable().optional(),
|
|
102
|
+
liquidationPrice: require_sdk_utils_zod.ZodBigInt().nullable().optional(),
|
|
91
103
|
pnl: pnlBreakdownSchema.optional(),
|
|
92
104
|
collaterals: zod_v4.z.array(positionCollateralSchema)
|
|
93
105
|
});
|
|
@@ -163,6 +175,7 @@ const positionKeySchema = zod_v4.z.discriminatedUnion("kind", [zod_v4.z.object({
|
|
|
163
175
|
...strategyPositionKeySchema.shape
|
|
164
176
|
})]);
|
|
165
177
|
//#endregion
|
|
178
|
+
exports.borrowRateBreakdownSchema = borrowRateBreakdownSchema;
|
|
166
179
|
exports.pnlBreakdownSchema = pnlBreakdownSchema;
|
|
167
180
|
exports.pointsProgramPnLSchema = pointsProgramPnLSchema;
|
|
168
181
|
exports.pointsRewardsPnLSchema = pointsRewardsPnLSchema;
|
|
@@ -58,12 +58,8 @@ var OpportunitiesNamespace = class extends require_new_sdk_AbstractNamespace.Abs
|
|
|
58
58
|
filter(response, filter) {
|
|
59
59
|
return require_new_sdk_utils_filterResponse.filterResponse(response, filter, require_model_opportunities.matchesOpportunityFilter);
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
opportunity: key,
|
|
64
|
-
range,
|
|
65
|
-
metric
|
|
66
|
-
}) };
|
|
61
|
+
async charts(key, metrics, range) {
|
|
62
|
+
return this.offchain.getCharts(key, metrics, range);
|
|
67
63
|
}
|
|
68
64
|
};
|
|
69
65
|
//#endregion
|
|
@@ -40,12 +40,8 @@ var PositionsNamespace = class extends require_new_sdk_AbstractNamespace.Abstrac
|
|
|
40
40
|
filter(response, filter) {
|
|
41
41
|
return require_new_sdk_utils_filterResponse.filterResponse(response, filter, require_model_positions.matchesPositionFilter);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
return
|
|
45
|
-
position: key,
|
|
46
|
-
range,
|
|
47
|
-
metric
|
|
48
|
-
}) };
|
|
43
|
+
async charts(key, metrics, range) {
|
|
44
|
+
return this.offchain.getCharts(key, metrics, range);
|
|
49
45
|
}
|
|
50
46
|
};
|
|
51
47
|
//#endregion
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_new_sdk_utils_filterResponse = require("./filterResponse.js");
|
|
3
|
-
require("./history.js");
|
|
4
3
|
const require_new_sdk_utils_mergeChains = require("./mergeChains.js");
|
|
5
4
|
exports.DEFAULT_MAX_OFFCHAIN_LAG = require_new_sdk_utils_mergeChains.DEFAULT_MAX_OFFCHAIN_LAG;
|
|
6
5
|
exports.filterResponse = require_new_sdk_utils_filterResponse.filterResponse;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_model_charts_schema = require("../model/charts.schema.js");
|
|
3
3
|
const require_model_response_schema = require("../model/response.schema.js");
|
|
4
4
|
const require_offchain_errors_OffchainInvalidJsonError = require("./errors/OffchainInvalidJsonError.js");
|
|
5
5
|
const require_offchain_errors_OffchainNotConfiguredError = require("./errors/OffchainNotConfiguredError.js");
|
|
@@ -65,14 +65,17 @@ var AbstractOffchainNamespace = class {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
/**
|
|
68
|
-
* Reads
|
|
69
|
-
*
|
|
68
|
+
* Reads the charts of one subject: one series per metric named, onto the one
|
|
69
|
+
* grid that lets them be compared at an index.
|
|
70
70
|
**/
|
|
71
|
-
async
|
|
71
|
+
async readCharts(path, metrics, range) {
|
|
72
72
|
return this.get({
|
|
73
|
-
path
|
|
74
|
-
query:
|
|
75
|
-
|
|
73
|
+
path,
|
|
74
|
+
query: zod_v4.z.encode(require_model_charts_schema.chartQueryCodec, {
|
|
75
|
+
metrics,
|
|
76
|
+
range
|
|
77
|
+
}),
|
|
78
|
+
schema: require_model_charts_schema.chartBundleSchemaFor(metrics, range)
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
/**
|
|
@@ -44,14 +44,10 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* Charts of one opportunity: one series per metric, on a shared grid.
|
|
48
48
|
**/
|
|
49
|
-
async
|
|
50
|
-
return this.
|
|
51
|
-
path: `${this.#historyRoot(query.opportunity)}/history/${query.metric}`,
|
|
52
|
-
metric: query.metric,
|
|
53
|
-
range: query.range
|
|
54
|
-
});
|
|
49
|
+
async getCharts(key, metrics, range) {
|
|
50
|
+
return this.readCharts(`${this.#chartRoot(key)}/charts`, metrics, range);
|
|
55
51
|
}
|
|
56
52
|
#poolPath(key) {
|
|
57
53
|
return `${this.#root}/pools/${key.chainId}/${key.pool}`;
|
|
@@ -59,7 +55,7 @@ var OffchainOpportunities = class extends require_offchain_AbstractOffchainNames
|
|
|
59
55
|
#strategyPath(key) {
|
|
60
56
|
return `${this.#root}/strategies/${key.chainId}/${key.creditManager}/${key.targetCollateral}`;
|
|
61
57
|
}
|
|
62
|
-
#
|
|
58
|
+
#chartRoot(key) {
|
|
63
59
|
return key.kind === "pool" ? this.#poolPath(key) : this.#strategyPath(key);
|
|
64
60
|
}
|
|
65
61
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_model_positions_schema = require("../../model/positions.schema.js");
|
|
3
|
+
const require_offchain_errors_OffchainNotImplementedError = require("../errors/OffchainNotImplementedError.js");
|
|
4
|
+
require("../errors/index.js");
|
|
3
5
|
const require_offchain_AbstractOffchainNamespace = require("../AbstractOffchainNamespace.js");
|
|
4
6
|
let zod_v4 = require("zod/v4");
|
|
5
7
|
//#region src/offchain/positions/OffchainPositions.ts
|
|
@@ -25,19 +27,14 @@ var OffchainPositions = class extends require_offchain_AbstractOffchainNamespace
|
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
|
-
*
|
|
30
|
+
* Charts of one position: one series per metric, on a shared grid.
|
|
29
31
|
*
|
|
30
|
-
* @
|
|
32
|
+
* @throws {OffchainNotImplementedError} Until the backend serves it. An empty
|
|
33
|
+
* bundle would be the one answer this model exists to rule out: a chart that
|
|
34
|
+
* could not be read is not a chart with no points.
|
|
31
35
|
**/
|
|
32
|
-
async
|
|
33
|
-
|
|
34
|
-
data: {
|
|
35
|
-
metric: query.metric,
|
|
36
|
-
points: [],
|
|
37
|
-
metadata: {}
|
|
38
|
-
},
|
|
39
|
-
meta: { chains: [] }
|
|
40
|
-
};
|
|
36
|
+
async getCharts(key, _metrics, _range) {
|
|
37
|
+
throw new require_offchain_errors_OffchainNotImplementedError.OffchainNotImplementedError(`${this.#root}/${key.chainId}/charts`);
|
|
41
38
|
}
|
|
42
39
|
};
|
|
43
40
|
//#endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_utils_AssetsMap = require("../../sdk/utils/AssetsMap.js");
|
|
3
|
-
require("../../sdk/constants/math.js");
|
|
3
|
+
const require_sdk_constants_math = require("../../sdk/constants/math.js");
|
|
4
4
|
require("../../sdk/index.js");
|
|
5
5
|
let viem = require("viem");
|
|
6
6
|
//#region src/preview/preview/CreditAccountState.ts
|
|
@@ -79,6 +79,19 @@ var CreditAccountState = class CreditAccountState {
|
|
|
79
79
|
totalDebt: ca.debt + ca.accruedInterest + ca.accruedFees
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Immutable snapshot of this projected state for `sdk.positions` metric
|
|
84
|
+
* methods: dust-filtered balances, all quotas, and {@link totalDebt}.
|
|
85
|
+
**/
|
|
86
|
+
toSnapshot(totalValue) {
|
|
87
|
+
return {
|
|
88
|
+
creditManager: this.creditManager,
|
|
89
|
+
assets: this.balances.toAssets(require_sdk_constants_math.DUST_THRESHOLD),
|
|
90
|
+
quotas: this.quotas.toAssets(0n),
|
|
91
|
+
totalDebt: this.totalDebt,
|
|
92
|
+
totalValue
|
|
93
|
+
};
|
|
94
|
+
}
|
|
82
95
|
clone() {
|
|
83
96
|
return new CreditAccountState({
|
|
84
97
|
creditAccount: this.creditAccount,
|
|
@@ -26,8 +26,10 @@ let viem = require("viem");
|
|
|
26
26
|
* @param receivedToken - Token the `CLOSE_ACCOUNT` resume withdraws to the
|
|
27
27
|
* user: the unwrapped underlying (vault asset) for RWA markets, the
|
|
28
28
|
* underlying itself otherwise.
|
|
29
|
+
* @param sdk - Market data source for the position metrics of the resulting
|
|
30
|
+
* state; read synchronously, no network access.
|
|
29
31
|
*/
|
|
30
|
-
function buildDelayedPreview(afterInstant, before, detected, convert, receivedToken) {
|
|
32
|
+
function buildDelayedPreview(afterInstant, before, detected, convert, receivedToken, sdk) {
|
|
31
33
|
const { request, intent } = detected;
|
|
32
34
|
const post = afterInstant.clone();
|
|
33
35
|
const converter = makeSafeConverter(convert);
|
|
@@ -40,7 +42,7 @@ function buildDelayedPreview(afterInstant, before, detected, convert, receivedTo
|
|
|
40
42
|
break;
|
|
41
43
|
case "WITHDRAW_COLLATERAL": applyWithdrawCollateral(post, request, intent, converter, collateralWithdrawn);
|
|
42
44
|
}
|
|
43
|
-
return buildAdjustPreview(post, before, collateralWithdrawn, converter);
|
|
45
|
+
return buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk);
|
|
44
46
|
}
|
|
45
47
|
function makeSafeConverter(convert) {
|
|
46
48
|
let error;
|
|
@@ -172,8 +174,11 @@ function buildClosePreview(post, converter, receivedToken) {
|
|
|
172
174
|
error: converter.error
|
|
173
175
|
};
|
|
174
176
|
}
|
|
175
|
-
function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
|
|
177
|
+
function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
|
|
176
178
|
const totalValue = totalValueInUnderlying(post, converter.convert, require_sdk_constants_math.DUST_THRESHOLD);
|
|
179
|
+
const assets = post.balances.toAssets(require_sdk_constants_math.DUST_THRESHOLD);
|
|
180
|
+
const quotas = post.quotas.toAssets(0n);
|
|
181
|
+
const snap = post.toSnapshot(totalValue);
|
|
177
182
|
return {
|
|
178
183
|
operation: "AdjustCreditAccount",
|
|
179
184
|
creditManager: post.creditManager,
|
|
@@ -183,11 +188,16 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter) {
|
|
|
183
188
|
totalValue,
|
|
184
189
|
debt: post.debt,
|
|
185
190
|
debtChange: post.debt - before.debt,
|
|
186
|
-
quotas
|
|
191
|
+
quotas,
|
|
187
192
|
quotasChange: post.quotas.difference(before.quotas).toAssets(),
|
|
188
|
-
assets
|
|
193
|
+
assets,
|
|
189
194
|
assetsChange: post.balances.difference(before.balances).toAssets(require_sdk_constants_math.DUST_THRESHOLD),
|
|
190
|
-
error: converter.error
|
|
195
|
+
error: converter.error,
|
|
196
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
197
|
+
overallApy: 0,
|
|
198
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
199
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
200
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
191
201
|
};
|
|
192
202
|
}
|
|
193
203
|
//#endregion
|
|
@@ -22,6 +22,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
22
22
|
const { assets: collateralAdded, error: unwrapError } = require_preview_preview_unwrapNativeCollateral.unwrapNativeCollateral(after.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(require_sdk_constants_address_provider.AP_WETH_TOKEN, 0));
|
|
23
23
|
error ??= unwrapError;
|
|
24
24
|
const assets = account.balances.toAssets(require_sdk_constants_math.DUST_THRESHOLD);
|
|
25
|
+
const quotas = account.quotas.toAssets(0n);
|
|
25
26
|
const assetsChange = account.balances.difference(before.balances).toAssets(require_sdk_constants_math.DUST_THRESHOLD);
|
|
26
27
|
const totalValue = assets.reduce((acc, { token, balance }) => {
|
|
27
28
|
try {
|
|
@@ -34,6 +35,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
34
35
|
return acc;
|
|
35
36
|
}
|
|
36
37
|
}, 0n);
|
|
38
|
+
const snap = account.toSnapshot(totalValue);
|
|
37
39
|
return {
|
|
38
40
|
operation: "AdjustCreditAccount",
|
|
39
41
|
creditManager: operation.creditManager,
|
|
@@ -43,11 +45,16 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
43
45
|
totalValue,
|
|
44
46
|
debt: account.debt,
|
|
45
47
|
debtChange: account.debt - before.debt,
|
|
46
|
-
quotas
|
|
48
|
+
quotas,
|
|
47
49
|
quotasChange: account.quotas.difference(before.quotas).toAssets(),
|
|
48
50
|
assets,
|
|
49
51
|
assetsChange,
|
|
50
|
-
error
|
|
52
|
+
error,
|
|
53
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
54
|
+
overallApy: 0,
|
|
55
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
56
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
57
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
51
58
|
};
|
|
52
59
|
}
|
|
53
60
|
//#endregion
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sdk_constants_address_provider = require("../../sdk/constants/address-provider.js");
|
|
3
|
+
const require_sdk_constants_math = require("../../sdk/constants/math.js");
|
|
3
4
|
require("../../sdk/index.js");
|
|
4
5
|
const require_preview_preview_types = require("./types.js");
|
|
5
6
|
const require_preview_preview_CreditAccountState = require("./CreditAccountState.js");
|
|
@@ -26,7 +27,9 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
26
27
|
});
|
|
27
28
|
const { assets: collateral, error: unwrapError } = require_preview_preview_unwrapNativeCollateral.unwrapNativeCollateral(state.collateralAdded.toAssets(), value, sdk.addressProvider.getAddress(require_sdk_constants_address_provider.AP_WETH_TOKEN, 0));
|
|
28
29
|
error ??= unwrapError ?? priceError;
|
|
29
|
-
const assets = account.balances.toAssets(
|
|
30
|
+
const assets = account.balances.toAssets(require_sdk_constants_math.DUST_THRESHOLD);
|
|
31
|
+
const quotas = account.quotas.toAssets(0n);
|
|
32
|
+
const snap = account.toSnapshot(collateralValue + account.totalDebt);
|
|
30
33
|
return {
|
|
31
34
|
operation: operation.operation,
|
|
32
35
|
creditManager: operation.creditManager,
|
|
@@ -34,9 +37,14 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
34
37
|
collateral,
|
|
35
38
|
collateralValue,
|
|
36
39
|
debt: account.debt,
|
|
37
|
-
quotas
|
|
40
|
+
quotas,
|
|
38
41
|
assets,
|
|
39
|
-
error
|
|
42
|
+
error,
|
|
43
|
+
healthFactor: sdk.positions.healthFactor(snap),
|
|
44
|
+
overallApy: 0,
|
|
45
|
+
borrowRate: sdk.positions.borrowRate(snap),
|
|
46
|
+
timeToLiquidation: sdk.positions.timeToLiquidation(snap),
|
|
47
|
+
liquidationPrice: sdk.positions.liquidationPrice(snap)
|
|
40
48
|
};
|
|
41
49
|
}
|
|
42
50
|
/**
|
|
@@ -70,7 +70,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
70
70
|
creditManager: operation.creditManager,
|
|
71
71
|
intent: delayed.intent,
|
|
72
72
|
instantPreview,
|
|
73
|
-
delayedPreview: require_preview_preview_buildDelayedPreview.buildDelayedPreview(after.account, before, delayed, convert, receivedToken)
|
|
73
|
+
delayedPreview: require_preview_preview_buildDelayedPreview.buildDelayedPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
//#endregion
|
|
@@ -57,12 +57,6 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
57
57
|
return this.#compressor.getBorrowerCreditAccounts(borrower, options, blockNumber);
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* {@inheritDoc ICreditAccountsService.listPositions}
|
|
61
|
-
**/
|
|
62
|
-
async listPositions(props) {
|
|
63
|
-
return this.#compressor.listPositions(props);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
60
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
67
61
|
**/
|
|
68
62
|
async getRewards(creditAccount) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_sdk_utils_AddressMap = require("../../utils/AddressMap.js");
|
|
3
2
|
const require_sdk_utils_AddressSet = require("../../utils/AddressSet.js");
|
|
4
3
|
const require_sdk_constants_address_provider = require("../../constants/address-provider.js");
|
|
5
4
|
const require_sdk_constants_addresses = require("../../constants/addresses.js");
|
|
@@ -10,11 +9,8 @@ const require_sdk_utils_hex = require("../../utils/hex.js");
|
|
|
10
9
|
require("../../utils/index.js");
|
|
11
10
|
const require_sdk_base_SDKConstruct = require("../../base/SDKConstruct.js");
|
|
12
11
|
require("../../base/index.js");
|
|
13
|
-
const require_sdk_market_math = require("../../market/math.js");
|
|
14
|
-
const require_sdk_market_credit_dominantCollateral = require("../../market/credit/dominantCollateral.js");
|
|
15
12
|
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../../utils/viem/simulateWithPriceUpdates.js");
|
|
16
13
|
require("../../utils/viem/index.js");
|
|
17
|
-
require("../../market/index.js");
|
|
18
14
|
const require_abi_rwa_iRWAFactory = require("../../../abi/rwa/iRWAFactory.js");
|
|
19
15
|
const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./CreditAccountCompressorV310Contract.js");
|
|
20
16
|
//#region src/sdk/accounts/credit-account-compressor/CreditAccountCompressor.ts
|
|
@@ -22,9 +18,8 @@ const require_sdk_accounts_credit_account_compressor_CreditAccountCompressorV310
|
|
|
22
18
|
* Reads credit accounts of the current chain.
|
|
23
19
|
*
|
|
24
20
|
* Stitches the credit account compressor together with the RWA factories (for
|
|
25
|
-
* accounts owned via an investor EOA) and
|
|
26
|
-
*
|
|
27
|
-
* either as raw account data or as {@link StrategyPosition}s.
|
|
21
|
+
* accounts owned via an investor EOA), and describes the result as raw
|
|
22
|
+
* account data.
|
|
28
23
|
*
|
|
29
24
|
* TODO: create and deploy new compressor contract onchain to avoid all this stitching
|
|
30
25
|
**/
|
|
@@ -174,89 +169,6 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
|
|
|
174
169
|
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
175
170
|
}
|
|
176
171
|
/**
|
|
177
|
-
* Describes all credit accounts of a wallet as strategy positions.
|
|
178
|
-
*
|
|
179
|
-
* @param props - {@link ListStrategyPositionsProps}
|
|
180
|
-
**/
|
|
181
|
-
async listPositions(props) {
|
|
182
|
-
const { owner, includeZeroDebt, blockNumber } = props;
|
|
183
|
-
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber), this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber)]);
|
|
184
|
-
const describable = accounts.filter((ca) => {
|
|
185
|
-
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
186
|
-
return ca.success;
|
|
187
|
-
});
|
|
188
|
-
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
|
|
189
|
-
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Builds one strategy position from an account snapshot.
|
|
193
|
-
*
|
|
194
|
-
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
195
|
-
* phantom token that represents them on it.
|
|
196
|
-
**/
|
|
197
|
-
#toStrategyPosition(ca, withdrawals) {
|
|
198
|
-
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
199
|
-
const { market } = suite;
|
|
200
|
-
const { priceOracle } = market;
|
|
201
|
-
const { pool } = market.pool;
|
|
202
|
-
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
203
|
-
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
204
|
-
const collateral = require_sdk_market_credit_dominantCollateral.dominantCollateral(ca, market);
|
|
205
|
-
return {
|
|
206
|
-
kind: "strategy",
|
|
207
|
-
chainId: this.sdk.chainId,
|
|
208
|
-
creditManager: ca.creditManager,
|
|
209
|
-
creditAccount: ca.creditAccount,
|
|
210
|
-
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
211
|
-
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
212
|
-
leverage: require_sdk_market_math.calcPositionLeverage(ca.totalValue, totalDebtValue),
|
|
213
|
-
borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
214
|
-
totalDebt: {
|
|
215
|
-
token,
|
|
216
|
-
value: totalDebtValue,
|
|
217
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
|
|
218
|
-
},
|
|
219
|
-
totalValue: {
|
|
220
|
-
token,
|
|
221
|
-
value: ca.totalValue,
|
|
222
|
-
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
223
|
-
},
|
|
224
|
-
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
225
|
-
collaterals: ca.tokens.flatMap((t) => {
|
|
226
|
-
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
227
|
-
return [{
|
|
228
|
-
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
229
|
-
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
230
|
-
withdrawals: withdrawals.get(t.token) ?? []
|
|
231
|
-
}];
|
|
232
|
-
})
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
237
|
-
* represents them on it, so that each collateral row can pick up its own.
|
|
238
|
-
**/
|
|
239
|
-
async #accountWithdrawals(ca, blockNumber) {
|
|
240
|
-
const compressor = this.sdk.withdrawalCompressor;
|
|
241
|
-
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
242
|
-
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
243
|
-
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
244
|
-
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
245
|
-
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
|
|
246
|
-
const add = (w, outputs, claimableAt) => {
|
|
247
|
-
const assets = outputs.map((o) => ({
|
|
248
|
-
isDelayed: true,
|
|
249
|
-
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
250
|
-
redeemer: w.redeemer,
|
|
251
|
-
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
252
|
-
}));
|
|
253
|
-
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
254
|
-
};
|
|
255
|
-
for (const w of claimable) add(w, w.outputs);
|
|
256
|
-
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
257
|
-
return byPhantomToken;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
172
|
* Credit account compressor contract of the current chain.
|
|
261
173
|
*
|
|
262
174
|
* Resolved on every access, because the address provider is only populated
|
|
@@ -84,11 +84,37 @@ function buildMockSdk(args) {
|
|
|
84
84
|
quotaIncreaseFee: 0n,
|
|
85
85
|
...q
|
|
86
86
|
})) };
|
|
87
|
-
const
|
|
87
|
+
const quotaOf = (token) => args.quotas[token.toLowerCase()] ?? args.quotas[token];
|
|
88
|
+
const liquidationThresholds = {
|
|
89
|
+
entries: () => Object.entries(args.liquidationThresholds),
|
|
90
|
+
get: (token) => args.liquidationThresholds[token.toLowerCase()] ?? args.liquidationThresholds[token]
|
|
91
|
+
};
|
|
88
92
|
const market = {
|
|
89
|
-
priceOracle: {
|
|
93
|
+
priceOracle: {
|
|
94
|
+
convert,
|
|
95
|
+
convertToUSD: (token, amount) => {
|
|
96
|
+
const from = token.toLowerCase();
|
|
97
|
+
const price = args.prices[from] ?? args.prices[token];
|
|
98
|
+
if (price === void 0) throw new Error(`mock priceOracle: missing price for ${from}`);
|
|
99
|
+
return amount * price / 10n ** BigInt(decimalsOf(from));
|
|
100
|
+
},
|
|
101
|
+
safeConvertToUSD: (token, amount) => {
|
|
102
|
+
const from = token.toLowerCase();
|
|
103
|
+
const price = args.prices[from] ?? args.prices[token];
|
|
104
|
+
if (price === void 0) return null;
|
|
105
|
+
return amount * price / 10n ** BigInt(decimalsOf(from));
|
|
106
|
+
}
|
|
107
|
+
},
|
|
90
108
|
pool: {
|
|
91
|
-
pqk: {
|
|
109
|
+
pqk: {
|
|
110
|
+
quotas,
|
|
111
|
+
quotaRate: (token) => Number(quotaOf(token)?.rate ?? 0n),
|
|
112
|
+
hasActiveQuota: (token) => {
|
|
113
|
+
const q = quotaOf(token);
|
|
114
|
+
return !!q?.isActive && q.limit > 0n;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
pool: { baseInterestRate: args.baseInterestRate ?? 0n },
|
|
92
118
|
underlying: args.underlying
|
|
93
119
|
}
|
|
94
120
|
};
|
|
@@ -96,7 +122,8 @@ function buildMockSdk(args) {
|
|
|
96
122
|
creditManager: {
|
|
97
123
|
address: args.creditManager,
|
|
98
124
|
liquidationThresholds,
|
|
99
|
-
collateralTokens: []
|
|
125
|
+
collateralTokens: [],
|
|
126
|
+
feeInterest: args.feeInterest ?? 0
|
|
100
127
|
},
|
|
101
128
|
creditFacade: {
|
|
102
129
|
address: args.creditFacade,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/sdk/accounts/intents/utils/adjust-state-to-snapshot.ts
|
|
3
|
+
/**
|
|
4
|
+
* Maps an intents {@link AdjustState} onto the {@link AccountSnapshot} that
|
|
5
|
+
* position-metric functions take. `accountDebt` is treated as total debt
|
|
6
|
+
* (principal plus accrued interest and fees).
|
|
7
|
+
**/
|
|
8
|
+
function adjustStateToSnapshot(creditManager, state) {
|
|
9
|
+
return {
|
|
10
|
+
creditManager,
|
|
11
|
+
assets: state.assets,
|
|
12
|
+
quotas: Object.values(state.quotas),
|
|
13
|
+
totalDebt: state.accountDebt,
|
|
14
|
+
totalValue: state.totalValue
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.adjustStateToSnapshot = adjustStateToSnapshot;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_intents_utils_adjust_state_to_snapshot = require("./adjust-state-to-snapshot.js");
|
|
2
3
|
const require_sdk_accounts_intents_utils_assemble_operation_calls = require("./assemble-operation-calls.js");
|
|
3
4
|
const require_sdk_accounts_intents_utils_borrowed_amount_plus_interest_and_fees = require("./borrowed-amount-plus-interest-and-fees.js");
|
|
4
5
|
const require_sdk_accounts_intents_utils_common = require("./common.js");
|
|
@@ -7,6 +8,7 @@ const require_sdk_accounts_intents_utils_quotas_for_update = require("./quotas-f
|
|
|
7
8
|
const require_sdk_accounts_intents_utils_simulate_assets = require("./simulate-assets.js");
|
|
8
9
|
const require_sdk_accounts_intents_utils_simulate_adjust_state = require("./simulate-adjust-state.js");
|
|
9
10
|
const require_sdk_accounts_intents_utils_with_quota_update = require("./with-quota-update.js");
|
|
11
|
+
exports.adjustStateToSnapshot = require_sdk_accounts_intents_utils_adjust_state_to_snapshot.adjustStateToSnapshot;
|
|
10
12
|
exports.assembleOperationCalls = require_sdk_accounts_intents_utils_assemble_operation_calls.assembleOperationCalls;
|
|
11
13
|
exports.calcBorrowedAmountPlusInterestAndFees = require_sdk_accounts_intents_utils_borrowed_amount_plus_interest_and_fees.calcBorrowedAmountPlusInterestAndFees;
|
|
12
14
|
exports.convertAmount = require_sdk_accounts_intents_utils_convert_amount.convertAmount;
|
|
@@ -33,7 +33,6 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
33
33
|
* Accounts whose collateral computation failed are excluded.
|
|
34
34
|
**/
|
|
35
35
|
async getLiquidatableAccounts(props) {
|
|
36
|
-
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, props?.blockNumber);
|
|
37
36
|
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
38
37
|
maxHealthFactor: require_sdk_constants_math.WAD - 1n,
|
|
39
38
|
includeZeroDebt: false
|
|
@@ -60,7 +59,6 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
60
59
|
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
61
60
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
62
61
|
const { priceOracle } = suite.market;
|
|
63
|
-
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber);
|
|
64
62
|
const account = this.#buildAccount(ca, suite);
|
|
65
63
|
const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
|
|
66
64
|
return {
|
|
@@ -97,7 +95,6 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
97
95
|
async getLiquidationPositions(props) {
|
|
98
96
|
const compressor = this.sdk.withdrawalCompressor;
|
|
99
97
|
if (!compressor) return [];
|
|
100
|
-
await compressor.loadWithdrawableAssets(void 0, props.blockNumber);
|
|
101
98
|
const phantomTokens = new require_sdk_utils_AddressSet.AddressSet(compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken));
|
|
102
99
|
const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals({
|
|
103
100
|
account: props.liquidator,
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -139,7 +139,13 @@ const require_sdk_plugins_errors = require("./plugins/errors.js");
|
|
|
139
139
|
require("./plugins/index.js");
|
|
140
140
|
const require_sdk_pools_PoolService = require("./pools/PoolService.js");
|
|
141
141
|
require("./pools/index.js");
|
|
142
|
+
const require_sdk_positions_calcBorrowRate = require("./positions/calcBorrowRate.js");
|
|
143
|
+
const require_sdk_positions_calcHealthFactor = require("./positions/calcHealthFactor.js");
|
|
144
|
+
const require_sdk_positions_calcLiquidationPriceForTarget = require("./positions/calcLiquidationPriceForTarget.js");
|
|
145
|
+
const require_sdk_positions_calcLiquidationPrice = require("./positions/calcLiquidationPrice.js");
|
|
146
|
+
const require_sdk_positions_calcTimeToLiquidationMs = require("./positions/calcTimeToLiquidationMs.js");
|
|
142
147
|
const require_sdk_positions_MultichainPositionsService = require("./positions/MultichainPositionsService.js");
|
|
148
|
+
const require_sdk_positions_types = require("./positions/types.js");
|
|
143
149
|
const require_sdk_positions_PositionsService = require("./positions/PositionsService.js");
|
|
144
150
|
require("./positions/index.js");
|
|
145
151
|
const require_sdk_router_helpers = require("./router/helpers.js");
|
|
@@ -327,14 +333,20 @@ exports.ZeroPriceFeedContract = require_sdk_market_pricefeeds_ZeroPriceFeed.Zero
|
|
|
327
333
|
exports.ZodAddress = require_sdk_utils_zod.ZodAddress;
|
|
328
334
|
exports.ZodBigInt = require_sdk_utils_zod.ZodBigInt;
|
|
329
335
|
exports.ZodHex = require_sdk_utils_zod.ZodHex;
|
|
336
|
+
exports.accountSnapshotFromCreditAccountData = require_sdk_positions_types.accountSnapshotFromCreditAccountData;
|
|
330
337
|
exports.assetsMap = require_sdk_router_helpers.assetsMap;
|
|
331
338
|
exports.attachOptionsSchema = require_sdk_options.attachOptionsSchema;
|
|
332
339
|
exports.botPermissionsToString = require_sdk_constants_bot_permissions.botPermissionsToString;
|
|
333
340
|
exports.bytes32ToString = require_sdk_utils_bytes32ToString.bytes32ToString;
|
|
334
341
|
exports.calcAdditionalBorrowApy = require_sdk_market_math.calcAdditionalBorrowApy;
|
|
335
342
|
exports.calcBorrowApy = require_sdk_market_math.calcBorrowApy;
|
|
343
|
+
exports.calcBorrowRate = require_sdk_positions_calcBorrowRate.calcBorrowRate;
|
|
344
|
+
exports.calcHealthFactor = require_sdk_positions_calcHealthFactor.calcHealthFactor;
|
|
345
|
+
exports.calcLiquidationPrice = require_sdk_positions_calcLiquidationPrice.calcLiquidationPrice;
|
|
346
|
+
exports.calcLiquidationPriceForTarget = require_sdk_positions_calcLiquidationPriceForTarget.calcLiquidationPriceForTarget;
|
|
336
347
|
exports.calcMaxLeverage = require_sdk_market_math.calcMaxLeverage;
|
|
337
348
|
exports.calcPositionLeverage = require_sdk_market_math.calcPositionLeverage;
|
|
349
|
+
exports.calcTimeToLiquidationMs = require_sdk_positions_calcTimeToLiquidationMs.calcTimeToLiquidationMs;
|
|
338
350
|
exports.calcUtilization = require_sdk_market_math.calcUtilization;
|
|
339
351
|
exports.chains = require_sdk_chain_chains.chains;
|
|
340
352
|
exports.childLogger = require_sdk_utils_childLogger.childLogger;
|