@gearbox-protocol/sdk 14.12.0-next.80 → 14.12.0-next.81
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/model/index.js +8 -0
- package/dist/cjs/model/response.js +1 -0
- package/dist/cjs/model/response.schema.js +61 -0
- package/dist/cjs/offchain/AbstractOffchainNamespace.js +3 -3
- package/dist/cjs/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +26 -20
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +3 -2
- package/dist/cjs/sdk/market/rwa/RWARegistry.js +4 -2
- package/dist/cjs/sdk/pools/PoolService.js +2 -1
- package/dist/cjs/sdk/positions/PositionsService.js +11 -4
- package/dist/esm/model/index.js +3 -1
- package/dist/esm/model/response.js +1 -0
- package/dist/esm/model/response.schema.js +55 -0
- package/dist/esm/offchain/AbstractOffchainNamespace.js +3 -3
- package/dist/esm/sdk/accounts/credit-account-compressor/CreditAccountCompressor.js +6 -6
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +26 -20
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +7 -5
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +3 -2
- package/dist/esm/sdk/market/rwa/RWARegistry.js +4 -2
- package/dist/esm/sdk/pools/PoolService.js +2 -1
- package/dist/esm/sdk/positions/PositionsService.js +11 -4
- package/dist/types/model/index.d.ts +3 -1
- package/dist/types/model/response.d.ts +104 -0
- package/dist/types/model/response.schema.d.ts +89 -0
- package/dist/types/offchain/AbstractOffchainNamespace.d.ts +3 -3
- package/dist/types/sdk/accounts/credit-account-compressor/types.d.ts +4 -0
- package/dist/types/sdk/accounts/index.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/LiquidationsService.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/types.d.ts +28 -6
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +4 -4
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +2 -2
- package/dist/types/sdk/accounts/withdrawal-compressor/index.d.ts +2 -2
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +26 -4
- package/dist/types/sdk/index.d.ts +4 -4
- package/dist/types/sdk/market/rwa/RWARegistry.d.ts +2 -1
- package/dist/types/sdk/pools/types.d.ts +4 -0
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +1 -1
- package/dist/types/sdk/positions/index.d.ts +2 -2
- package/dist/types/sdk/positions/types.d.ts +14 -5
- package/dist/types/sdk/types/index.d.ts +2 -2
- package/dist/types/sdk/types/multichain.d.ts +16 -1
- package/package.json +1 -1
package/dist/cjs/model/index.js
CHANGED
|
@@ -13,6 +13,8 @@ const require_model_liquidations = require("./liquidations.js");
|
|
|
13
13
|
const require_model_opportunities = require("./opportunities.js");
|
|
14
14
|
const require_model_positions = require("./positions.js");
|
|
15
15
|
require("./primitives.js");
|
|
16
|
+
require("./response.js");
|
|
17
|
+
const require_model_response_schema = require("./response.schema.js");
|
|
16
18
|
exports.FILTER_ALL = require_model_filters.FILTER_ALL;
|
|
17
19
|
exports.POOL_HISTORY_METRICS = require_model_history.POOL_HISTORY_METRICS;
|
|
18
20
|
exports.POOL_POSITION_HISTORY_METRICS = require_model_history.POOL_POSITION_HISTORY_METRICS;
|
|
@@ -23,9 +25,13 @@ exports.apyBreakdownSchema = require_model_opportunities_schema.apyBreakdownSche
|
|
|
23
25
|
exports.assetTypeSchema = require_model_primitives_schema.assetTypeSchema;
|
|
24
26
|
exports.booleanParamSchema = require_model_filters_schema.booleanParamSchema;
|
|
25
27
|
exports.bpsSchema = require_model_primitives_schema.bpsSchema;
|
|
28
|
+
exports.chainFailedSchema = require_model_response_schema.chainFailedSchema;
|
|
26
29
|
exports.chainIdSchema = require_model_primitives_schema.chainIdSchema;
|
|
30
|
+
exports.chainMetadataSchema = require_model_response_schema.chainMetadataSchema;
|
|
31
|
+
exports.chainSucceededSchema = require_model_response_schema.chainSucceededSchema;
|
|
27
32
|
exports.curatorNameSchema = require_model_curators_schema.curatorNameSchema;
|
|
28
33
|
exports.curatorSchema = require_model_curators_schema.curatorSchema;
|
|
34
|
+
exports.dataSourceSchema = require_model_response_schema.dataSourceSchema;
|
|
29
35
|
exports.delayedReceivedAssetSchema = require_model_liquidations_schema.delayedReceivedAssetSchema;
|
|
30
36
|
exports.filterAllSchema = require_model_filters_schema.filterAllSchema;
|
|
31
37
|
exports.filterable = require_model_filters_schema.filterable;
|
|
@@ -84,6 +90,8 @@ exports.quotaAssetSchema = require_model_opportunities_schema.quotaAssetSchema;
|
|
|
84
90
|
exports.rateCurvePointSchema = require_model_opportunities_schema.rateCurvePointSchema;
|
|
85
91
|
exports.rateCurveSchema = require_model_opportunities_schema.rateCurveSchema;
|
|
86
92
|
exports.receivedAssetSchema = require_model_liquidations_schema.receivedAssetSchema;
|
|
93
|
+
exports.responseMetadataSchema = require_model_response_schema.responseMetadataSchema;
|
|
94
|
+
exports.responseSchema = require_model_response_schema.responseSchema;
|
|
87
95
|
exports.rewardsPnLSchema = require_model_positions_schema.rewardsPnLSchema;
|
|
88
96
|
exports.rewardsSchema = require_model_opportunities_schema.rewardsSchema;
|
|
89
97
|
exports.strategyHistoryMetricSchema = require_model_history_schema.strategyHistoryMetricSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_model_primitives_schema = require("./primitives.schema.js");
|
|
3
|
+
let zod_v4 = require("zod/v4");
|
|
4
|
+
//#region src/model/response.schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* Runtime schemas for {@link ./response.js}, see the note in
|
|
7
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
8
|
+
*
|
|
9
|
+
* `responseSchema(payloadSchema)` validates a successful backend 2xx body.
|
|
10
|
+
* HTTP and transport errors never pass through it.
|
|
11
|
+
**/
|
|
12
|
+
/**
|
|
13
|
+
* {@link DataSource}
|
|
14
|
+
**/
|
|
15
|
+
const dataSourceSchema = zod_v4.z.union([zod_v4.z.literal("onchain"), zod_v4.z.literal("offchain")]);
|
|
16
|
+
/**
|
|
17
|
+
* {@link ChainSucceeded}
|
|
18
|
+
**/
|
|
19
|
+
const chainSucceededSchema = zod_v4.z.object({
|
|
20
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
21
|
+
status: zod_v4.z.literal("success"),
|
|
22
|
+
source: dataSourceSchema,
|
|
23
|
+
blockNumber: zod_v4.z.number().int().nonnegative().optional(),
|
|
24
|
+
timestamp: require_model_primitives_schema.timestampSchema.optional()
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* {@link ChainFailed}
|
|
28
|
+
*
|
|
29
|
+
* `error` is a `string` on the wire. The schema accepts `unknown` so the same
|
|
30
|
+
* codec also validates a locally produced envelope that carries an `Error`.
|
|
31
|
+
**/
|
|
32
|
+
const chainFailedSchema = zod_v4.z.object({
|
|
33
|
+
chainId: require_model_primitives_schema.chainIdSchema,
|
|
34
|
+
status: zod_v4.z.literal("error"),
|
|
35
|
+
source: dataSourceSchema.optional(),
|
|
36
|
+
error: zod_v4.z.unknown().optional()
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* {@link ChainMetadata}
|
|
40
|
+
**/
|
|
41
|
+
const chainMetadataSchema = zod_v4.z.discriminatedUnion("status", [chainSucceededSchema, chainFailedSchema]);
|
|
42
|
+
/**
|
|
43
|
+
* {@link ResponseMetadata}
|
|
44
|
+
**/
|
|
45
|
+
const responseMetadataSchema = zod_v4.z.object({ chains: zod_v4.z.array(chainMetadataSchema) });
|
|
46
|
+
/**
|
|
47
|
+
* {@link DataResponse} parameterized by the payload schema.
|
|
48
|
+
**/
|
|
49
|
+
function responseSchema(payloadSchema) {
|
|
50
|
+
return zod_v4.z.object({
|
|
51
|
+
data: payloadSchema,
|
|
52
|
+
meta: responseMetadataSchema
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.chainFailedSchema = chainFailedSchema;
|
|
57
|
+
exports.chainMetadataSchema = chainMetadataSchema;
|
|
58
|
+
exports.chainSucceededSchema = chainSucceededSchema;
|
|
59
|
+
exports.dataSourceSchema = dataSourceSchema;
|
|
60
|
+
exports.responseMetadataSchema = responseMetadataSchema;
|
|
61
|
+
exports.responseSchema = responseSchema;
|
|
@@ -31,9 +31,9 @@ var AbstractOffchainNamespace = class {
|
|
|
31
31
|
/**
|
|
32
32
|
* Reads one endpoint and decodes its payload.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* A 2xx body is a {@link DataResponse}. Timeouts, non-2xx, and schema skew
|
|
35
|
+
* throw — they are not a backend envelope, and this layer is what wraps
|
|
36
|
+
* them, because the request may never have reached the backend.
|
|
37
37
|
**/
|
|
38
38
|
async get(request) {
|
|
39
39
|
const url = this.#url(request.path, request.query);
|
|
@@ -109,7 +109,7 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
|
|
|
109
109
|
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
110
110
|
const { creditManager, includeZeroDebt = false, maxHealthFactor = require_sdk_constants_math.MAX_UINT256, minHealthFactor = 0n, ignoreReservePrices = false } = options ?? {};
|
|
111
111
|
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
112
|
-
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
112
|
+
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower, void 0, blockNumber)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
113
113
|
const cmFilter = creditManager ? {
|
|
114
114
|
configurators: [],
|
|
115
115
|
creditManagers: [creditManager],
|
|
@@ -179,13 +179,13 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
|
|
|
179
179
|
* @param props - {@link ListStrategyPositionsProps}
|
|
180
180
|
**/
|
|
181
181
|
async listPositions(props) {
|
|
182
|
-
const { owner, includeZeroDebt } = props;
|
|
183
|
-
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
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
184
|
const describable = accounts.filter((ca) => {
|
|
185
185
|
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
186
186
|
return ca.success;
|
|
187
187
|
});
|
|
188
|
-
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
188
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
|
|
189
189
|
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
@@ -236,13 +236,13 @@ var CreditAccountCompressor = class extends require_sdk_base_SDKConstruct.SDKCon
|
|
|
236
236
|
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
237
237
|
* represents them on it, so that each collateral row can pick up its own.
|
|
238
238
|
**/
|
|
239
|
-
async #accountWithdrawals(ca) {
|
|
239
|
+
async #accountWithdrawals(ca, blockNumber) {
|
|
240
240
|
const compressor = this.sdk.withdrawalCompressor;
|
|
241
241
|
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
242
242
|
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
243
243
|
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
244
244
|
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
245
|
-
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
245
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
|
|
246
246
|
const add = (w, outputs, claimableAt) => {
|
|
247
247
|
const assets = outputs.map((o) => ({
|
|
248
248
|
isDelayed: true,
|
|
@@ -33,13 +33,13 @@ 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();
|
|
36
|
+
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, props?.blockNumber);
|
|
37
37
|
const unhealthy = await this.sdk.accounts.getCreditAccounts({
|
|
38
38
|
maxHealthFactor: require_sdk_constants_math.WAD - 1n,
|
|
39
39
|
includeZeroDebt: false
|
|
40
|
-
});
|
|
40
|
+
}, props?.blockNumber);
|
|
41
41
|
const seen = new require_sdk_utils_AddressSet.AddressSet(unhealthy.map((ca) => ca.creditAccount));
|
|
42
|
-
let expired = await this.#getExpiredCreditAccounts();
|
|
42
|
+
let expired = await this.#getExpiredCreditAccounts(props?.blockNumber);
|
|
43
43
|
expired = expired.filter((ca) => !seen.has(ca.creditAccount));
|
|
44
44
|
return [...unhealthy, ...expired].flatMap((ca) => {
|
|
45
45
|
if (!ca.success) {
|
|
@@ -56,13 +56,13 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
56
56
|
* @throws When the account is not found or its collateral computation fails.
|
|
57
57
|
**/
|
|
58
58
|
async getLiquidationDetails(props) {
|
|
59
|
-
const { creditAccount, liquidator, ignoreReservePrices } = props;
|
|
60
|
-
const ca = await this.#getCreditAccountData(creditAccount);
|
|
59
|
+
const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
|
|
60
|
+
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
61
61
|
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
62
62
|
const { priceOracle } = suite.market;
|
|
63
|
-
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets();
|
|
63
|
+
await this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber);
|
|
64
64
|
const account = this.#buildAccount(ca, suite);
|
|
65
|
-
const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
|
|
65
|
+
const data = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
|
|
66
66
|
return {
|
|
67
67
|
...account,
|
|
68
68
|
repaymentAmount: priceOracle.toTokenAmount(require_sdk_utils_hex.hexEq(data.requiredToken, "0x0000000000000000000000000000000000000000") ? account.totalValue.token.address : data.requiredToken, data.requiredAmount),
|
|
@@ -80,9 +80,9 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
80
80
|
* the debt from own funds and receiving the collateral from the credit account.
|
|
81
81
|
**/
|
|
82
82
|
async buildLiquidationTx(props) {
|
|
83
|
-
const { creditAccount, liquidator, ignoreReservePrices } = props;
|
|
84
|
-
const ca = await this.#getCreditAccountData(creditAccount);
|
|
85
|
-
const { liquidationCall } = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices);
|
|
83
|
+
const { creditAccount, liquidator, ignoreReservePrices, blockNumber } = props;
|
|
84
|
+
const ca = await this.#getCreditAccountData(creditAccount, blockNumber);
|
|
85
|
+
const { liquidationCall } = await this.#getLiquidationData(ca, liquidator, ignoreReservePrices, blockNumber);
|
|
86
86
|
this.logger?.debug(`built tx to liquidate credit account ${this.labelAddress(creditAccount)} to ${this.labelAddress(liquidator)}`);
|
|
87
87
|
return {
|
|
88
88
|
to: liquidationCall.target,
|
|
@@ -97,9 +97,13 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
97
97
|
async getLiquidationPositions(props) {
|
|
98
98
|
const compressor = this.sdk.withdrawalCompressor;
|
|
99
99
|
if (!compressor) return [];
|
|
100
|
-
await compressor.loadWithdrawableAssets();
|
|
100
|
+
await compressor.loadWithdrawableAssets(void 0, props.blockNumber);
|
|
101
101
|
const phantomTokens = new require_sdk_utils_AddressSet.AddressSet(compressor.getWithdrawableAssets().map((a) => a.withdrawalPhantomToken));
|
|
102
|
-
const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals(
|
|
102
|
+
const { claimable, pending } = await compressor.getExternalAccountCurrentWithdrawals({
|
|
103
|
+
account: props.liquidator,
|
|
104
|
+
withdrawalTokens: phantomTokens.asArray(),
|
|
105
|
+
blockNumber: props.blockNumber
|
|
106
|
+
});
|
|
103
107
|
return [...claimable.map((w) => ({
|
|
104
108
|
...this.#liquidationPosition(w.token, w.outputs),
|
|
105
109
|
claimTx: this.#claimTx(w.claimCalls, w.token),
|
|
@@ -115,7 +119,7 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
115
119
|
* deployed for the markets of the chain and registers them in the SDK
|
|
116
120
|
* contracts register.
|
|
117
121
|
**/
|
|
118
|
-
async loadRWALiquidators() {
|
|
122
|
+
async loadRWALiquidators(props) {
|
|
119
123
|
const configurators = this.sdk.marketRegister.marketConfigurators;
|
|
120
124
|
if (configurators.length === 0) return;
|
|
121
125
|
const resp = await this.client.multicall({
|
|
@@ -126,7 +130,8 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
126
130
|
args: [mc.address]
|
|
127
131
|
})),
|
|
128
132
|
allowFailure: false,
|
|
129
|
-
batchSize: 0
|
|
133
|
+
batchSize: 0,
|
|
134
|
+
blockNumber: props?.blockNumber
|
|
130
135
|
});
|
|
131
136
|
for (const info of resp.flat()) this.#createRWALiquidator(info);
|
|
132
137
|
}
|
|
@@ -212,13 +217,13 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
212
217
|
...priceOracle.toTokenAmount(requiredToken, requiredAmount * (require_sdk_constants_math.PERCENTAGE_FACTOR + require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER) / require_sdk_constants_math.PERCENTAGE_FACTOR)
|
|
213
218
|
};
|
|
214
219
|
}
|
|
215
|
-
async #getCreditAccountData(creditAccount) {
|
|
216
|
-
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount);
|
|
220
|
+
async #getCreditAccountData(creditAccount, blockNumber) {
|
|
221
|
+
const ca = await this.sdk.accounts.getCreditAccountData(creditAccount, blockNumber);
|
|
217
222
|
if (!ca) throw new Error(`credit account ${creditAccount} not found`);
|
|
218
223
|
if (!ca.success) throw new Error(`cannot compute liquidation details for ${creditAccount}: collateral computation failed`);
|
|
219
224
|
return ca;
|
|
220
225
|
}
|
|
221
|
-
async #getLiquidationData(ca, liquidator = require_sdk_constants_addresses.ADDRESS_0X0, ignoreReservePrices) {
|
|
226
|
+
async #getLiquidationData(ca, liquidator = require_sdk_constants_addresses.ADDRESS_0X0, ignoreReservePrices, blockNumber) {
|
|
222
227
|
const priceUpdates = await this.sdk.accounts.getOnDemandPriceUpdates(ca, ignoreReservePrices);
|
|
223
228
|
const { result } = await this.client.simulateContract({
|
|
224
229
|
address: require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS,
|
|
@@ -228,11 +233,12 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
228
233
|
liquidator,
|
|
229
234
|
ca.creditAccount,
|
|
230
235
|
priceUpdates
|
|
231
|
-
]
|
|
236
|
+
],
|
|
237
|
+
blockNumber
|
|
232
238
|
});
|
|
233
239
|
return result;
|
|
234
240
|
}
|
|
235
|
-
async #getExpiredCreditAccounts() {
|
|
241
|
+
async #getExpiredCreditAccounts(blockNumber) {
|
|
236
242
|
const expiredCMs = [];
|
|
237
243
|
for (const market of this.sdk.marketRegister.markets) {
|
|
238
244
|
if (market.pool.pool.totalBorrowed === 0n) continue;
|
|
@@ -246,7 +252,7 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
246
252
|
return (await Promise.all(expiredCMs.map((creditManager) => this.sdk.accounts.getCreditAccounts({
|
|
247
253
|
creditManager,
|
|
248
254
|
includeZeroDebt: false
|
|
249
|
-
})))).flat();
|
|
255
|
+
}, blockNumber)))).flat();
|
|
250
256
|
}
|
|
251
257
|
#buildAccount(ca, suite = this.sdk.marketRegister.findCreditManager(ca.creditManager)) {
|
|
252
258
|
const market = suite.market;
|
|
@@ -65,7 +65,7 @@ var AbstractWithdrawalCompressorContract = class extends require_sdk_base_BaseCo
|
|
|
65
65
|
/**
|
|
66
66
|
* {@inheritDoc IWithdrawalCompressorContract.loadWithdrawableAssets}
|
|
67
67
|
**/
|
|
68
|
-
async loadWithdrawableAssets(force) {
|
|
68
|
+
async loadWithdrawableAssets(force, blockNumber) {
|
|
69
69
|
if (this.#withdrawableAssets && !force) return this.getWithdrawableAssets();
|
|
70
70
|
const cms = this.#sdk.marketRegister.creditManagers.map((cm) => cm.creditManager.address);
|
|
71
71
|
const resp = await this.client.multicall({
|
|
@@ -76,7 +76,8 @@ var AbstractWithdrawalCompressorContract = class extends require_sdk_base_BaseCo
|
|
|
76
76
|
args: [cm]
|
|
77
77
|
})),
|
|
78
78
|
allowFailure: true,
|
|
79
|
-
batchSize: 0
|
|
79
|
+
batchSize: 0,
|
|
80
|
+
blockNumber
|
|
80
81
|
});
|
|
81
82
|
const cache = new require_sdk_utils_AddressMap.AddressMap(void 0, MAP_LABEL);
|
|
82
83
|
for (let i = 0; i < resp.length; i++) {
|
|
@@ -121,7 +122,7 @@ var AbstractWithdrawalCompressorContract = class extends require_sdk_base_BaseCo
|
|
|
121
122
|
/**
|
|
122
123
|
* {@inheritDoc IWithdrawalCompressorContract.getCurrentWithdrawals}
|
|
123
124
|
**/
|
|
124
|
-
async getCurrentWithdrawals(creditAccount) {
|
|
125
|
+
async getCurrentWithdrawals(creditAccount, blockNumber) {
|
|
125
126
|
const [[claimable, pending], creditManager] = await this.client.multicall({
|
|
126
127
|
contracts: [{
|
|
127
128
|
address: this.address,
|
|
@@ -134,7 +135,8 @@ var AbstractWithdrawalCompressorContract = class extends require_sdk_base_BaseCo
|
|
|
134
135
|
functionName: "creditManager"
|
|
135
136
|
}],
|
|
136
137
|
allowFailure: false,
|
|
137
|
-
batchSize: 0
|
|
138
|
+
batchSize: 0,
|
|
139
|
+
blockNumber
|
|
138
140
|
});
|
|
139
141
|
return {
|
|
140
142
|
claimable: claimable.map((w) => toClaimableWithdrawal(w, creditManager)),
|
|
@@ -144,7 +146,7 @@ var AbstractWithdrawalCompressorContract = class extends require_sdk_base_BaseCo
|
|
|
144
146
|
/**
|
|
145
147
|
* {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
|
|
146
148
|
**/
|
|
147
|
-
async getExternalAccountCurrentWithdrawals(
|
|
149
|
+
async getExternalAccountCurrentWithdrawals(_props) {
|
|
148
150
|
this.#reportUnsupported("external account withdrawals");
|
|
149
151
|
return {
|
|
150
152
|
claimable: [],
|
|
@@ -184,7 +184,7 @@ var WithdrawalCompressorV313Contract = class extends require_sdk_accounts_withdr
|
|
|
184
184
|
/**
|
|
185
185
|
* {@inheritDoc IWithdrawalCompressorContract.getExternalAccountCurrentWithdrawals}
|
|
186
186
|
**/
|
|
187
|
-
async getExternalAccountCurrentWithdrawals(account,
|
|
187
|
+
async getExternalAccountCurrentWithdrawals({ account, withdrawalTokens = [], blockNumber }) {
|
|
188
188
|
if (withdrawalTokens.length === 0) return {
|
|
189
189
|
claimable: [],
|
|
190
190
|
pending: []
|
|
@@ -193,7 +193,8 @@ var WithdrawalCompressorV313Contract = class extends require_sdk_accounts_withdr
|
|
|
193
193
|
address: this.address,
|
|
194
194
|
abi: iExternalWithdrawalsBatchAbi,
|
|
195
195
|
functionName: "getExternalAccountCurrentWithdrawals",
|
|
196
|
-
args: [withdrawalTokens, account]
|
|
196
|
+
args: [withdrawalTokens, account],
|
|
197
|
+
blockNumber
|
|
197
198
|
});
|
|
198
199
|
return {
|
|
199
200
|
claimable: claimable.map((w) => require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.toClaimableWithdrawal(w, void 0)),
|
|
@@ -55,8 +55,9 @@ var RWARegistry = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
55
55
|
* @param investor - Investor EOA address.
|
|
56
56
|
* @param factories_ - Optional subset of factory addresses to query.
|
|
57
57
|
* When omitted, all loaded factories are used.
|
|
58
|
+
* @param blockNumber - Block to read at, defaults to the latest block.
|
|
58
59
|
*/
|
|
59
|
-
async getInvestorData(investor, factories_) {
|
|
60
|
+
async getInvestorData(investor, factories_, blockNumber) {
|
|
60
61
|
let factories = this.#factories.values();
|
|
61
62
|
if (factories_?.length) factories = factories_.map((f) => this.#factories.mustGet(f));
|
|
62
63
|
if (!factories.length) return [];
|
|
@@ -65,7 +66,8 @@ var RWARegistry = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
65
66
|
abi: require_abi_rwa_iRWACompressor.iRWACompressorAbi,
|
|
66
67
|
address: rwaCompressorAddress,
|
|
67
68
|
functionName: "getRWAInvestorData",
|
|
68
|
-
args: [investor, factories.map((f) => f.address)]
|
|
69
|
+
args: [investor, factories.map((f) => f.address)],
|
|
70
|
+
blockNumber
|
|
69
71
|
});
|
|
70
72
|
const result = [];
|
|
71
73
|
for (let i = 0; i < factories.length; i++) {
|
|
@@ -189,7 +189,8 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
189
189
|
args: [props.wallet]
|
|
190
190
|
})),
|
|
191
191
|
allowFailure: false,
|
|
192
|
-
batchSize: 0
|
|
192
|
+
batchSize: 0,
|
|
193
|
+
blockNumber: props.blockNumber
|
|
193
194
|
});
|
|
194
195
|
return markets.flatMap((market, i) => {
|
|
195
196
|
const shares = balances[i] ?? 0n;
|
|
@@ -18,19 +18,26 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
18
18
|
* the call rather than the SDK's loaded snapshot.
|
|
19
19
|
**/
|
|
20
20
|
async list(props) {
|
|
21
|
-
const { wallet, filter } = props;
|
|
21
|
+
const { wallet, filter, blockNumber } = props;
|
|
22
22
|
const chainIds = filter?.chainIds;
|
|
23
23
|
if (require_model_filters.isFilterSet(chainIds) && !chainIds.includes(this.chainId)) return [];
|
|
24
24
|
const wantedKind = filter?.kind;
|
|
25
25
|
const wanted = (kind) => !require_model_filters.isFilterSet(wantedKind) || wantedKind === kind;
|
|
26
26
|
const isZeroDebt = filter?.isZeroDebt;
|
|
27
27
|
const [pool, strategy, liquidation] = await Promise.all([
|
|
28
|
-
wanted("pool") ? this.sdk.pools.listPositions({
|
|
28
|
+
wanted("pool") ? this.sdk.pools.listPositions({
|
|
29
|
+
wallet,
|
|
30
|
+
blockNumber
|
|
31
|
+
}) : Promise.resolve([]),
|
|
29
32
|
wanted("strategy") ? this.sdk.accounts.listPositions({
|
|
30
33
|
owner: wallet,
|
|
31
|
-
includeZeroDebt: !require_model_filters.isFilterSet(isZeroDebt) || isZeroDebt
|
|
34
|
+
includeZeroDebt: !require_model_filters.isFilterSet(isZeroDebt) || isZeroDebt,
|
|
35
|
+
blockNumber
|
|
32
36
|
}) : Promise.resolve([]),
|
|
33
|
-
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({
|
|
37
|
+
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({
|
|
38
|
+
liquidator: wallet,
|
|
39
|
+
blockNumber
|
|
40
|
+
}) : Promise.resolve([])
|
|
34
41
|
]);
|
|
35
42
|
return [
|
|
36
43
|
...pool,
|
package/dist/esm/model/index.js
CHANGED
|
@@ -12,4 +12,6 @@ import { matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
|
12
12
|
import { matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
13
13
|
import { liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
14
14
|
import "./primitives.js";
|
|
15
|
-
|
|
15
|
+
import "./response.js";
|
|
16
|
+
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
17
|
+
export { FILTER_ALL, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, filterAllSchema, filterable, historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, instantReceivedAssetSchema, isFilterSet, leverageSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionId, liquidationPositionSchema, matchesLiquidatableAccountFilter, matchesOpportunityFilter, matchesPositionFilter, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityHistoryQuerySchema, opportunityId, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pnlBreakdownSchema, pointRewardsSchema, pointsProgramPnLSchema, pointsProgramSchema, pointsRewardsPnLSchema, poolHistoryMetricSchema, poolOpportunityDetailSchema, poolOpportunityId, poolOpportunityKeySchema, poolOpportunitySchema, poolPositionHistoryMetricSchema, poolPositionId, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, positionId, positionKeySchema, positionKindSchema, positionSchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, receivedAssetSchema, responseMetadataSchema, responseSchema, rewardsPnLSchema, rewardsSchema, strategyHistoryMetricSchema, strategyOpportunityDetailSchema, strategyOpportunityId, strategyOpportunityKeySchema, strategyOpportunitySchema, strategyPositionHistoryMetricSchema, strategyPositionId, strategyPositionKeySchema, strategyPositionSchema, timestampSchema, tokenAmountSchema, tokenRewardsPnLSchema, tokenRewardsSchema, tokenSchema, txCallSchema };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { chainIdSchema, timestampSchema } from "./primitives.schema.js";
|
|
2
|
+
import { z } from "zod/v4";
|
|
3
|
+
//#region src/model/response.schema.ts
|
|
4
|
+
/**
|
|
5
|
+
* Runtime schemas for {@link ./response.js}, see the note in
|
|
6
|
+
* `primitives.schema.ts` on why they are written by hand.
|
|
7
|
+
*
|
|
8
|
+
* `responseSchema(payloadSchema)` validates a successful backend 2xx body.
|
|
9
|
+
* HTTP and transport errors never pass through it.
|
|
10
|
+
**/
|
|
11
|
+
/**
|
|
12
|
+
* {@link DataSource}
|
|
13
|
+
**/
|
|
14
|
+
const dataSourceSchema = z.union([z.literal("onchain"), z.literal("offchain")]);
|
|
15
|
+
/**
|
|
16
|
+
* {@link ChainSucceeded}
|
|
17
|
+
**/
|
|
18
|
+
const chainSucceededSchema = z.object({
|
|
19
|
+
chainId: chainIdSchema,
|
|
20
|
+
status: z.literal("success"),
|
|
21
|
+
source: dataSourceSchema,
|
|
22
|
+
blockNumber: z.number().int().nonnegative().optional(),
|
|
23
|
+
timestamp: timestampSchema.optional()
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* {@link ChainFailed}
|
|
27
|
+
*
|
|
28
|
+
* `error` is a `string` on the wire. The schema accepts `unknown` so the same
|
|
29
|
+
* codec also validates a locally produced envelope that carries an `Error`.
|
|
30
|
+
**/
|
|
31
|
+
const chainFailedSchema = z.object({
|
|
32
|
+
chainId: chainIdSchema,
|
|
33
|
+
status: z.literal("error"),
|
|
34
|
+
source: dataSourceSchema.optional(),
|
|
35
|
+
error: z.unknown().optional()
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* {@link ChainMetadata}
|
|
39
|
+
**/
|
|
40
|
+
const chainMetadataSchema = z.discriminatedUnion("status", [chainSucceededSchema, chainFailedSchema]);
|
|
41
|
+
/**
|
|
42
|
+
* {@link ResponseMetadata}
|
|
43
|
+
**/
|
|
44
|
+
const responseMetadataSchema = z.object({ chains: z.array(chainMetadataSchema) });
|
|
45
|
+
/**
|
|
46
|
+
* {@link DataResponse} parameterized by the payload schema.
|
|
47
|
+
**/
|
|
48
|
+
function responseSchema(payloadSchema) {
|
|
49
|
+
return z.object({
|
|
50
|
+
data: payloadSchema,
|
|
51
|
+
meta: responseMetadataSchema
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema };
|
|
@@ -30,9 +30,9 @@ var AbstractOffchainNamespace = class {
|
|
|
30
30
|
/**
|
|
31
31
|
* Reads one endpoint and decodes its payload.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* A 2xx body is a {@link DataResponse}. Timeouts, non-2xx, and schema skew
|
|
34
|
+
* throw — they are not a backend envelope, and this layer is what wraps
|
|
35
|
+
* them, because the request may never have reached the backend.
|
|
36
36
|
**/
|
|
37
37
|
async get(request) {
|
|
38
38
|
const url = this.#url(request.path, request.query);
|
|
@@ -108,7 +108,7 @@ var CreditAccountCompressor = class extends SDKConstruct {
|
|
|
108
108
|
async getBorrowerCreditAccounts(borrower, options, blockNumber) {
|
|
109
109
|
const { creditManager, includeZeroDebt = false, maxHealthFactor = MAX_UINT256, minHealthFactor = 0n, ignoreReservePrices = false } = options ?? {};
|
|
110
110
|
const { txs: priceUpdateTxs } = await this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(ignoreReservePrices ? { main: true } : void 0);
|
|
111
|
-
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
111
|
+
const rwaAccountAddresses = (await this.sdk.rwa.getInvestorData(borrower, void 0, blockNumber)).flatMap((d) => d.creditAccounts.map((ca) => ca.creditAccount));
|
|
112
112
|
const cmFilter = creditManager ? {
|
|
113
113
|
configurators: [],
|
|
114
114
|
creditManagers: [creditManager],
|
|
@@ -178,13 +178,13 @@ var CreditAccountCompressor = class extends SDKConstruct {
|
|
|
178
178
|
* @param props - {@link ListStrategyPositionsProps}
|
|
179
179
|
**/
|
|
180
180
|
async listPositions(props) {
|
|
181
|
-
const { owner, includeZeroDebt } = props;
|
|
182
|
-
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
181
|
+
const { owner, includeZeroDebt, blockNumber } = props;
|
|
182
|
+
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber), this.sdk.withdrawalCompressor?.loadWithdrawableAssets(void 0, blockNumber)]);
|
|
183
183
|
const describable = accounts.filter((ca) => {
|
|
184
184
|
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
185
185
|
return ca.success;
|
|
186
186
|
});
|
|
187
|
-
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
187
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
|
|
188
188
|
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
|
|
189
189
|
}
|
|
190
190
|
/**
|
|
@@ -235,13 +235,13 @@ var CreditAccountCompressor = class extends SDKConstruct {
|
|
|
235
235
|
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
236
236
|
* represents them on it, so that each collateral row can pick up its own.
|
|
237
237
|
**/
|
|
238
|
-
async #accountWithdrawals(ca) {
|
|
238
|
+
async #accountWithdrawals(ca, blockNumber) {
|
|
239
239
|
const compressor = this.sdk.withdrawalCompressor;
|
|
240
240
|
const byPhantomToken = new AddressMap(void 0, "accountWithdrawals");
|
|
241
241
|
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
242
242
|
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
243
243
|
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
244
|
-
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
244
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
|
|
245
245
|
const add = (w, outputs, claimableAt) => {
|
|
246
246
|
const assets = outputs.map((o) => ({
|
|
247
247
|
isDelayed: true,
|