@gearbox-protocol/sdk 15.1.0-next.21 → 15.1.0-next.22
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/sdk/market/oracle/PriceOracleBaseContract.js +11 -0
- package/dist/cjs/sdk/positions/PositionsService.js +22 -11
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.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 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- 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/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/sdk/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +11 -0
- 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 +22 -11
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +4 -0
- package/dist/types/sdk/market/oracle/types.d.ts +9 -0
- package/package.json +1 -1
|
@@ -138,6 +138,17 @@ var PriceOracleBaseContract = class extends require_sdk_base_BaseContract.BaseCo
|
|
|
138
138
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(token)) / price;
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
+
* {@inheritDoc IPriceOracleContract.safeConvert}
|
|
142
|
+
**/
|
|
143
|
+
safeConvert(from, to, amount) {
|
|
144
|
+
try {
|
|
145
|
+
return this.convert(from, to, amount);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
this.logger?.debug(`cannot convert ${this.labelAddress(from)} to ${this.labelAddress(to)}: ${e}`);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
141
152
|
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
142
153
|
**/
|
|
143
154
|
safeConvertToUSD(token, amount) {
|
|
@@ -154,6 +154,24 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
154
154
|
const borrowRate = this.borrowRate(snapshot);
|
|
155
155
|
const timeToLiquidation = this.timeToLiquidation(snapshot);
|
|
156
156
|
const liquidationPrice = this.liquidationPrice(snapshot);
|
|
157
|
+
const zeroDebt = ca.debt === 0n;
|
|
158
|
+
const collaterals = [];
|
|
159
|
+
let totalValue = zeroDebt ? 0n : ca.totalValue;
|
|
160
|
+
let totalValueUSD = zeroDebt ? 0n : ca.totalValueUSD;
|
|
161
|
+
for (const t of ca.tokens) {
|
|
162
|
+
if (t.balance <= 10n) continue;
|
|
163
|
+
collaterals.push({
|
|
164
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
165
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
166
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
167
|
+
});
|
|
168
|
+
if (zeroDebt) {
|
|
169
|
+
const value = priceOracle.safeConvert(t.token, market.underlying, t.balance) || 0n;
|
|
170
|
+
totalValue += value;
|
|
171
|
+
const usd = priceOracle.safeConvertToUSD(t.token, t.balance) || 0n;
|
|
172
|
+
totalValueUSD += usd;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
157
175
|
return {
|
|
158
176
|
kind: "strategy",
|
|
159
177
|
chainId: this.sdk.chainId,
|
|
@@ -161,7 +179,7 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
161
179
|
creditAccount: ca.creditAccount,
|
|
162
180
|
name: target ? require_sdk_market_strategyName.strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
|
|
163
181
|
targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
|
|
164
|
-
leverage: require_sdk_market_math.calcPositionLeverage(
|
|
182
|
+
leverage: require_sdk_market_math.calcPositionLeverage(totalValue, totalDebtValue),
|
|
165
183
|
borrowApy: require_sdk_market_math.calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
166
184
|
totalDebt: {
|
|
167
185
|
token,
|
|
@@ -170,21 +188,14 @@ var PositionsService = class extends require_sdk_base_SDKConstruct.SDKConstruct
|
|
|
170
188
|
},
|
|
171
189
|
totalValue: {
|
|
172
190
|
token,
|
|
173
|
-
value:
|
|
174
|
-
valueUsd: require_sdk_market_math.usdToNumber(
|
|
191
|
+
value: totalValue,
|
|
192
|
+
valueUsd: require_sdk_market_math.usdToNumber(totalValueUSD)
|
|
175
193
|
},
|
|
176
194
|
healthFactor: require_sdk_market_math.healthFactorBps(ca.healthFactor),
|
|
177
195
|
borrowRate,
|
|
178
196
|
timeToLiquidation,
|
|
179
197
|
liquidationPrice,
|
|
180
|
-
collaterals
|
|
181
|
-
if (t.balance <= 10n) return [];
|
|
182
|
-
return [{
|
|
183
|
-
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
184
|
-
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
185
|
-
withdrawals: withdrawals.get(t.token) ?? []
|
|
186
|
-
}];
|
|
187
|
-
})
|
|
198
|
+
collaterals
|
|
188
199
|
};
|
|
189
200
|
}
|
|
190
201
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../sdk/utils/AddressMap.js";
|
|
4
3
|
import { AddressSet } from "../sdk/utils/AddressSet.js";
|
|
5
4
|
import { AssetsMap } from "../sdk/utils/AssetsMap.js";
|
|
6
5
|
import { childLogger } from "../sdk/utils/childLogger.js";
|
|
6
|
+
import { ierc20Abi } from "../abi/iERC20.js";
|
|
7
7
|
import "../sdk/constants/addresses.js";
|
|
8
8
|
import { MAX_UINT256, PERCENTAGE_FACTOR } from "../sdk/constants/math.js";
|
|
9
9
|
import { SDKConstruct } from "../sdk/base/SDKConstruct.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { getNetworkType } from "../sdk/chain/chains.js";
|
|
3
2
|
import { getWithdrawalCompressorAddress } from "../sdk/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../sdk/index.js";
|
|
5
5
|
import { iMidasDataFeedAbi, iMidasRedemptionVaultAbi, midasGatewayAbi, midasRedeemerAbi, midasRedemptionVaultPhantomTokenAbi, securitizeRedeemerAbi, securitizeRedemptionGatewayAbi, securitizeRedemptionPhantomTokenAbi } from "./withdrawalAbi.js";
|
|
6
6
|
import { erc20Abi, hexToString, parseAbi, parseEther } from "viem";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
3
3
|
import { asPreviewSimulationError } from "./errors.js";
|
|
4
4
|
//#region src/preview/simulate/simulatePoolOperation.ts
|
|
5
5
|
function previewRead(operation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../sdk/utils/AddressMap.js";
|
|
3
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
4
4
|
import "../../sdk/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
6
6
|
import { getAddress, isAddressEqual, parseEventLogs } from "viem";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
-
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
3
1
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
4
2
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
5
3
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -10,6 +8,8 @@ import "../base/index.js";
|
|
|
10
8
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
11
9
|
import "./bots/index.js";
|
|
12
10
|
import { rewardsCompressorAbi } from "../../abi/compressors/rewardsCompressor.js";
|
|
11
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
12
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
13
13
|
import { expectedBalanceDeltas } from "../market/credit/expectedBalanceDeltas.js";
|
|
14
14
|
import "../market/index.js";
|
|
15
15
|
import { CreditAccountCompressor } from "./credit-account-compressor/CreditAccountCompressor.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
2
1
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
3
2
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
4
3
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -20,6 +19,7 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
20
19
|
import "../../market/rwa/securitize/index.js";
|
|
21
20
|
import "../../market/index.js";
|
|
22
21
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
//#region src/sdk/accounts/liquidations/LiquidationsService.ts
|
|
24
24
|
/**
|
|
25
25
|
* Service for discovering liquidatable credit accounts and previewing manual
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
4
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
5
5
|
import { InvalidDelayedIntentError } from "./errors.js";
|
|
6
6
|
//#region src/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
7
7
|
const abi = iRedemptionLoggerV310Abi;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
3
3
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
3
3
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
3
2
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import { toWithdrawalStatus } from "./types.js";
|
|
5
5
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
|
|
6
6
|
const abi = iWithdrawalCompressorV313Abi;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
2
|
-
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
3
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
4
1
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
5
2
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
6
3
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
7
4
|
import { getAssetType } from "../chain/chains.js";
|
|
8
5
|
import { formatBN } from "../utils/formatter.js";
|
|
9
6
|
import "../utils/index.js";
|
|
7
|
+
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
8
|
+
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
9
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
10
10
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
11
11
|
//#region src/sdk/base/TokensMeta.ts
|
|
12
12
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
2
1
|
import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
|
|
3
2
|
import { isV310 } from "../constants/versions.js";
|
|
4
3
|
import "../constants/index.js";
|
|
5
4
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/sdk/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = { Mainnet: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
2
1
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
2
|
+
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
3
3
|
//#region src/sdk/market/adapters/contracts/AccountMigratorAdapterContract.ts
|
|
4
4
|
const abi = accountMigratorAbi;
|
|
5
5
|
const protocolAbi = accountMigratorAbi;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
2
1
|
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
3
2
|
import "../../../base/index.js";
|
|
3
|
+
import { ierc4626AdapterAbi } from "../../../../abi/ierc4626Adapter.js";
|
|
4
4
|
import { iERC4626Abi } from "../abi/targetContractAbi.js";
|
|
5
5
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
6
6
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
@@ -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,
|
|
@@ -137,6 +137,17 @@ var PriceOracleBaseContract = class extends BaseContract {
|
|
|
137
137
|
return amount * 10n ** BigInt(this.tokensMeta.decimals(token)) / price;
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
|
+
* {@inheritDoc IPriceOracleContract.safeConvert}
|
|
141
|
+
**/
|
|
142
|
+
safeConvert(from, to, amount) {
|
|
143
|
+
try {
|
|
144
|
+
return this.convert(from, to, amount);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
this.logger?.debug(`cannot convert ${this.labelAddress(from)} to ${this.labelAddress(to)}: ${e}`);
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
140
151
|
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
141
152
|
**/
|
|
142
153
|
safeConvertToUSD(token, amount) {
|
|
@@ -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 { PERCENTAGE_FACTOR, RAY } from "../constants/math.js";
|
|
5
5
|
import "../constants/index.js";
|
|
@@ -153,6 +153,24 @@ var PositionsService = class extends SDKConstruct {
|
|
|
153
153
|
const borrowRate = this.borrowRate(snapshot);
|
|
154
154
|
const timeToLiquidation = this.timeToLiquidation(snapshot);
|
|
155
155
|
const liquidationPrice = this.liquidationPrice(snapshot);
|
|
156
|
+
const zeroDebt = ca.debt === 0n;
|
|
157
|
+
const collaterals = [];
|
|
158
|
+
let totalValue = zeroDebt ? 0n : ca.totalValue;
|
|
159
|
+
let totalValueUSD = zeroDebt ? 0n : ca.totalValueUSD;
|
|
160
|
+
for (const t of ca.tokens) {
|
|
161
|
+
if (t.balance <= 10n) continue;
|
|
162
|
+
collaterals.push({
|
|
163
|
+
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
164
|
+
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
165
|
+
withdrawals: withdrawals.get(t.token) ?? []
|
|
166
|
+
});
|
|
167
|
+
if (zeroDebt) {
|
|
168
|
+
const value = priceOracle.safeConvert(t.token, market.underlying, t.balance) || 0n;
|
|
169
|
+
totalValue += value;
|
|
170
|
+
const usd = priceOracle.safeConvertToUSD(t.token, t.balance) || 0n;
|
|
171
|
+
totalValueUSD += usd;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
156
174
|
return {
|
|
157
175
|
kind: "strategy",
|
|
158
176
|
chainId: this.sdk.chainId,
|
|
@@ -160,7 +178,7 @@ var PositionsService = class extends SDKConstruct {
|
|
|
160
178
|
creditAccount: ca.creditAccount,
|
|
161
179
|
name: target ? strategyName(this.sdk.tokensMeta.mustGetToken(target), token, this.sdk.chainId) : token.symbol,
|
|
162
180
|
targetCollateral: target ? this.sdk.tokensMeta.mustGetToken(target) : null,
|
|
163
|
-
leverage: calcPositionLeverage(
|
|
181
|
+
leverage: calcPositionLeverage(totalValue, totalDebtValue),
|
|
164
182
|
borrowApy: calcBorrowApy(pool.baseInterestRate, suite.creditManager.feeInterest),
|
|
165
183
|
totalDebt: {
|
|
166
184
|
token,
|
|
@@ -169,21 +187,14 @@ var PositionsService = class extends SDKConstruct {
|
|
|
169
187
|
},
|
|
170
188
|
totalValue: {
|
|
171
189
|
token,
|
|
172
|
-
value:
|
|
173
|
-
valueUsd: usdToNumber(
|
|
190
|
+
value: totalValue,
|
|
191
|
+
valueUsd: usdToNumber(totalValueUSD)
|
|
174
192
|
},
|
|
175
193
|
healthFactor: healthFactorBps(ca.healthFactor),
|
|
176
194
|
borrowRate,
|
|
177
195
|
timeToLiquidation,
|
|
178
196
|
liquidationPrice,
|
|
179
|
-
collaterals
|
|
180
|
-
if (t.balance <= 10n) return [];
|
|
181
|
-
return [{
|
|
182
|
-
collateral: priceOracle.toTokenAmount(t.token, t.balance),
|
|
183
|
-
quota: priceOracle.toTokenAmount(market.underlying, t.quota),
|
|
184
|
-
withdrawals: withdrawals.get(t.token) ?? []
|
|
185
|
-
}];
|
|
186
|
-
})
|
|
197
|
+
collaterals
|
|
187
198
|
};
|
|
188
199
|
}
|
|
189
200
|
/**
|
|
@@ -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";
|
|
@@ -92,6 +92,10 @@ declare abstract class PriceOracleBaseContract<abi extends Abi | readonly unknow
|
|
|
92
92
|
* {@inheritDoc IPriceOracleContract.convertFromUSD}
|
|
93
93
|
**/
|
|
94
94
|
convertFromUSD(to: Address, amount: bigint, reserve?: boolean): bigint;
|
|
95
|
+
/**
|
|
96
|
+
* {@inheritDoc IPriceOracleContract.safeConvert}
|
|
97
|
+
**/
|
|
98
|
+
safeConvert(from: Address, to: Address, amount: bigint): bigint | null;
|
|
95
99
|
/**
|
|
96
100
|
* {@inheritDoc IPriceOracleContract.safeConvertToUSD}
|
|
97
101
|
**/
|
|
@@ -131,6 +131,15 @@ interface IPriceOracleContract extends IBaseContract {
|
|
|
131
131
|
* @param reserve - Use reserve feeds instead of main.
|
|
132
132
|
**/
|
|
133
133
|
convert: (from: Address, to: Address, amount: bigint, reserve?: boolean) => bigint;
|
|
134
|
+
/**
|
|
135
|
+
* Like {@link convert}, but returns `null` instead of throwing when either
|
|
136
|
+
* token cannot be priced (missing or unsuccessful feed).
|
|
137
|
+
*
|
|
138
|
+
* @param from - Source token address.
|
|
139
|
+
* @param to - Destination token address.
|
|
140
|
+
* @param amount - Amount in source-token decimals.
|
|
141
|
+
**/
|
|
142
|
+
safeConvert: (from: Address, to: Address, amount: bigint) => bigint | null;
|
|
134
143
|
/**
|
|
135
144
|
* Converts a token amount to its USD value using latest known prices.
|
|
136
145
|
*
|