@gearbox-protocol/sdk 15.1.0-next.6 → 15.1.0-next.7
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/index.js +1 -0
- package/dist/cjs/model/positions.schema.js +13 -0
- 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/index.js +2 -2
- package/dist/esm/model/positions.schema.js +14 -2
- 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/index.d.ts +3 -3
- package/dist/types/model/positions.d.ts +84 -1
- package/dist/types/model/positions.schema.d.ts +26 -1
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../base/index.js";
|
|
4
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
5
|
//#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -132,17 +132,24 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
132
132
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(to)) / price;
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
|
-
* {@inheritDoc IPriceOracleContract.
|
|
135
|
+
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
136
136
|
**/
|
|
137
|
-
|
|
137
|
+
safeConvertToUSD(token, amount) {
|
|
138
138
|
try {
|
|
139
|
-
return
|
|
139
|
+
return this.convertToUSD(token, amount);
|
|
140
140
|
} catch (e) {
|
|
141
141
|
this.logger?.debug(`cannot price ${this.labelAddress(token)}: ${e}`);
|
|
142
142
|
return null;
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
+
* {@inheritDoc IPriceOracleContract.safeUsdValue}
|
|
147
|
+
**/
|
|
148
|
+
safeUsdValue(token, amount) {
|
|
149
|
+
const usd = this.safeConvertToUSD(token, amount);
|
|
150
|
+
return usd === null ? null : usdToNumber(usd);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
146
153
|
* {@inheritDoc IPriceOracleContract.toAmount}
|
|
147
154
|
**/
|
|
148
155
|
toAmount = (token, value) => {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
4
3
|
import { RAY } from "../../constants/math.js";
|
|
@@ -7,6 +6,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
|
7
6
|
import "../../utils/index.js";
|
|
8
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
9
8
|
import "../../base/index.js";
|
|
9
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
10
10
|
import { calcUtilization } from "../math.js";
|
|
11
11
|
//#region src/sdk/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
2
|
+
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
3
3
|
//#region src/sdk/market/zapper/IETHZapperContract.ts
|
|
4
4
|
const abi = iethZapperAbi;
|
|
5
5
|
var IETHZapperContract = class extends ZapperContract {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
3
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
4
4
|
import { UnsupportedZapperFunctionError } from "./errors.js";
|
|
5
5
|
//#region src/sdk/market/zapper/ZapperContract.ts
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import "../constants/addresses.js";
|
|
4
4
|
import { RAY } from "../constants/math.js";
|
|
5
5
|
import "../constants/index.js";
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
+
import "../constants/math.js";
|
|
3
|
+
import "../constants/index.js";
|
|
4
|
+
import "../utils/index.js";
|
|
1
5
|
import { SDKConstruct } from "../base/SDKConstruct.js";
|
|
2
6
|
import "../base/index.js";
|
|
7
|
+
import { calcBorrowApy, calcPositionLeverage, healthFactorBps, usdToNumber } from "../market/math.js";
|
|
8
|
+
import { dominantCollateral } from "../market/credit/dominantCollateral.js";
|
|
3
9
|
import { isFilterSet } from "../../model/filters.js";
|
|
4
10
|
import { matchesPositionFilter } from "../../model/positions.js";
|
|
5
11
|
import "../../model/index.js";
|
|
12
|
+
import "../market/index.js";
|
|
13
|
+
import { calcBorrowRate } from "./calcBorrowRate.js";
|
|
14
|
+
import { calcHealthFactor } from "./calcHealthFactor.js";
|
|
15
|
+
import { calcLiquidationPrice } from "./calcLiquidationPrice.js";
|
|
16
|
+
import { calcTimeToLiquidationMs } from "./calcTimeToLiquidationMs.js";
|
|
17
|
+
import { accountSnapshotFromCreditAccountData } from "./types.js";
|
|
6
18
|
//#region src/sdk/positions/PositionsService.ts
|
|
7
19
|
/**
|
|
8
20
|
* The `positions` read model of one chain: everything a wallet holds in the
|
|
@@ -27,7 +39,7 @@ var PositionsService = class extends SDKConstruct {
|
|
|
27
39
|
wallet,
|
|
28
40
|
blockNumber
|
|
29
41
|
}) : Promise.resolve([]),
|
|
30
|
-
wanted("strategy") ? this.
|
|
42
|
+
wanted("strategy") ? this.listStrategyPositions({
|
|
31
43
|
owner: wallet,
|
|
32
44
|
includeZeroDebt: !isFilterSet(isZeroDebt) || isZeroDebt,
|
|
33
45
|
blockNumber
|
|
@@ -43,6 +55,199 @@ var PositionsService = class extends SDKConstruct {
|
|
|
43
55
|
...liquidation
|
|
44
56
|
].filter((row) => matchesPositionFilter(row, filter));
|
|
45
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Describes all credit accounts of a wallet as strategy positions.
|
|
60
|
+
*
|
|
61
|
+
* @param props - {@link ListStrategyPositionsProps}
|
|
62
|
+
**/
|
|
63
|
+
async listStrategyPositions(props) {
|
|
64
|
+
const { owner, includeZeroDebt, blockNumber } = props;
|
|
65
|
+
const describable = (await this.sdk.accounts.getBorrowerCreditAccounts(owner, { includeZeroDebt }, blockNumber)).filter((ca) => {
|
|
66
|
+
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
67
|
+
return ca.success;
|
|
68
|
+
});
|
|
69
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca, blockNumber)));
|
|
70
|
+
return describable.map((ca, i) => this.#toStrategyPosition(ca, withdrawals[i] ?? new AddressMap()));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
74
|
+
**/
|
|
75
|
+
healthFactor(snapshot) {
|
|
76
|
+
const data = this.#marketData(snapshot);
|
|
77
|
+
return calcHealthFactor({
|
|
78
|
+
snapshot,
|
|
79
|
+
underlying: data.underlying,
|
|
80
|
+
decimals: data.decimals,
|
|
81
|
+
prices: data.prices,
|
|
82
|
+
liquidationThresholds: data.liquidationThresholds,
|
|
83
|
+
activeQuotas: data.activeQuotas
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Cost of an account state's debt, broken down into the pool's base rate
|
|
88
|
+
* and per-token quota rates.
|
|
89
|
+
**/
|
|
90
|
+
borrowRate(snapshot) {
|
|
91
|
+
const data = this.#marketData(snapshot);
|
|
92
|
+
return calcBorrowRate({
|
|
93
|
+
snapshot,
|
|
94
|
+
baseInterestRate: data.baseInterestRate,
|
|
95
|
+
feeInterest: data.feeInterest,
|
|
96
|
+
quotaRates: data.quotaRates
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Estimated milliseconds until the account's health factor decays to
|
|
101
|
+
* `10000` under its current borrow rate, or `null` when the debt carries
|
|
102
|
+
* no rate (or the account is already liquidatable).
|
|
103
|
+
**/
|
|
104
|
+
timeToLiquidation(snapshot) {
|
|
105
|
+
const data = this.#marketData(snapshot);
|
|
106
|
+
return calcTimeToLiquidationMs(calcHealthFactor({
|
|
107
|
+
snapshot,
|
|
108
|
+
underlying: data.underlying,
|
|
109
|
+
decimals: data.decimals,
|
|
110
|
+
prices: data.prices,
|
|
111
|
+
liquidationThresholds: data.liquidationThresholds,
|
|
112
|
+
activeQuotas: data.activeQuotas
|
|
113
|
+
}), BigInt(calcBorrowRate({
|
|
114
|
+
snapshot,
|
|
115
|
+
baseInterestRate: data.baseInterestRate,
|
|
116
|
+
feeInterest: data.feeInterest,
|
|
117
|
+
quotaRates: data.quotaRates
|
|
118
|
+
}).totalOnDebt));
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Price of the single non-underlying collateral at which the account
|
|
122
|
+
* becomes liquidatable, or `null` when the account holds zero or several
|
|
123
|
+
* non-underlying assets.
|
|
124
|
+
**/
|
|
125
|
+
liquidationPrice(snapshot) {
|
|
126
|
+
const data = this.#marketData(snapshot);
|
|
127
|
+
return calcLiquidationPrice({
|
|
128
|
+
snapshot,
|
|
129
|
+
underlying: data.underlying,
|
|
130
|
+
decimals: data.decimals,
|
|
131
|
+
liquidationThresholds: data.liquidationThresholds
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Builds one strategy position from an account snapshot.
|
|
136
|
+
*
|
|
137
|
+
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
138
|
+
* phantom token that represents them on it.
|
|
139
|
+
**/
|
|
140
|
+
#toStrategyPosition(ca, withdrawals) {
|
|
141
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
142
|
+
const { market } = suite;
|
|
143
|
+
const { priceOracle } = market;
|
|
144
|
+
const { pool } = market.pool;
|
|
145
|
+
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
146
|
+
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
147
|
+
const collateral = dominantCollateral(ca, market);
|
|
148
|
+
const snapshot = accountSnapshotFromCreditAccountData(ca);
|
|
149
|
+
const borrowRate = this.borrowRate(snapshot);
|
|
150
|
+
const timeToLiquidation = this.timeToLiquidation(snapshot);
|
|
151
|
+
const liquidationPrice = this.liquidationPrice(snapshot);
|
|
152
|
+
return {
|
|
153
|
+
kind: "strategy",
|
|
154
|
+
chainId: this.sdk.chainId,
|
|
155
|
+
creditManager: ca.creditManager,
|
|
156
|
+
creditAccount: ca.creditAccount,
|
|
157
|
+
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
158
|
+
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
159
|
+
leverage: calcPositionLeverage(ca.totalValue, totalDebtValue),
|
|
160
|
+
borrowApy: calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
161
|
+
totalDebt: {
|
|
162
|
+
token,
|
|
163
|
+
value: totalDebtValue,
|
|
164
|
+
valueUsd: usdToNumber(ca.totalDebtUSD)
|
|
165
|
+
},
|
|
166
|
+
totalValue: {
|
|
167
|
+
token,
|
|
168
|
+
value: ca.totalValue,
|
|
169
|
+
valueUsd: usdToNumber(ca.totalValueUSD)
|
|
170
|
+
},
|
|
171
|
+
healthFactor: healthFactorBps(ca.healthFactor),
|
|
172
|
+
borrowRate,
|
|
173
|
+
timeToLiquidation,
|
|
174
|
+
liquidationPrice,
|
|
175
|
+
collaterals: ca.tokens.flatMap((t) => {
|
|
176
|
+
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
177
|
+
return [{
|
|
178
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
179
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
180
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
181
|
+
}];
|
|
182
|
+
})
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
187
|
+
* represents them on it, so that each collateral row can pick up its own.
|
|
188
|
+
**/
|
|
189
|
+
async #accountWithdrawals(ca, blockNumber) {
|
|
190
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
191
|
+
const byPhantomToken = new AddressMap(void 0, "accountWithdrawals");
|
|
192
|
+
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
193
|
+
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
194
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
195
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount, blockNumber);
|
|
196
|
+
const add = (w, outputs, claimableAt) => {
|
|
197
|
+
const assets = outputs.map((o) => ({
|
|
198
|
+
isDelayed: true,
|
|
199
|
+
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
200
|
+
redeemer: w.redeemer,
|
|
201
|
+
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
202
|
+
}));
|
|
203
|
+
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
204
|
+
};
|
|
205
|
+
for (const w of claimable) add(w, w.outputs);
|
|
206
|
+
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
207
|
+
return byPhantomToken;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Collects decimals, prices and thresholds for the snapshot's tokens plus
|
|
211
|
+
* the market underlying, even when the account holds no underlying balance.
|
|
212
|
+
**/
|
|
213
|
+
#marketData(snapshot) {
|
|
214
|
+
const market = this.sdk.marketRegister.findByCreditManager(snapshot.creditManager);
|
|
215
|
+
const cm = this.sdk.marketRegister.findCreditManager(snapshot.creditManager).creditManager;
|
|
216
|
+
const { priceOracle } = market;
|
|
217
|
+
const underlying = market.pool.underlying;
|
|
218
|
+
const { pqk, pool } = market.pool;
|
|
219
|
+
const tokens = [underlying];
|
|
220
|
+
for (const a of snapshot.assets) tokens.push(a.token);
|
|
221
|
+
for (const q of snapshot.quotas) tokens.push(q.token);
|
|
222
|
+
const decimals = {};
|
|
223
|
+
const prices = {};
|
|
224
|
+
const liquidationThresholds = {};
|
|
225
|
+
const activeQuotas = {};
|
|
226
|
+
const quotaRates = {};
|
|
227
|
+
for (const token of tokens) {
|
|
228
|
+
const meta = this.sdk.tokensMeta.get(token);
|
|
229
|
+
if (meta) decimals[token] = meta.decimals;
|
|
230
|
+
try {
|
|
231
|
+
prices[token] = priceOracle.mainPrice(token);
|
|
232
|
+
} catch {}
|
|
233
|
+
const lt = cm.liquidationThresholds.get(token);
|
|
234
|
+
if (lt !== void 0) liquidationThresholds[token] = lt;
|
|
235
|
+
if (pqk.hasActiveQuota(token)) {
|
|
236
|
+
activeQuotas[token] = true;
|
|
237
|
+
quotaRates[token] = pqk.quotaRate(token);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
underlying,
|
|
242
|
+
decimals,
|
|
243
|
+
prices,
|
|
244
|
+
liquidationThresholds,
|
|
245
|
+
activeQuotas,
|
|
246
|
+
quotaRates,
|
|
247
|
+
baseInterestRate: pool.baseInterestRate,
|
|
248
|
+
feeInterest: cm.feeInterest
|
|
249
|
+
};
|
|
250
|
+
}
|
|
46
251
|
};
|
|
47
252
|
//#endregion
|
|
48
253
|
export { PositionsService };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
+
import { PERCENTAGE_FACTOR } from "../constants/math.js";
|
|
3
|
+
import { calcBorrowApy } from "../market/math.js";
|
|
4
|
+
//#region src/sdk/positions/calcBorrowRate.ts
|
|
5
|
+
/**
|
|
6
|
+
* Cost of an account state's debt, broken down into the pool's base rate and
|
|
7
|
+
* per-token quota rates.
|
|
8
|
+
*
|
|
9
|
+
* The base rate is the market's current borrow APY (the pool's base rate plus
|
|
10
|
+
* the credit manager's interest fee) — the same value `borrowApy` reports on
|
|
11
|
+
* a position; it is not recomputed for the projected pool liquidity. Quota
|
|
12
|
+
* contributions are `quotaBalance * quotaRate` with the interest fee on top,
|
|
13
|
+
* normalized against the total value (`total`, `quotas`) and against the
|
|
14
|
+
* debt (`totalOnDebt`, the rate the debt itself grows at). Formulas are in
|
|
15
|
+
* parity with the frontend's `BorrowRateUtils`.
|
|
16
|
+
**/
|
|
17
|
+
function calcBorrowRate(props) {
|
|
18
|
+
const { snapshot, baseInterestRate, feeInterest, quotaRates } = props;
|
|
19
|
+
const { quotas, totalDebt, totalValue } = snapshot;
|
|
20
|
+
const rates = new AddressMap(Object.entries(quotaRates));
|
|
21
|
+
const base = calcBorrowApy(baseInterestRate, feeInterest);
|
|
22
|
+
const fee = PERCENTAGE_FACTOR + BigInt(feeInterest);
|
|
23
|
+
let quotaRateSum = 0n;
|
|
24
|
+
const perQuota = {};
|
|
25
|
+
for (const q of quotas) {
|
|
26
|
+
if (q.balance <= 10n) continue;
|
|
27
|
+
const rate = rates.get(q.token);
|
|
28
|
+
const rateBalance = rate === void 0 ? 0n : q.balance * BigInt(rate);
|
|
29
|
+
quotaRateSum += rateBalance;
|
|
30
|
+
const withFee = rateBalance * fee / PERCENTAGE_FACTOR;
|
|
31
|
+
perQuota[q.token] = totalValue > 0n ? Number(withFee / totalValue) : 0;
|
|
32
|
+
}
|
|
33
|
+
const quotaRateSumWithFee = quotaRateSum * fee / PERCENTAGE_FACTOR;
|
|
34
|
+
return {
|
|
35
|
+
total: totalValue > 0n ? Number(totalDebt * BigInt(base) / totalValue) + Number(quotaRateSumWithFee / totalValue) : 0,
|
|
36
|
+
totalOnDebt: totalDebt > 0n ? base + Number(quotaRateSumWithFee / totalDebt) : 0,
|
|
37
|
+
base,
|
|
38
|
+
quotas: perQuota
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { calcBorrowRate };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
+
import { BigIntMath } from "../utils/bigint-math.js";
|
|
3
|
+
import { MAX_UINT16, PERCENTAGE_FACTOR } from "../constants/math.js";
|
|
4
|
+
import { isAddressEqual } from "viem";
|
|
5
|
+
//#region src/sdk/positions/calcHealthFactor.ts
|
|
6
|
+
/**
|
|
7
|
+
* Health factor of an account state, in basis points (`10000` = 1.0).
|
|
8
|
+
*
|
|
9
|
+
* Collateral is valued under liquidation thresholds, with quoted tokens
|
|
10
|
+
* capped by their quota, and compared against the debt's value. An account
|
|
11
|
+
* with no debt reports `65535` (`MAX_UINT16`), the contract's own sentinel
|
|
12
|
+
* scaled down. Formulas are in parity with the legacy `calcHealthFactor`.
|
|
13
|
+
* Tokens with no price in {@link CalcHealthFactorProps.prices} contribute
|
|
14
|
+
* nothing.
|
|
15
|
+
**/
|
|
16
|
+
function calcHealthFactor(props) {
|
|
17
|
+
const { snapshot, underlying, decimals, prices, liquidationThresholds, activeQuotas } = props;
|
|
18
|
+
if (snapshot.totalDebt === 0n) return Number(MAX_UINT16);
|
|
19
|
+
const decimalsByToken = new AddressMap(Object.entries(decimals));
|
|
20
|
+
const pricesByToken = new AddressMap(Object.entries(prices));
|
|
21
|
+
const lts = new AddressMap(Object.entries(liquidationThresholds));
|
|
22
|
+
const active = new AddressMap(Object.entries(activeQuotas));
|
|
23
|
+
const convertToUSD = (token, amount) => {
|
|
24
|
+
const price = pricesByToken.get(token);
|
|
25
|
+
if (price === void 0) return null;
|
|
26
|
+
const scale = 10n ** BigInt(decimalsByToken.get(token) ?? 18);
|
|
27
|
+
return amount * price / scale;
|
|
28
|
+
};
|
|
29
|
+
const assetMoney = snapshot.assets.reduce((acc, { token, balance }) => {
|
|
30
|
+
if (balance <= 10n) return acc;
|
|
31
|
+
const lt = BigInt(lts.get(token) ?? 0);
|
|
32
|
+
const tokenLtWeighted = (convertToUSD(token, balance) ?? 0n) * lt;
|
|
33
|
+
const quota = snapshot.quotas.find((q) => isAddressEqual(q.token, token));
|
|
34
|
+
const quotaBalance = quota && (active.get(token) ?? false) ? quota.balance : 0n;
|
|
35
|
+
const quotaWeighted = (convertToUSD(underlying, quotaBalance) ?? 0n) * PERCENTAGE_FACTOR;
|
|
36
|
+
return acc + (quota ? BigIntMath.min(quotaWeighted, tokenLtWeighted) : tokenLtWeighted);
|
|
37
|
+
}, 0n);
|
|
38
|
+
const borrowedMoney = convertToUSD(underlying, snapshot.totalDebt) ?? 0n;
|
|
39
|
+
const hf = borrowedMoney > 0n ? assetMoney / borrowedMoney : 0n;
|
|
40
|
+
return Number(hf);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { calcHealthFactor };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "../constants/math.js";
|
|
2
|
+
import { calcLiquidationPriceForTarget } from "./calcLiquidationPriceForTarget.js";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
4
|
+
//#region src/sdk/positions/calcLiquidationPrice.ts
|
|
5
|
+
/**
|
|
6
|
+
* Liquidation price of an account state's target collateral, in the oracle's
|
|
7
|
+
* 8-decimal (`PRICE_DECIMALS`) fixed point.
|
|
8
|
+
*
|
|
9
|
+
* As the frontend does, a liquidation price only exists when the account
|
|
10
|
+
* holds exactly one non-dust non-underlying asset; otherwise `null`.
|
|
11
|
+
**/
|
|
12
|
+
function calcLiquidationPrice(props) {
|
|
13
|
+
const { snapshot, underlying } = props;
|
|
14
|
+
const targets = snapshot.assets.filter((a) => a.balance > 10n && !isAddressEqual(a.token, underlying));
|
|
15
|
+
if (targets.length !== 1) return null;
|
|
16
|
+
return calcLiquidationPriceForTarget({
|
|
17
|
+
...props,
|
|
18
|
+
targetToken: targets[0].token
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { calcLiquidationPrice };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
|
+
import { PERCENTAGE_FACTOR, PRICE_DECIMALS, WAD } from "../constants/math.js";
|
|
3
|
+
import { isAddressEqual } from "viem";
|
|
4
|
+
//#region src/sdk/positions/calcLiquidationPriceForTarget.ts
|
|
5
|
+
/**
|
|
6
|
+
* Liquidation price of an explicitly named collateral token, in
|
|
7
|
+
* `PRICE_DECIMALS` fixed point; `0n` when the account holds none of it or the
|
|
8
|
+
* token has no liquidation threshold. Formula is in parity with the legacy
|
|
9
|
+
* `liquidationPrice`: the effective debt (debt less the underlying balance's
|
|
10
|
+
* contribution under its threshold) over the threshold-weighted target
|
|
11
|
+
* balance.
|
|
12
|
+
**/
|
|
13
|
+
function calcLiquidationPriceForTarget(props) {
|
|
14
|
+
const { snapshot, targetToken, underlying, decimals, liquidationThresholds } = props;
|
|
15
|
+
const decimalsByToken = new AddressMap(Object.entries(decimals));
|
|
16
|
+
const lts = new AddressMap(Object.entries(liquidationThresholds));
|
|
17
|
+
const underlyingDecimals = decimalsByToken.get(underlying) ?? 18;
|
|
18
|
+
const underlyingBalance = snapshot.assets.find((a) => isAddressEqual(a.token, underlying))?.balance ?? 0n;
|
|
19
|
+
const ltUnderlying = BigInt(lts.get(underlying) ?? 0);
|
|
20
|
+
const effectiveDebt = (snapshot.totalDebt - underlyingBalance * ltUnderlying / PERCENTAGE_FACTOR) * WAD / 10n ** BigInt(underlyingDecimals);
|
|
21
|
+
const targetDecimals = decimalsByToken.get(targetToken) ?? 18;
|
|
22
|
+
const targetBalance = snapshot.assets.find((a) => isAddressEqual(a.token, targetToken))?.balance ?? 0n;
|
|
23
|
+
const effectiveTargetBalance = targetBalance * WAD / 10n ** BigInt(targetDecimals);
|
|
24
|
+
const lpLT = BigInt(lts.get(targetToken) ?? 0);
|
|
25
|
+
if (targetBalance <= 10n || lpLT <= 0n) return 0n;
|
|
26
|
+
return effectiveDebt * PRICE_DECIMALS * PERCENTAGE_FACTOR / (effectiveTargetBalance * lpLT);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { calcLiquidationPriceForTarget };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PERCENTAGE_DECIMALS, PERCENTAGE_FACTOR, SECONDS_PER_YEAR } from "../constants/math.js";
|
|
2
|
+
//#region src/sdk/positions/calcTimeToLiquidationMs.ts
|
|
3
|
+
/**
|
|
4
|
+
* Estimated milliseconds until `healthFactorBps` decays to `10000` (1.0)
|
|
5
|
+
* while the debt grows at `totalBorrowRateOnDebt` (basis points relative to
|
|
6
|
+
* the debt, as {@link BorrowRateBreakdown.totalOnDebt} reports it).
|
|
7
|
+
*
|
|
8
|
+
* `null` when the account is already at or under the liquidation threshold,
|
|
9
|
+
* or when the debt carries no borrow rate at all. Formula is in parity with
|
|
10
|
+
* the legacy `getTimeToLiquidation`.
|
|
11
|
+
**/
|
|
12
|
+
function calcTimeToLiquidationMs(healthFactorBps, totalBorrowRateOnDebt) {
|
|
13
|
+
if (BigInt(healthFactorBps) <= 10000n || totalBorrowRateOnDebt === 0n) return null;
|
|
14
|
+
return (BigInt(healthFactorBps) - PERCENTAGE_FACTOR) * (BigInt(SECONDS_PER_YEAR) * PERCENTAGE_FACTOR * PERCENTAGE_DECIMALS / totalBorrowRateOnDebt) * 1000n / PERCENTAGE_FACTOR;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { calcTimeToLiquidationMs };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { calcBorrowRate } from "./calcBorrowRate.js";
|
|
2
|
+
import { calcHealthFactor } from "./calcHealthFactor.js";
|
|
3
|
+
import { calcLiquidationPriceForTarget } from "./calcLiquidationPriceForTarget.js";
|
|
4
|
+
import { calcLiquidationPrice } from "./calcLiquidationPrice.js";
|
|
5
|
+
import { calcTimeToLiquidationMs } from "./calcTimeToLiquidationMs.js";
|
|
1
6
|
import { MultichainPositionsService } from "./MultichainPositionsService.js";
|
|
7
|
+
import { accountSnapshotFromCreditAccountData } from "./types.js";
|
|
2
8
|
import { PositionsService } from "./PositionsService.js";
|
|
3
|
-
|
|
4
|
-
export { MultichainPositionsService, PositionsService };
|
|
9
|
+
export { MultichainPositionsService, PositionsService, accountSnapshotFromCreditAccountData, calcBorrowRate, calcHealthFactor, calcLiquidationPrice, calcLiquidationPriceForTarget, calcTimeToLiquidationMs };
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import "../constants/math.js";
|
|
2
|
+
//#region src/sdk/positions/types.ts
|
|
3
|
+
/**
|
|
4
|
+
* Builds an {@link AccountSnapshot} from on-chain credit account data: the
|
|
5
|
+
* enabled, above-dust tokens become assets and quotas, and `totalDebt` is
|
|
6
|
+
* principal plus accrued interest and fees.
|
|
7
|
+
**/
|
|
8
|
+
function accountSnapshotFromCreditAccountData(ca) {
|
|
9
|
+
const assets = [];
|
|
10
|
+
const quotas = [];
|
|
11
|
+
for (const t of ca.tokens) {
|
|
12
|
+
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
|
|
13
|
+
assets.push({
|
|
14
|
+
token: t.token,
|
|
15
|
+
balance: t.balance
|
|
16
|
+
});
|
|
17
|
+
quotas.push({
|
|
18
|
+
token: t.token,
|
|
19
|
+
balance: t.quota
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
creditManager: ca.creditManager,
|
|
24
|
+
assets,
|
|
25
|
+
quotas,
|
|
26
|
+
totalDebt: ca.debt + ca.accruedInterest + ca.accruedFees,
|
|
27
|
+
totalValue: ca.totalValue
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { accountSnapshotFromCreditAccountData };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
2
|
import { generateCastTraceCall } from "./cast.js";
|
|
3
|
+
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -6,6 +6,8 @@ interface GetSingleQuotaBorrowRateRate extends CalcQuotaBorrowRateProps {
|
|
|
6
6
|
/**
|
|
7
7
|
* Under the hood sums up rates for all given quotas and then multiplies them by 1+feeInterest,
|
|
8
8
|
* but it is expected that the ONLY quota will be passed
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
9
11
|
*/
|
|
10
12
|
declare function getSingleQuotaBorrowRate(props: GetSingleQuotaBorrowRateRate): bigint;
|
|
11
13
|
//#endregion
|
|
@@ -23,6 +23,9 @@ interface CalcHealthFactorProps {
|
|
|
23
23
|
* @param props Credit account balances, quotas, prices, thresholds, and debt context.
|
|
24
24
|
* @returns Health factor as a number in `PERCENTAGE_FACTOR` scale,
|
|
25
25
|
* or `65535` when debt is zero.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use `calcHealthFactor` from `sdk/positions` instead; this
|
|
28
|
+
* wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
26
29
|
*/
|
|
27
30
|
declare function calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList }: CalcHealthFactorProps): number;
|
|
28
31
|
//#endregion
|
|
@@ -16,6 +16,8 @@ interface CalcQuotaBorrowRateProps {
|
|
|
16
16
|
*
|
|
17
17
|
* @param props Quota balances and per-token quota rates.
|
|
18
18
|
* @returns Sum of `balance * rate` terms in percentage-factor scale.
|
|
19
|
+
*
|
|
20
|
+
* @deprecated Use `calcBorrowRate` from `sdk/positions` instead.
|
|
19
21
|
*/
|
|
20
22
|
declare function calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
|
|
21
23
|
//#endregion
|
|
@@ -13,6 +13,9 @@ interface TimeToLiquidationProps {
|
|
|
13
13
|
* @param props Current health factor and `totalBorrowRate * debt` term.
|
|
14
14
|
* @returns Milliseconds to liquidation as `bigint`, or `null` when already at/under
|
|
15
15
|
* liquidation threshold or when borrow-rate exposure is zero.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Use `calcTimeToLiquidationMs` from `sdk/positions` instead;
|
|
18
|
+
* this wrapper only forwards to the new implementation.
|
|
16
19
|
*/
|
|
17
20
|
declare function getTimeToLiquidation({ healthFactor, totalBorrowRate_debt }: TimeToLiquidationProps): bigint | null;
|
|
18
21
|
//#endregion
|
|
@@ -22,6 +22,9 @@ interface LiquidationPriceProps {
|
|
|
22
22
|
* @param props Debt context, assets, thresholds, and token metadata.
|
|
23
23
|
* @returns Target token price in `PRICE_DECIMALS` precision that corresponds
|
|
24
24
|
* to liquidation boundary; returns `0n` when target balance or LT is non-positive.
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Use `calcLiquidationPriceForTarget` from `sdk/positions`
|
|
27
|
+
* instead; this wrapper only maps the legacy props onto an `AccountSnapshot`.
|
|
25
28
|
*/
|
|
26
29
|
declare function liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, tokensList }: LiquidationPriceProps): bigint;
|
|
27
30
|
//#endregion
|
|
@@ -5,13 +5,13 @@ import { ChainScopedFilter, FILTER_ALL, FilterAll, Filterable, isFilterSet } fro
|
|
|
5
5
|
import { booleanParamSchema, encodeFlag, filterAllSchema, filterable } from "./filters.schema.js";
|
|
6
6
|
import { ApyBreakdown, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityId, OpportunityKey, OpportunityKind, PointRewards, PointsProgram, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, Rewards, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, TokenRewards, matchesOpportunityFilter, opportunityId, poolOpportunityId, strategyOpportunityId } from "./opportunities.js";
|
|
7
7
|
import { DelayedReceivedAsset, InstantReceivedAsset, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, ReceivedAsset, matchesLiquidatableAccountFilter } from "./liquidations.js";
|
|
8
|
-
import { PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, RewardsPnL, StrategyPosition, StrategyPositionKey, StrategyPositionRef, TokenRewardsPnL, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
8
|
+
import { BorrowRateBreakdown, PnlBreakdown, PointsProgramPnL, PointsRewardsPnL, PoolPosition, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionId, PositionKey, PositionKind, PositionMetrics, RewardsPnL, StrategyPosition, StrategyPositionKey, StrategyPositionRef, TokenRewardsPnL, liquidationPositionId, matchesPositionFilter, poolPositionId, positionId, strategyPositionId } from "./positions.js";
|
|
9
9
|
import { HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, OpportunityHistoryQuery, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PoolHistoryMetric, PoolPositionHistoryMetric, PositionHistoryMetric, PositionHistoryQuery, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyPositionHistoryMetric } from "./history.js";
|
|
10
10
|
import { historyChartMetadataSchema, historyMetricSchema, historyPointSchema, historyRangeSchema, historySeriesSchema, opportunityHistoryQuerySchema, poolHistoryMetricSchema, poolPositionHistoryMetricSchema, positionHistoryMetricSchema, positionHistoryQuerySchema, strategyHistoryMetricSchema, strategyPositionHistoryMetricSchema } from "./history.schema.js";
|
|
11
11
|
import { delayedReceivedAssetSchema, instantReceivedAssetSchema, liquidatableAccountFilterSchema, liquidatableAccountSchema, liquidationApprovalSchema, liquidationDetailsSchema, liquidationPositionSchema, receivedAssetSchema } from "./liquidations.schema.js";
|
|
12
12
|
import { apyBreakdownSchema, opportunityBaseSchema, opportunityDetailSchema, opportunityFilterQueryParamsSchema, opportunityFilterQuerySchema, opportunityFilterSchema, opportunityKeySchema, opportunityKindSchema, opportunitySchema, pointRewardsSchema, pointsProgramSchema, poolOpportunityDetailSchema, poolOpportunityKeySchema, poolOpportunitySchema, priceFeedDataSchema, priceFeedSummarySchema, quotaAssetSchema, rateCurvePointSchema, rateCurveSchema, rewardsSchema, strategyOpportunityDetailSchema, strategyOpportunityKeySchema, strategyOpportunitySchema, tokenRewardsSchema } from "./opportunities.schema.js";
|
|
13
|
-
import { pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
13
|
+
import { borrowRateBreakdownSchema, pnlBreakdownSchema, pointsProgramPnLSchema, pointsRewardsPnLSchema, poolPositionKeySchema, poolPositionSchema, positionCollateralSchema, positionFilterQueryParamsSchema, positionFilterQuerySchema, positionFilterSchema, positionKeySchema, positionKindSchema, positionSchema, rewardsPnLSchema, strategyPositionKeySchema, strategyPositionSchema, tokenRewardsPnLSchema } from "./positions.schema.js";
|
|
14
14
|
import { amountSchema, assetTypeSchema, bpsSchema, chainIdSchema, leverageSchema, timestampSchema, tokenAmountSchema, tokenSchema, txCallSchema } from "./primitives.schema.js";
|
|
15
15
|
import { ChainFailed, ChainMetadata, ChainScoped, ChainSucceeded, DataResponse, DataSource, ResponseMetadata } from "./response.js";
|
|
16
16
|
import { chainFailedSchema, chainMetadataSchema, chainSucceededSchema, dataSourceSchema, responseMetadataSchema, responseSchema } from "./response.schema.js";
|
|
17
|
-
export { Amount, ApyBreakdown, AssetType, Bps, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, Curator, CuratorName, DataResponse, DataSource, DelayedReceivedAsset, FILTER_ALL, FilterAll, Filterable, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionHistoryMetric, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionHistoryMetric, PositionHistoryQuery, PositionId, PositionKey, PositionKind, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, ResponseMetadata, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionHistoryMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, 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, positionFilterQueryParamsSchema, positionFilterQuerySchema, 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 };
|
|
17
|
+
export { Amount, ApyBreakdown, AssetType, BorrowRateBreakdown, Bps, ChainFailed, ChainId, ChainMetadata, ChainScoped, ChainScopedFilter, ChainSucceeded, Curator, CuratorName, DataResponse, DataSource, DelayedReceivedAsset, FILTER_ALL, FilterAll, Filterable, HistoryChartMetadata, HistoryMetric, HistoryPoint, HistoryRange, HistorySeries, InstantReceivedAsset, Leverage, LiquidatableAccount, LiquidatableAccountFilter, LiquidationApproval, LiquidationDetails, LiquidationPosition, Opportunity, OpportunityBase, OpportunityDetail, OpportunityFilter, OpportunityHistoryQuery, OpportunityId, OpportunityKey, OpportunityKind, POOL_HISTORY_METRICS, POOL_POSITION_HISTORY_METRICS, PnlBreakdown, PointRewards, PointsProgram, PointsProgramPnL, PointsRewardsPnL, PoolHistoryMetric, PoolOpportunity, PoolOpportunityDetail, PoolOpportunityKey, PoolOpportunityRef, PoolPosition, PoolPositionHistoryMetric, PoolPositionKey, PoolPositionRef, Position, PositionCollateral, PositionFilter, PositionHistoryMetric, PositionHistoryQuery, PositionId, PositionKey, PositionKind, PositionMetrics, PriceFeedData, PriceFeedSummary, QuotaAsset, RateCurve, RateCurvePoint, ReceivedAsset, ResponseMetadata, Rewards, RewardsPnL, STRATEGY_HISTORY_METRICS, STRATEGY_POSITION_HISTORY_METRICS, StrategyHistoryMetric, StrategyOpportunity, StrategyOpportunityDetail, StrategyOpportunityKey, StrategyOpportunityRef, StrategyPosition, StrategyPositionHistoryMetric, StrategyPositionKey, StrategyPositionRef, Timestamp, Token, TokenAmount, TokenRewards, TokenRewardsPnL, TxCall, amountSchema, apyBreakdownSchema, assetTypeSchema, booleanParamSchema, borrowRateBreakdownSchema, bpsSchema, chainFailedSchema, chainIdSchema, chainMetadataSchema, chainSucceededSchema, curatorNameSchema, curatorSchema, dataSourceSchema, delayedReceivedAssetSchema, encodeFlag, 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, positionFilterQueryParamsSchema, positionFilterQuerySchema, 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 };
|