@gearbox-protocol/sdk 14.12.0-next.71 → 14.12.0-next.73
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/history.js +25 -0
- package/dist/cjs/model/history.schema.js +45 -1
- package/dist/cjs/model/index.js +17 -3
- package/dist/cjs/model/positions.js +89 -0
- package/dist/cjs/model/positions.schema.js +28 -0
- package/dist/cjs/new-sdk/GearboxSDK.js +7 -0
- package/dist/cjs/new-sdk/index.js +3 -0
- package/dist/cjs/new-sdk/positions/PositionsNamespace.js +119 -0
- package/dist/cjs/new-sdk/positions/index.js +4 -0
- package/dist/cjs/new-sdk/positions/types.js +1 -0
- package/dist/cjs/offchain/GearboxAPI.js +9 -2
- package/dist/cjs/offchain/index.js +5 -2
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +3 -14
- package/dist/cjs/offchain/opportunities/index.js +0 -1
- package/dist/cjs/offchain/positions/OffchainPositions.js +69 -0
- package/dist/cjs/offchain/positions/index.js +3 -0
- package/dist/cjs/offchain/types.js +17 -0
- package/dist/cjs/sdk/MultichainSDK.js +7 -0
- package/dist/cjs/sdk/OnchainSDK.js +7 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +84 -0
- package/dist/cjs/sdk/accounts/constants.js +12 -0
- package/dist/cjs/sdk/accounts/dominantCollateral.js +33 -0
- package/dist/cjs/sdk/accounts/index.js +4 -1
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +3 -10
- package/dist/cjs/sdk/accounts/liquidations/constants.js +2 -6
- package/dist/cjs/sdk/accounts/liquidations/index.js +2 -1
- package/dist/cjs/sdk/index.js +11 -1
- package/dist/cjs/sdk/market/MarketSuite.js +7 -1
- package/dist/cjs/sdk/market/credit/CreditSuite.js +10 -1
- package/dist/cjs/sdk/market/math.js +37 -0
- package/dist/cjs/sdk/opportunities/index.js +2 -0
- package/dist/cjs/sdk/pools/PoolService.js +37 -0
- package/dist/cjs/sdk/positions/MultichainPositionsService.js +48 -0
- package/dist/cjs/sdk/positions/PositionsService.js +39 -0
- package/dist/cjs/sdk/positions/index.js +6 -0
- package/dist/cjs/sdk/positions/types.js +1 -0
- package/dist/esm/model/history.js +24 -1
- package/dist/esm/model/history.schema.js +42 -2
- package/dist/esm/model/index.js +6 -6
- package/dist/esm/model/positions.js +85 -1
- package/dist/esm/model/positions.schema.js +26 -1
- package/dist/esm/new-sdk/GearboxSDK.js +7 -0
- package/dist/esm/new-sdk/index.js +3 -1
- package/dist/esm/new-sdk/positions/PositionsNamespace.js +118 -0
- package/dist/esm/new-sdk/positions/index.js +3 -0
- package/dist/esm/new-sdk/positions/types.js +1 -0
- package/dist/esm/offchain/GearboxAPI.js +9 -2
- package/dist/esm/offchain/index.js +5 -3
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +2 -12
- package/dist/esm/offchain/opportunities/index.js +2 -2
- package/dist/esm/offchain/positions/OffchainPositions.js +68 -0
- package/dist/esm/offchain/positions/index.js +2 -0
- package/dist/esm/offchain/types.js +17 -1
- package/dist/esm/sdk/MultichainSDK.js +7 -0
- package/dist/esm/sdk/OnchainSDK.js +7 -0
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +84 -0
- package/dist/esm/sdk/accounts/constants.js +11 -0
- package/dist/esm/sdk/accounts/dominantCollateral.js +32 -0
- package/dist/esm/sdk/accounts/index.js +4 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +3 -10
- package/dist/esm/sdk/accounts/liquidations/constants.js +1 -5
- package/dist/esm/sdk/accounts/liquidations/index.js +2 -1
- package/dist/esm/sdk/index.js +8 -3
- package/dist/esm/sdk/market/MarketSuite.js +7 -1
- package/dist/esm/sdk/market/credit/CreditSuite.js +10 -1
- package/dist/esm/sdk/market/math.js +37 -2
- package/dist/esm/sdk/opportunities/index.js +2 -2
- package/dist/esm/sdk/pools/PoolService.js +37 -0
- package/dist/esm/sdk/positions/MultichainPositionsService.js +47 -0
- package/dist/esm/sdk/positions/PositionsService.js +38 -0
- package/dist/esm/sdk/positions/index.js +4 -0
- package/dist/esm/sdk/positions/types.js +1 -0
- package/dist/types/model/history.d.ts +50 -2
- package/dist/types/model/history.schema.d.ts +32 -3
- package/dist/types/model/index.d.ts +5 -5
- package/dist/types/model/positions.d.ts +100 -1
- package/dist/types/model/positions.schema.d.ts +29 -1
- package/dist/types/new-sdk/AbstractNamespace.d.ts +2 -2
- package/dist/types/new-sdk/GearboxSDK.d.ts +6 -0
- package/dist/types/new-sdk/index.d.ts +4 -1
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +1 -1
- package/dist/types/new-sdk/positions/PositionsNamespace.d.ts +62 -0
- package/dist/types/new-sdk/positions/index.d.ts +3 -0
- package/dist/types/new-sdk/positions/types.d.ts +62 -0
- package/dist/types/new-sdk/utils/history.d.ts +6 -2
- package/dist/types/offchain/GearboxAPI.d.ts +8 -2
- package/dist/types/offchain/index.d.ts +5 -3
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -9
- package/dist/types/offchain/opportunities/index.d.ts +2 -2
- package/dist/types/offchain/positions/OffchainPositions.d.ts +47 -0
- package/dist/types/offchain/positions/index.d.ts +2 -0
- package/dist/types/offchain/types.d.ts +12 -1
- package/dist/types/sdk/MultichainSDK.d.ts +6 -0
- package/dist/types/sdk/OnchainSDK.d.ts +6 -0
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +7 -1
- package/dist/types/sdk/accounts/constants.d.ts +11 -0
- package/dist/types/sdk/accounts/dominantCollateral.d.ts +22 -0
- package/dist/types/sdk/accounts/index.d.ts +5 -3
- package/dist/types/sdk/accounts/liquidations/MultichainLiquidationsService.d.ts +2 -2
- package/dist/types/sdk/accounts/liquidations/constants.d.ts +1 -5
- package/dist/types/sdk/accounts/liquidations/index.d.ts +2 -1
- package/dist/types/sdk/accounts/liquidations/types.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +26 -1
- package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
- package/dist/types/sdk/index.d.ts +11 -5
- package/dist/types/sdk/market/MarketConfiguratorContract.d.ts +1 -1
- package/dist/types/sdk/market/MarketSuite.d.ts +5 -1
- package/dist/types/sdk/market/credit/CreditManagerV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/credit/CreditSuite.d.ts +8 -1
- package/dist/types/sdk/market/credit/types.d.ts +1 -1
- package/dist/types/sdk/market/math.d.ts +29 -1
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +2 -2
- package/dist/types/sdk/market/oracle/types.d.ts +2 -2
- package/dist/types/sdk/market/pool/LinearInterestRateModelContract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolQuotaKeeperV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolSuite.d.ts +1 -1
- package/dist/types/sdk/market/pool/PoolV310Contract.d.ts +1 -1
- package/dist/types/sdk/market/pool/types.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +1 -1
- package/dist/types/sdk/market/pricefeeds/types.d.ts +1 -1
- package/dist/types/sdk/opportunities/MultichainOpportunitiesService.d.ts +2 -2
- package/dist/types/sdk/opportunities/index.d.ts +2 -2
- package/dist/types/sdk/pools/PoolService.d.ts +7 -1
- package/dist/types/sdk/pools/index.d.ts +2 -2
- package/dist/types/sdk/pools/types.d.ts +18 -1
- package/dist/types/sdk/positions/MultichainPositionsService.d.ts +33 -0
- package/dist/types/sdk/positions/PositionsService.d.ts +22 -0
- package/dist/types/sdk/positions/index.d.ts +4 -0
- package/dist/types/sdk/positions/types.d.ts +25 -0
- package/package.json +1 -1
|
@@ -8,6 +8,8 @@ require("./accounts/index.js");
|
|
|
8
8
|
require("./core/index.js");
|
|
9
9
|
const require_sdk_opportunities_MultichainOpportunitiesService = require("./opportunities/MultichainOpportunitiesService.js");
|
|
10
10
|
require("./opportunities/index.js");
|
|
11
|
+
const require_sdk_positions_MultichainPositionsService = require("./positions/MultichainPositionsService.js");
|
|
12
|
+
require("./positions/index.js");
|
|
11
13
|
const require_sdk_OnchainSDK = require("./OnchainSDK.js");
|
|
12
14
|
//#region src/sdk/MultichainSDK.ts
|
|
13
15
|
/**
|
|
@@ -30,6 +32,10 @@ var MultichainSDK = class {
|
|
|
30
32
|
* chains.
|
|
31
33
|
*/
|
|
32
34
|
opportunities;
|
|
35
|
+
/**
|
|
36
|
+
* Namespace for the positions a wallet holds on all configured chains.
|
|
37
|
+
*/
|
|
38
|
+
positions;
|
|
33
39
|
constructor(options) {
|
|
34
40
|
this.#chains = /* @__PURE__ */ new Map();
|
|
35
41
|
this.#logger = options.logger;
|
|
@@ -48,6 +54,7 @@ var MultichainSDK = class {
|
|
|
48
54
|
}
|
|
49
55
|
this.liquidations = new require_sdk_accounts_liquidations_MultichainLiquidationsService.MultichainLiquidationsService(this);
|
|
50
56
|
this.opportunities = new require_sdk_opportunities_MultichainOpportunitiesService.MultichainOpportunitiesService(this);
|
|
57
|
+
this.positions = new require_sdk_positions_MultichainPositionsService.MultichainPositionsService(this);
|
|
51
58
|
}
|
|
52
59
|
/**
|
|
53
60
|
* Attach all configured chains in parallel.
|
|
@@ -31,6 +31,8 @@ const require_sdk_plugins_errors = require("./plugins/errors.js");
|
|
|
31
31
|
require("./plugins/index.js");
|
|
32
32
|
const require_sdk_pools_PoolService = require("./pools/PoolService.js");
|
|
33
33
|
require("./pools/index.js");
|
|
34
|
+
const require_sdk_positions_PositionsService = require("./positions/PositionsService.js");
|
|
35
|
+
require("./positions/index.js");
|
|
34
36
|
const require_sdk_router_createRouter = require("./router/createRouter.js");
|
|
35
37
|
require("./router/index.js");
|
|
36
38
|
let viem = require("viem");
|
|
@@ -113,6 +115,10 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
113
115
|
*/
|
|
114
116
|
opportunities;
|
|
115
117
|
/**
|
|
118
|
+
* Namespace for the positions a wallet holds on this chain.
|
|
119
|
+
*/
|
|
120
|
+
positions;
|
|
121
|
+
/**
|
|
116
122
|
* @param network - Gearbox network type (e.g. `"Mainnet"`, `"Monad"`).
|
|
117
123
|
* @param clientOptions - Connection options (RPC URLs, transport, or client).
|
|
118
124
|
* @param options - SDK configuration options.
|
|
@@ -134,6 +140,7 @@ var OnchainSDK = class extends require_sdk_base_ChainContractsRegister.ChainCont
|
|
|
134
140
|
this.pools = new require_sdk_pools_PoolService.PoolService(this);
|
|
135
141
|
this.liquidations = new require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService(this);
|
|
136
142
|
this.opportunities = new require_sdk_opportunities_OpportunitiesService.OpportunitiesService(this);
|
|
143
|
+
this.positions = new require_sdk_positions_PositionsService.PositionsService(this);
|
|
137
144
|
this.#withdrawalCompressor = require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor.createWithdrawalCompressor(this);
|
|
138
145
|
}
|
|
139
146
|
/**
|
|
@@ -18,10 +18,13 @@ const require_sdk_utils_hex = require("../utils/hex.js");
|
|
|
18
18
|
require("../utils/index.js");
|
|
19
19
|
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
20
20
|
require("../base/index.js");
|
|
21
|
+
const require_sdk_market_math = require("../market/math.js");
|
|
21
22
|
const require_sdk_utils_viem_simulateWithPriceUpdates = require("../utils/viem/simulateWithPriceUpdates.js");
|
|
22
23
|
require("../utils/viem/index.js");
|
|
23
24
|
const require_sdk_market_pricefeeds_getRawPriceUpdates = require("../market/pricefeeds/getRawPriceUpdates.js");
|
|
24
25
|
require("../market/index.js");
|
|
26
|
+
require("./constants.js");
|
|
27
|
+
const require_sdk_accounts_dominantCollateral = require("./dominantCollateral.js");
|
|
25
28
|
const require_sdk_accounts_multicall_utils = require("./multicall-utils.js");
|
|
26
29
|
let viem = require("viem");
|
|
27
30
|
//#region src/sdk/accounts/CreditAccountsServiceV310.ts
|
|
@@ -219,6 +222,87 @@ var CreditAccountsServiceV310 = class extends require_sdk_base_SDKConstruct.SDKC
|
|
|
219
222
|
return filtered.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
220
223
|
}
|
|
221
224
|
/**
|
|
225
|
+
* {@inheritDoc ICreditAccountsService.listPositions}
|
|
226
|
+
**/
|
|
227
|
+
async listPositions(props) {
|
|
228
|
+
const { owner, includeZeroDebt } = props;
|
|
229
|
+
const [accounts] = await Promise.all([this.getBorrowerCreditAccounts(owner, { includeZeroDebt }), this.sdk.withdrawalCompressor?.loadWithdrawableAssets()]);
|
|
230
|
+
const describable = accounts.filter((ca) => {
|
|
231
|
+
if (!ca.success) this.logger?.warn(`cannot describe position of ${this.labelAddress(ca.creditAccount)}: collateral computation failed`);
|
|
232
|
+
return ca.success;
|
|
233
|
+
});
|
|
234
|
+
const withdrawals = await Promise.all(describable.map((ca) => this.#accountWithdrawals(ca)));
|
|
235
|
+
return describable.map((ca, i) => this.#strategyPosition(ca, withdrawals[i] ?? new require_sdk_utils_AddressMap.AddressMap()));
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Builds one strategy position from an account snapshot.
|
|
239
|
+
*
|
|
240
|
+
* @param withdrawals - Delayed withdrawals of the account, keyed by the
|
|
241
|
+
* phantom token that represents them on it.
|
|
242
|
+
**/
|
|
243
|
+
#strategyPosition(ca, withdrawals) {
|
|
244
|
+
const suite = this.sdk.marketRegister.findCreditManager(ca.creditManager);
|
|
245
|
+
const { market } = suite;
|
|
246
|
+
const { priceOracle } = market;
|
|
247
|
+
const { pool } = market.pool;
|
|
248
|
+
const token = this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying);
|
|
249
|
+
const totalDebtValue = ca.debt + ca.accruedInterest + ca.accruedFees;
|
|
250
|
+
const collateral = require_sdk_accounts_dominantCollateral.dominantCollateral(ca, market);
|
|
251
|
+
return {
|
|
252
|
+
kind: "strategy",
|
|
253
|
+
chainId: this.sdk.chainId,
|
|
254
|
+
creditManager: ca.creditManager,
|
|
255
|
+
creditAccount: ca.creditAccount,
|
|
256
|
+
name: collateral ? suite.strategyName(collateral) : token.symbol,
|
|
257
|
+
targetCollateral: collateral ? this.sdk.tokensMeta.mustGetToken(collateral) : null,
|
|
258
|
+
leverage: require_sdk_market_math.positionLeverage(totalDebtValue, ca.totalValue),
|
|
259
|
+
borrowApy: require_sdk_market_math.borrowApyBps(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
260
|
+
totalDebt: {
|
|
261
|
+
token,
|
|
262
|
+
value: totalDebtValue,
|
|
263
|
+
valueUsd: require_sdk_market_math.usdToNumber(ca.totalDebtUSD)
|
|
264
|
+
},
|
|
265
|
+
totalValue: {
|
|
266
|
+
token,
|
|
267
|
+
value: ca.totalValue,
|
|
268
|
+
valueUsd: require_sdk_market_math.usdToNumber(ca.totalValueUSD)
|
|
269
|
+
},
|
|
270
|
+
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
271
|
+
collaterals: ca.tokens.flatMap((t) => {
|
|
272
|
+
if ((t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) return [];
|
|
273
|
+
return [{
|
|
274
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
275
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
276
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
277
|
+
}];
|
|
278
|
+
})
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Delayed withdrawals of one account, keyed by the phantom token that
|
|
283
|
+
* represents them on it, so that each collateral row can pick up its own.
|
|
284
|
+
**/
|
|
285
|
+
async #accountWithdrawals(ca) {
|
|
286
|
+
const compressor = this.sdk.withdrawalCompressor;
|
|
287
|
+
const byPhantomToken = new require_sdk_utils_AddressMap.AddressMap(void 0, "accountWithdrawals");
|
|
288
|
+
const holdsPhantomToken = ca.tokens.some((t) => t.balance > 10n && compressor?.getWithdrawalSourceToken(t.token) !== void 0);
|
|
289
|
+
if (!compressor || !holdsPhantomToken) return byPhantomToken;
|
|
290
|
+
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(ca.creditManager);
|
|
291
|
+
const { claimable, pending } = await compressor.getCurrentWithdrawals(ca.creditAccount);
|
|
292
|
+
const add = (w, outputs, claimableAt) => {
|
|
293
|
+
const assets = outputs.map((o) => ({
|
|
294
|
+
isDelayed: true,
|
|
295
|
+
...priceOracle.toTokenAmount(o.token, o.amount),
|
|
296
|
+
redeemer: w.redeemer,
|
|
297
|
+
claimableAt: claimableAt === void 0 ? void 0 : Number(claimableAt)
|
|
298
|
+
}));
|
|
299
|
+
byPhantomToken.upsert(w.withdrawalPhantomToken, [...byPhantomToken.get(w.withdrawalPhantomToken) ?? [], ...assets]);
|
|
300
|
+
};
|
|
301
|
+
for (const w of claimable) add(w, w.outputs);
|
|
302
|
+
for (const w of pending) add(w, w.expectedOutputs, w.claimableAt);
|
|
303
|
+
return byPhantomToken;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
222
306
|
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
223
307
|
**/
|
|
224
308
|
async getRewards(creditAccount) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/sdk/accounts/constants.ts
|
|
3
|
+
/**
|
|
4
|
+
* Token balances at or below this threshold are treated as dust and ignored,
|
|
5
|
+
* consistent with the rest of the SDK (see `filterDust`).
|
|
6
|
+
*
|
|
7
|
+
* Shared by every service that describes what a credit account holds, so that
|
|
8
|
+
* a liquidation row and a position row agree on which balances exist at all.
|
|
9
|
+
**/
|
|
10
|
+
const DUST_THRESHOLD = 10n;
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.DUST_THRESHOLD = DUST_THRESHOLD;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_utils_hex = require("../utils/hex.js");
|
|
3
|
+
require("../utils/index.js");
|
|
4
|
+
require("./constants.js");
|
|
5
|
+
//#region src/sdk/accounts/dominantCollateral.ts
|
|
6
|
+
/**
|
|
7
|
+
* The account's dominant collateral: the most valuable enabled non-underlying
|
|
8
|
+
* token it holds above dust, by USD value.
|
|
9
|
+
*
|
|
10
|
+
* This is the single definition of "what this account is a position in".
|
|
11
|
+
* Using onchain-only data we can only determine at the time of the call (without
|
|
12
|
+
* unreasably difficult calls)
|
|
13
|
+
*
|
|
14
|
+
* @param account - Account to inspect.
|
|
15
|
+
* @param market - Market of the account, whose oracle prices the candidates.
|
|
16
|
+
* @returns The dominant collateral, or `undefined` when the account holds
|
|
17
|
+
* nothing but its underlying, or nothing the oracle can price.
|
|
18
|
+
**/
|
|
19
|
+
function dominantCollateral(account, market) {
|
|
20
|
+
let bestValue = 0;
|
|
21
|
+
let dominant;
|
|
22
|
+
for (const t of account.tokens) {
|
|
23
|
+
if (require_sdk_utils_hex.hexEq(t.token, account.underlying) || (t.mask & account.enabledTokensMask) === 0n || t.balance <= 10n) continue;
|
|
24
|
+
const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
|
|
25
|
+
if (value > bestValue) {
|
|
26
|
+
bestValue = value;
|
|
27
|
+
dominant = t.token;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return dominant;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.dominantCollateral = dominantCollateral;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_constants = require("./constants.js");
|
|
3
|
+
const require_sdk_accounts_dominantCollateral = require("./dominantCollateral.js");
|
|
2
4
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./CreditAccountsServiceV310.js");
|
|
3
5
|
const require_sdk_accounts_intents_operations_claim_delayed_index = require("./intents/operations/claim-delayed/index.js");
|
|
4
6
|
const require_sdk_accounts_intents_index = require("./intents/index.js");
|
|
@@ -24,7 +26,7 @@ exports.CreditAccountOperationsService = require_sdk_accounts_intents_index.Cred
|
|
|
24
26
|
exports.CreditAccountsServiceV310 = require_sdk_accounts_CreditAccountsServiceV310.CreditAccountsServiceV310;
|
|
25
27
|
exports.DELAYED_INTENT_TYPES = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_TYPES;
|
|
26
28
|
exports.DELAYED_INTENT_VERSION = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_VERSION;
|
|
27
|
-
exports.DUST_THRESHOLD =
|
|
29
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_constants.DUST_THRESHOLD;
|
|
28
30
|
exports.InvalidDelayedIntentError = require_sdk_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
29
31
|
exports.LIQUIDATION_APPROVAL_BUFFER = require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER;
|
|
30
32
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
@@ -37,6 +39,7 @@ exports.WithdrawalCompressorV313Contract = require_sdk_accounts_withdrawal_compr
|
|
|
37
39
|
exports.createRedemptionLogger = require_sdk_accounts_withdrawal_compressor_createRedemptionLogger.createRedemptionLogger;
|
|
38
40
|
exports.createWithdrawalCompressor = require_sdk_accounts_withdrawal_compressor_createWithdrawalCompressor.createWithdrawalCompressor;
|
|
39
41
|
exports.decodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.decodeDelayedIntent;
|
|
42
|
+
exports.dominantCollateral = require_sdk_accounts_dominantCollateral.dominantCollateral;
|
|
40
43
|
exports.encodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent;
|
|
41
44
|
exports.getWithdrawalCompressorAddress = require_sdk_accounts_withdrawal_compressor_addresses.getWithdrawalCompressorAddress;
|
|
42
45
|
exports.iCreditAccountAbi = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.iCreditAccountAbi;
|
|
@@ -18,6 +18,8 @@ require("../../market/rwa/midas/index.js");
|
|
|
18
18
|
const require_sdk_market_rwa_securitize_constants = require("../../market/rwa/securitize/constants.js");
|
|
19
19
|
const require_sdk_market_rwa_securitize_SecuritizeLiquidatorContract = require("../../market/rwa/securitize/SecuritizeLiquidatorContract.js");
|
|
20
20
|
require("../../market/rwa/securitize/index.js");
|
|
21
|
+
require("../constants.js");
|
|
22
|
+
const require_sdk_accounts_dominantCollateral = require("../dominantCollateral.js");
|
|
21
23
|
const require_sdk_accounts_liquidations_constants = require("./constants.js");
|
|
22
24
|
//#region src/sdk/accounts/liquidations/LiquidationsService.ts
|
|
23
25
|
/**
|
|
@@ -280,16 +282,7 @@ var LiquidationsService = class extends require_sdk_base_SDKConstruct.SDKConstru
|
|
|
280
282
|
};
|
|
281
283
|
}
|
|
282
284
|
#mainAsset(ca, market, fallback) {
|
|
283
|
-
|
|
284
|
-
let asset;
|
|
285
|
-
for (const t of ca.tokens) {
|
|
286
|
-
if (require_sdk_utils_hex.hexEq(t.token, ca.underlying) || (t.mask & ca.enabledTokensMask) === 0n || t.balance <= 10n) continue;
|
|
287
|
-
const value = market.priceOracle.safeUsdValue(t.token, t.balance) ?? 0;
|
|
288
|
-
if (value > bestValue) {
|
|
289
|
-
bestValue = value;
|
|
290
|
-
asset = t.token;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
285
|
+
const asset = require_sdk_accounts_dominantCollateral.dominantCollateral(ca, market);
|
|
293
286
|
if (!asset) return fallback;
|
|
294
287
|
return this.sdk.withdrawalCompressor?.getWithdrawalSourceToken(asset) ?? asset;
|
|
295
288
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_constants = require("../constants.js");
|
|
2
3
|
//#region src/sdk/accounts/liquidations/constants.ts
|
|
3
4
|
const LIQUIDATION_COMPRESSOR_V313_ADDRESS = "0xB70C4500a0afF02107eB983a348F22492fB6dC94";
|
|
4
5
|
/**
|
|
5
|
-
* Token balances at or below this threshold are treated as dust and ignored,
|
|
6
|
-
* consistent with the rest of the SDK (see `filterDust`).
|
|
7
|
-
**/
|
|
8
|
-
const DUST_THRESHOLD = 10n;
|
|
9
|
-
/**
|
|
10
6
|
* Headroom (in bps) added on top of the amount the liquidation pulls when
|
|
11
7
|
* building the liquidator's approval, so that the transaction does not revert
|
|
12
8
|
* when prices move between the preview and the execution.
|
|
13
9
|
**/
|
|
14
10
|
const LIQUIDATION_APPROVAL_BUFFER = 50n;
|
|
15
11
|
//#endregion
|
|
16
|
-
exports.DUST_THRESHOLD = DUST_THRESHOLD;
|
|
12
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_constants.DUST_THRESHOLD;
|
|
17
13
|
exports.LIQUIDATION_APPROVAL_BUFFER = LIQUIDATION_APPROVAL_BUFFER;
|
|
18
14
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_accounts_constants = require("../constants.js");
|
|
2
3
|
const require_sdk_accounts_liquidations_constants = require("./constants.js");
|
|
3
4
|
const require_sdk_accounts_liquidations_LiquidationsService = require("./LiquidationsService.js");
|
|
4
5
|
const require_sdk_accounts_liquidations_MultichainLiquidationsService = require("./MultichainLiquidationsService.js");
|
|
5
6
|
require("./types.js");
|
|
6
|
-
exports.DUST_THRESHOLD =
|
|
7
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_constants.DUST_THRESHOLD;
|
|
7
8
|
exports.LIQUIDATION_APPROVAL_BUFFER = require_sdk_accounts_liquidations_constants.LIQUIDATION_APPROVAL_BUFFER;
|
|
8
9
|
exports.LIQUIDATION_COMPRESSOR_V313_ADDRESS = require_sdk_accounts_liquidations_constants.LIQUIDATION_COMPRESSOR_V313_ADDRESS;
|
|
9
10
|
exports.LiquidationsService = require_sdk_accounts_liquidations_LiquidationsService.LiquidationsService;
|
package/dist/cjs/sdk/index.js
CHANGED
|
@@ -103,6 +103,8 @@ const require_sdk_market_rwa_securitize_SecuritizeRWAFactory = require("./market
|
|
|
103
103
|
const require_sdk_market_rwa_RWARegistry = require("./market/rwa/RWARegistry.js");
|
|
104
104
|
const require_sdk_market_rwa_types = require("./market/rwa/types.js");
|
|
105
105
|
require("./market/index.js");
|
|
106
|
+
const require_sdk_accounts_constants = require("./accounts/constants.js");
|
|
107
|
+
const require_sdk_accounts_dominantCollateral = require("./accounts/dominantCollateral.js");
|
|
106
108
|
const require_sdk_accounts_CreditAccountsServiceV310 = require("./accounts/CreditAccountsServiceV310.js");
|
|
107
109
|
const require_sdk_accounts_intents_operations_claim_delayed_index = require("./accounts/intents/operations/claim-delayed/index.js");
|
|
108
110
|
const require_sdk_accounts_intents_index = require("./accounts/intents/index.js");
|
|
@@ -132,6 +134,9 @@ const require_sdk_plugins_errors = require("./plugins/errors.js");
|
|
|
132
134
|
require("./plugins/index.js");
|
|
133
135
|
const require_sdk_pools_PoolService = require("./pools/PoolService.js");
|
|
134
136
|
require("./pools/index.js");
|
|
137
|
+
const require_sdk_positions_MultichainPositionsService = require("./positions/MultichainPositionsService.js");
|
|
138
|
+
const require_sdk_positions_PositionsService = require("./positions/PositionsService.js");
|
|
139
|
+
require("./positions/index.js");
|
|
135
140
|
const require_sdk_router_helpers = require("./router/helpers.js");
|
|
136
141
|
const require_sdk_router_RouterV310Contract = require("./router/RouterV310Contract.js");
|
|
137
142
|
const require_sdk_router_createRouter = require("./router/createRouter.js");
|
|
@@ -208,7 +213,7 @@ exports.CurveStablePriceFeedContract = require_sdk_market_pricefeeds_CurveStable
|
|
|
208
213
|
exports.CurveUSDPriceFeedContract = require_sdk_market_pricefeeds_CurveUSDPriceFeed.CurveUSDPriceFeedContract;
|
|
209
214
|
exports.DELAYED_INTENT_TYPES = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_TYPES;
|
|
210
215
|
exports.DELAYED_INTENT_VERSION = require_sdk_accounts_withdrawal_compressor_intent_codec.DELAYED_INTENT_VERSION;
|
|
211
|
-
exports.DUST_THRESHOLD =
|
|
216
|
+
exports.DUST_THRESHOLD = require_sdk_accounts_constants.DUST_THRESHOLD;
|
|
212
217
|
exports.Erc4626PriceFeedContract = require_sdk_market_pricefeeds_Erc4626PriceFeed.Erc4626PriceFeedContract;
|
|
213
218
|
exports.ExternalPriceFeedContract = require_sdk_market_pricefeeds_ExternalPriceFeed.ExternalPriceFeedContract;
|
|
214
219
|
exports.GaugeContract = require_sdk_market_pool_GaugeContract.GaugeContract;
|
|
@@ -233,6 +238,7 @@ exports.MissingSerializedParamsError = require_sdk_base_errors.MissingSerialized
|
|
|
233
238
|
exports.MultichainConstruct = require_sdk_base_MultichainConstruct.MultichainConstruct;
|
|
234
239
|
exports.MultichainLiquidationsService = require_sdk_accounts_liquidations_MultichainLiquidationsService.MultichainLiquidationsService;
|
|
235
240
|
exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpportunitiesService.MultichainOpportunitiesService;
|
|
241
|
+
exports.MultichainPositionsService = require_sdk_positions_MultichainPositionsService.MultichainPositionsService;
|
|
236
242
|
exports.MultichainSDK = require_sdk_MultichainSDK.MultichainSDK;
|
|
237
243
|
exports.NATIVE_ADDRESS = require_sdk_constants_addresses.NATIVE_ADDRESS;
|
|
238
244
|
exports.NOT_DEPLOYED = require_sdk_constants_addresses.NOT_DEPLOYED;
|
|
@@ -257,6 +263,7 @@ exports.PluginStateVersionError = require_sdk_plugins_errors.PluginStateVersionE
|
|
|
257
263
|
exports.PoolService = require_sdk_pools_PoolService.PoolService;
|
|
258
264
|
exports.PoolSuite = require_sdk_market_pool_PoolSuite.PoolSuite;
|
|
259
265
|
exports.PoolV310Contract = require_sdk_market_pool_PoolV310Contract.PoolV310Contract;
|
|
266
|
+
exports.PositionsService = require_sdk_positions_PositionsService.PositionsService;
|
|
260
267
|
exports.PriceFeedRef = require_sdk_market_pricefeeds_PriceFeedRef.PriceFeedRef;
|
|
261
268
|
exports.PriceFeedRegister = require_sdk_market_pricefeeds_PriceFeedsRegister.PriceFeedRegister;
|
|
262
269
|
exports.PriceOracleV310Contract = require_sdk_market_oracle_PriceOracleV310Contract.PriceOracleV310Contract;
|
|
@@ -326,6 +333,7 @@ exports.createZapper = require_sdk_market_zapper_createZapper.createZapper;
|
|
|
326
333
|
exports.creditFacadeV310Abi = require_sdk_market_credit_CreditFacadeV310BaseContract.creditFacadeV310Abi;
|
|
327
334
|
exports.decodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.decodeDelayedIntent;
|
|
328
335
|
exports.detectNetwork = require_sdk_chain_detectNetwork.detectNetwork;
|
|
336
|
+
exports.dominantCollateral = require_sdk_accounts_dominantCollateral.dominantCollateral;
|
|
329
337
|
exports.encodeDelayedIntent = require_sdk_accounts_withdrawal_compressor_intent_codec.encodeDelayedIntent;
|
|
330
338
|
exports.estimateRawTxGas = require_sdk_utils_viem_sendRawTx.estimateRawTxGas;
|
|
331
339
|
exports.etherscanApiUrl = require_sdk_utils_etherscan.etherscanApiUrl;
|
|
@@ -357,6 +365,7 @@ exports.getRawPriceUpdates = require_sdk_market_pricefeeds_getRawPriceUpdates.ge
|
|
|
357
365
|
exports.getSimulateWithPriceUpdatesError = require_sdk_utils_viem_simulateWithPriceUpdates.getSimulateWithPriceUpdatesError;
|
|
358
366
|
exports.getWithdrawalCompressorAddress = require_sdk_accounts_withdrawal_compressor_addresses.getWithdrawalCompressorAddress;
|
|
359
367
|
exports.halfRAY = require_sdk_constants_math.halfRAY;
|
|
368
|
+
exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
|
|
360
369
|
exports.hexEq = require_sdk_utils_hex.hexEq;
|
|
361
370
|
exports.hydrateAddressProvider = require_sdk_core_createAddressProvider.hydrateAddressProvider;
|
|
362
371
|
exports.iCreditAccountAbi = require_sdk_accounts_withdrawal_compressor_AbstractWithdrawalCompressorContract.iCreditAccountAbi;
|
|
@@ -377,6 +386,7 @@ exports.maxLeverage = require_sdk_market_math.maxLeverage;
|
|
|
377
386
|
exports.numberWithCommas = require_sdk_utils_formatter.numberWithCommas;
|
|
378
387
|
exports.onchainSDKOptionsSchema = require_sdk_options.onchainSDKOptionsSchema;
|
|
379
388
|
exports.percentFmt = require_sdk_utils_formatter.percentFmt;
|
|
389
|
+
exports.positionLeverage = require_sdk_market_math.positionLeverage;
|
|
380
390
|
exports.primaryInstantOutput = require_sdk_accounts_intents_operations_claim_delayed_index.primaryInstantOutput;
|
|
381
391
|
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
382
392
|
exports.rayToNumber = require_sdk_utils_formatter.rayToNumber;
|
|
@@ -124,6 +124,12 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
124
124
|
return this.tokensMeta.mustGetToken(this.unwrappedUnderlying);
|
|
125
125
|
}
|
|
126
126
|
/**
|
|
127
|
+
* Display name of this market's pool, e.g. `"USDC Pool"`.
|
|
128
|
+
*/
|
|
129
|
+
get poolName() {
|
|
130
|
+
return `${this.underlyingToken.symbol} Pool`;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
127
133
|
* {@inheritDoc MarketConfiguratorContract.curator}
|
|
128
134
|
*/
|
|
129
135
|
get curator() {
|
|
@@ -213,7 +219,7 @@ var MarketSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
213
219
|
kind: "pool",
|
|
214
220
|
chainId: this.chainId,
|
|
215
221
|
pool: pool.address,
|
|
216
|
-
name:
|
|
222
|
+
name: this.poolName,
|
|
217
223
|
curator: this.curator,
|
|
218
224
|
underlyingToken: this.underlyingToken,
|
|
219
225
|
totalSupply: oracle.toAmount(pool.underlying, pool.totalAssets),
|
|
@@ -142,6 +142,15 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
142
142
|
return require_sdk_utils_bigint_math.BigIntMath.min(debtParams?.available ?? 115792089237316195423570985008687907853269984665640564039457584007913129639935n, pool.availableLiquidity, this.creditFacade.maxDebt);
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
|
+
* Display name of a leveraged position built on one collateral token, e.g.
|
|
146
|
+
* `"wstETH / WETH"`.
|
|
147
|
+
*
|
|
148
|
+
* @param collateral - Target collateral of the position.
|
|
149
|
+
*/
|
|
150
|
+
strategyName(collateral) {
|
|
151
|
+
return `${this.tokensMeta.symbol(collateral)} / ${this.market.underlyingToken.symbol}`;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
145
154
|
* Describes a leveraged position built on one collateral token as the shared
|
|
146
155
|
* read model does.
|
|
147
156
|
*
|
|
@@ -160,7 +169,7 @@ var CreditSuite = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
160
169
|
chainId: this.chainId,
|
|
161
170
|
creditManager: cm.address,
|
|
162
171
|
targetCollateral: this.tokensMeta.mustGetToken(collateral),
|
|
163
|
-
name:
|
|
172
|
+
name: this.strategyName(collateral),
|
|
164
173
|
curator: market.curator,
|
|
165
174
|
underlyingToken: market.underlyingToken,
|
|
166
175
|
totalBorrow: oracle.toAmount(pool.underlying, borrowed),
|
|
@@ -81,6 +81,41 @@ function maxLeverage(liquidationThreshold) {
|
|
|
81
81
|
return equity > 0 ? FULL / equity : Number.POSITIVE_INFINITY;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
+
* Converts a credit account's health factor from the 18-decimal fixed point the
|
|
85
|
+
* contracts store to basis points.
|
|
86
|
+
*
|
|
87
|
+
* An account with no debt return MAX_UINT256 from contract, here we return 0
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* healthFactorBps(1_250_000_000_000_000_000n) // 12500, i.e. 1.25
|
|
92
|
+
* ```
|
|
93
|
+
**/
|
|
94
|
+
function healthFactorBps(healthFactor) {
|
|
95
|
+
if (healthFactor === 115792089237316195423570985008687907853269984665640564039457584007913129639935n) return 0;
|
|
96
|
+
return Number(healthFactor * require_sdk_constants_math.PERCENTAGE_FACTOR / require_sdk_constants_math.WAD);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Leverage of an open position: `totalDebt / equity`, where equity is what is
|
|
100
|
+
* left of the position's value once its debt is repaid.
|
|
101
|
+
*
|
|
102
|
+
* Returns `0` for a position that carries no debt and for one that is
|
|
103
|
+
* underwater, where there is no equity to lever.
|
|
104
|
+
*
|
|
105
|
+
* @param totalDebt - Debt principal plus accrued interest and fees.
|
|
106
|
+
* @param totalValue - Total value of the position, in the same token.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* positionLeverage(800n, 1000n) // 4, i.e. 4x debt per unit of equity
|
|
111
|
+
* ```
|
|
112
|
+
**/
|
|
113
|
+
function positionLeverage(totalDebt, totalValue) {
|
|
114
|
+
const equity = totalValue - totalDebt;
|
|
115
|
+
if (equity <= 0n || totalDebt <= 0n) return 0;
|
|
116
|
+
return Number(totalDebt) / Number(equity);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
84
119
|
* Annual quota cost scaled to the debt a maximally leveraged position carries,
|
|
85
120
|
* in basis points. Every unit of own capital carries `maxLeverage - 1` units of
|
|
86
121
|
* debt, and the quota is paid on the whole quoted position.
|
|
@@ -98,7 +133,9 @@ function additionalBorrowApyBps(quotaRate, leverage) {
|
|
|
98
133
|
//#endregion
|
|
99
134
|
exports.additionalBorrowApyBps = additionalBorrowApyBps;
|
|
100
135
|
exports.borrowApyBps = borrowApyBps;
|
|
136
|
+
exports.healthFactorBps = healthFactorBps;
|
|
101
137
|
exports.maxLeverage = maxLeverage;
|
|
138
|
+
exports.positionLeverage = positionLeverage;
|
|
102
139
|
exports.rayToBps = rayToBps;
|
|
103
140
|
exports.usdToNumber = usdToNumber;
|
|
104
141
|
exports.utilizationBps = utilizationBps;
|
|
@@ -6,7 +6,9 @@ exports.MultichainOpportunitiesService = require_sdk_opportunities_MultichainOpp
|
|
|
6
6
|
exports.OpportunitiesService = require_sdk_opportunities_OpportunitiesService.OpportunitiesService;
|
|
7
7
|
exports.additionalBorrowApyBps = require_sdk_market_math.additionalBorrowApyBps;
|
|
8
8
|
exports.borrowApyBps = require_sdk_market_math.borrowApyBps;
|
|
9
|
+
exports.healthFactorBps = require_sdk_market_math.healthFactorBps;
|
|
9
10
|
exports.maxLeverage = require_sdk_market_math.maxLeverage;
|
|
11
|
+
exports.positionLeverage = require_sdk_market_math.positionLeverage;
|
|
10
12
|
exports.rayToBps = require_sdk_market_math.rayToBps;
|
|
11
13
|
exports.usdToNumber = require_sdk_market_math.usdToNumber;
|
|
12
14
|
exports.utilizationBps = require_sdk_market_math.utilizationBps;
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_abi_iERC20 = require("../../abi/iERC20.js");
|
|
3
3
|
const require_sdk_utils_AddressSet = require("../utils/AddressSet.js");
|
|
4
4
|
require("../constants/addresses.js");
|
|
5
|
+
const require_sdk_constants_math = require("../constants/math.js");
|
|
5
6
|
require("../constants/index.js");
|
|
6
7
|
const require_sdk_utils_hex = require("../utils/hex.js");
|
|
7
8
|
require("../utils/index.js");
|
|
@@ -9,6 +10,7 @@ const require_sdk_base_BaseContract = require("../base/BaseContract.js");
|
|
|
9
10
|
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
10
11
|
const require_sdk_base_token_types = require("../base/token-types.js");
|
|
11
12
|
require("../base/index.js");
|
|
13
|
+
const require_sdk_market_math = require("../market/math.js");
|
|
12
14
|
const require_sdk_market_zapper_IERC20ZapperContract = require("../market/zapper/IERC20ZapperContract.js");
|
|
13
15
|
const require_sdk_market_zapper_IETHZapperContract = require("../market/zapper/IETHZapperContract.js");
|
|
14
16
|
require("../market/index.js");
|
|
@@ -174,6 +176,27 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
174
176
|
return this.#withdrawalMetadata("classic", pool, tokenIn, tokenOut, true);
|
|
175
177
|
}
|
|
176
178
|
/**
|
|
179
|
+
* {@inheritDoc IPoolsService.listPositions}
|
|
180
|
+
*/
|
|
181
|
+
async listPositions(props) {
|
|
182
|
+
const { markets } = this.sdk.marketRegister;
|
|
183
|
+
if (markets.length === 0) return [];
|
|
184
|
+
const balances = await this.client.multicall({
|
|
185
|
+
contracts: markets.map((market) => ({
|
|
186
|
+
address: market.pool.pool.address,
|
|
187
|
+
abi: require_abi_iERC20.ierc20Abi,
|
|
188
|
+
functionName: "balanceOf",
|
|
189
|
+
args: [props.wallet]
|
|
190
|
+
})),
|
|
191
|
+
allowFailure: false,
|
|
192
|
+
batchSize: 0
|
|
193
|
+
});
|
|
194
|
+
return markets.flatMap((market, i) => {
|
|
195
|
+
const shares = balances[i] ?? 0n;
|
|
196
|
+
return shares > 0n ? [this.#poolPosition(market, shares)] : [];
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
177
200
|
* Returns non-migration zappers available for the pool.
|
|
178
201
|
*/
|
|
179
202
|
#getDepositZappers(poolAddr) {
|
|
@@ -290,6 +313,20 @@ var PoolService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
|
290
313
|
const market = this.sdk.marketRegister.findByPool(pool);
|
|
291
314
|
return this.sdk.tokensMeta.mustGet(market.underlying);
|
|
292
315
|
}
|
|
316
|
+
#poolPosition(market, shares) {
|
|
317
|
+
const { pool } = market.pool;
|
|
318
|
+
return {
|
|
319
|
+
kind: "pool",
|
|
320
|
+
name: market.poolName,
|
|
321
|
+
chainId: this.chainId,
|
|
322
|
+
pool: pool.address,
|
|
323
|
+
netValue: {
|
|
324
|
+
token: this.sdk.tokensMeta.mustGetToken(market.unwrappedUnderlying),
|
|
325
|
+
...market.priceOracle.toAmount(market.underlying, shares * pool.dieselRate / require_sdk_constants_math.RAY)
|
|
326
|
+
},
|
|
327
|
+
apy: { organicApy: require_sdk_market_math.rayToBps(pool.supplyRate) }
|
|
328
|
+
};
|
|
329
|
+
}
|
|
293
330
|
};
|
|
294
331
|
//#endregion
|
|
295
332
|
exports.PoolService = PoolService;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_chain_chains = require("../chain/chains.js");
|
|
3
|
+
const require_sdk_base_MultichainConstruct = require("../base/MultichainConstruct.js");
|
|
4
|
+
require("../base/index.js");
|
|
5
|
+
//#region src/sdk/positions/MultichainPositionsService.ts
|
|
6
|
+
/**
|
|
7
|
+
* Cross-chain counterpart of {@link PositionsService}.
|
|
8
|
+
*
|
|
9
|
+
* Fans out over every chain configured in {@link MultichainSDK}. A chain that
|
|
10
|
+
* fails is logged and skipped so one dead RPC does not hide the positions a
|
|
11
|
+
* wallet holds elsewhere; its failure is reported in
|
|
12
|
+
* {@link MultichainResult.meta}.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam Plugins - Map of attached plugin types.
|
|
15
|
+
**/
|
|
16
|
+
var MultichainPositionsService = class extends require_sdk_base_MultichainConstruct.MultichainConstruct {
|
|
17
|
+
/**
|
|
18
|
+
* Positions of a wallet on all queried chains, see
|
|
19
|
+
* {@link PositionsService.list}.
|
|
20
|
+
*
|
|
21
|
+
* A filter that names chains narrows the fan-out itself, so chains whose rows
|
|
22
|
+
* would be discarded are never queried and never appear in the meta.
|
|
23
|
+
**/
|
|
24
|
+
async list(props) {
|
|
25
|
+
return this.queryChains({
|
|
26
|
+
networks: this.#networksOf(props.filter),
|
|
27
|
+
label: "list positions",
|
|
28
|
+
run: (sdk) => sdk.positions.list(props)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Chains named by the filter, or `undefined` to query all of them. Chain ids
|
|
33
|
+
* the SDK does not support are dropped here rather than reported as failures:
|
|
34
|
+
* a filter naming them is a narrowing, not a request.
|
|
35
|
+
**/
|
|
36
|
+
#networksOf(filter) {
|
|
37
|
+
if (!filter?.chainIds) return;
|
|
38
|
+
const networks = [];
|
|
39
|
+
for (const chainId of filter.chainIds) try {
|
|
40
|
+
networks.push(require_sdk_chain_chains.getNetworkType(chainId));
|
|
41
|
+
} catch {
|
|
42
|
+
this.sdk.logger?.debug(`ignoring unsupported chain ${chainId} in positions filter`);
|
|
43
|
+
}
|
|
44
|
+
return networks;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
exports.MultichainPositionsService = MultichainPositionsService;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_base_SDKConstruct = require("../base/SDKConstruct.js");
|
|
3
|
+
require("../base/index.js");
|
|
4
|
+
const require_model_positions = require("../../model/positions.js");
|
|
5
|
+
require("../../model/index.js");
|
|
6
|
+
//#region src/sdk/positions/PositionsService.ts
|
|
7
|
+
/**
|
|
8
|
+
* The `positions` read model of one chain: everything a wallet holds in the
|
|
9
|
+
* protocol — pool shares, open credit accounts, and delayed withdrawals it
|
|
10
|
+
* took over by liquidating.
|
|
11
|
+
**/
|
|
12
|
+
var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct {
|
|
13
|
+
/**
|
|
14
|
+
* Every position of a wallet on this chain, optionally narrowed by
|
|
15
|
+
* {@link PositionFilter} (see {@link matchesPositionFilter} for what each
|
|
16
|
+
* criterion selects). Reads live chain state, so rows reflect the moment of
|
|
17
|
+
* the call rather than the SDK's loaded snapshot.
|
|
18
|
+
**/
|
|
19
|
+
async list(props) {
|
|
20
|
+
const { wallet, filter } = props;
|
|
21
|
+
if (filter?.chainIds && !filter.chainIds.includes(this.chainId)) return [];
|
|
22
|
+
const wanted = (kind) => !filter?.kind || filter.kind === kind;
|
|
23
|
+
const [pool, strategy, liquidation] = await Promise.all([
|
|
24
|
+
wanted("pool") ? this.sdk.pools.listPositions({ wallet }) : Promise.resolve([]),
|
|
25
|
+
wanted("strategy") ? this.sdk.accounts.listPositions({
|
|
26
|
+
owner: wallet,
|
|
27
|
+
includeZeroDebt: filter?.isZeroDebt !== false
|
|
28
|
+
}) : Promise.resolve([]),
|
|
29
|
+
wanted("liquidation") ? this.sdk.liquidations.getLiquidationPositions({ liquidator: wallet }) : Promise.resolve([])
|
|
30
|
+
]);
|
|
31
|
+
return [
|
|
32
|
+
...pool,
|
|
33
|
+
...strategy,
|
|
34
|
+
...liquidation
|
|
35
|
+
].filter((row) => require_model_positions.matchesPositionFilter(row, filter));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.PositionsService = PositionsService;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sdk_positions_MultichainPositionsService = require("./MultichainPositionsService.js");
|
|
3
|
+
const require_sdk_positions_PositionsService = require("./PositionsService.js");
|
|
4
|
+
require("./types.js");
|
|
5
|
+
exports.MultichainPositionsService = require_sdk_positions_MultichainPositionsService.MultichainPositionsService;
|
|
6
|
+
exports.PositionsService = require_sdk_positions_PositionsService.PositionsService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|