@gearbox-protocol/sdk 17.0.0-next.1 → 17.0.0-next.3
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/onchain/validation/bundles/checkCreditOperation.js +2 -1
- package/dist/cjs/onchain/validation/checkSimulation.js +11 -4
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +6 -2
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/history/trace/extractTransfers.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/AccountMigratorAdapterContract.js +1 -1
- package/dist/esm/onchain/market/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/onchain/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/onchain/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/onchain/market/rwa/createDegenNFT.js +1 -1
- package/dist/esm/onchain/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/onchain/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/onchain/preview/preview/previewPoolPositionOperation.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +2 -1
- package/dist/esm/onchain/validation/checkSimulation.js +11 -4
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +6 -2
- package/dist/types/model/errors/operation-errors.d.ts +5 -0
- package/dist/types/onchain/validation/checkSimulation.d.ts +6 -3
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +4 -0
- package/package.json +1 -1
|
@@ -33,7 +33,8 @@ async function checkCreditOperation(args) {
|
|
|
33
33
|
minDebt: suite.creditFacade.minDebt,
|
|
34
34
|
maxDebt: suite.creditFacade.maxDebt,
|
|
35
35
|
underlying,
|
|
36
|
-
allowZero: !isOpening
|
|
36
|
+
allowZero: !isOpening,
|
|
37
|
+
ceiling: suite.maxBorrowAmount()
|
|
37
38
|
}),
|
|
38
39
|
...require_onchain_validation_bundles_checkDraw.checkDraw(suite, preview, underlying),
|
|
39
40
|
...require_onchain_validation_bundles_checkObtained.checkObtained(suite, preview),
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_onchain_validation_helpers_token = require("./helpers/token.js");
|
|
3
3
|
require("./helpers/index.js");
|
|
4
4
|
const require_onchain_validation_checks_checkDebtLimits = require("./checks/checkDebtLimits.js");
|
|
5
|
+
const require_onchain_validation_checks_checkQuotaCount = require("./checks/checkQuotaCount.js");
|
|
5
6
|
require("./checks/index.js");
|
|
6
7
|
const require_onchain_validation_bundles_checkAccountQuotas = require("./bundles/checkAccountQuotas.js");
|
|
7
8
|
const require_onchain_validation_bundles_checkHealthFactors = require("./bundles/checkHealthFactors.js");
|
|
@@ -27,8 +28,10 @@ const require_onchain_validation_bundles_checkMarket = require("./bundles/checkM
|
|
|
27
28
|
* touched. The engine performed all three during the walk, so a simulation that
|
|
28
29
|
* came back `ok` has already passed them.
|
|
29
30
|
*
|
|
30
|
-
* A credit account only: a pool operation has no account
|
|
31
|
-
* three things its own state decides are read by `prepare`
|
|
31
|
+
* A credit account only, opened or adjusted: a pool operation has no account
|
|
32
|
+
* to weigh, and the three things its own state decides are read by `prepare`
|
|
33
|
+
* before it answers. An opening names its quotas `averageQuota` — the branch
|
|
34
|
+
* the planner already weighed it as.
|
|
32
35
|
*/
|
|
33
36
|
function checkSimulation(sdk, input, options = {}) {
|
|
34
37
|
const { state } = input;
|
|
@@ -40,9 +43,13 @@ function checkSimulation(sdk, input, options = {}) {
|
|
|
40
43
|
minDebt: suite.creditFacade.minDebt,
|
|
41
44
|
maxDebt: suite.creditFacade.maxDebt,
|
|
42
45
|
underlying: require_onchain_validation_helpers_token.toToken(sdk, suite.market.pool.underlying),
|
|
43
|
-
allowZero: true
|
|
46
|
+
allowZero: true,
|
|
47
|
+
ceiling: suite.maxBorrowAmount()
|
|
44
48
|
}),
|
|
45
|
-
...
|
|
49
|
+
..."averageQuota" in state ? require_onchain_validation_checks_checkQuotaCount.checkQuotaCount({
|
|
50
|
+
count: state.averageQuota.filter((q) => q.balance > 0n).length,
|
|
51
|
+
max: suite.creditManager.maxEnabledTokens
|
|
52
|
+
}) : require_onchain_validation_bundles_checkAccountQuotas.checkAccountQuotas(suite, state),
|
|
46
53
|
...require_onchain_validation_bundles_checkHealthFactors.checkHealthFactors(state, options)
|
|
47
54
|
];
|
|
48
55
|
}
|
|
@@ -6,12 +6,16 @@ require("../helpers/index.js");
|
|
|
6
6
|
//#region src/onchain/validation/checks/checkDebtLimits.ts
|
|
7
7
|
/** A debt the facade would revert on. */
|
|
8
8
|
function checkDebtLimits(args) {
|
|
9
|
-
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
9
|
+
const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
|
|
10
10
|
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
|
|
11
11
|
return [require_model_errors_operation_errors.debtOutOfRange({
|
|
12
12
|
requested: require_onchain_validation_helpers_amount.amountOf(underlying, debt),
|
|
13
13
|
minDebt: require_onchain_validation_helpers_amount.amountOf(underlying, minDebt),
|
|
14
|
-
maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt)
|
|
14
|
+
maxDebt: require_onchain_validation_helpers_amount.amountOf(underlying, maxDebt),
|
|
15
|
+
ceiling: ceiling && {
|
|
16
|
+
amount: require_onchain_validation_helpers_amount.amountOf(underlying, ceiling.value),
|
|
17
|
+
limit: ceiling.limit
|
|
18
|
+
}
|
|
15
19
|
})];
|
|
16
20
|
}
|
|
17
21
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
|
+
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
3
3
|
import { AddressMap } from "../onchain/utils/AddressMap.js";
|
|
4
4
|
import { AddressSet } from "../onchain/utils/AddressSet.js";
|
|
5
5
|
import { AssetsMap } from "../onchain/utils/AssetsMap.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
2
3
|
import { getWithdrawalCompressorAddress } from "../onchain/accounts/withdrawal-compressor/addresses.js";
|
|
3
|
-
import { iWithdrawalCompressorV313Abi } from "../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import "../onchain/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 { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
|
+
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
3
3
|
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { iBaseRewardPoolAbi } from "../../abi/iBaseRewardPool.js";
|
|
2
|
+
import { ierc4626AdapterAbi } from "../../abi/ierc4626Adapter.js";
|
|
1
3
|
import { AP_REWARDS_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
4
|
import { ADDRESS_0X0 } from "../constants/addresses.js";
|
|
3
5
|
import { MAX_UINT256 } from "../constants/math.js";
|
|
@@ -8,8 +10,6 @@ import "../base/index.js";
|
|
|
8
10
|
import { AccountBotsService } from "./bots/AccountBotsService.js";
|
|
9
11
|
import "./bots/index.js";
|
|
10
12
|
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,3 +1,4 @@
|
|
|
1
|
+
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
1
2
|
import { AddressSet } from "../../utils/AddressSet.js";
|
|
2
3
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
4
|
import { ADDRESS_0X0 } from "../../constants/addresses.js";
|
|
@@ -19,7 +20,6 @@ import { SecuritizeLiquidatorContract } from "../../market/rwa/securitize/Securi
|
|
|
19
20
|
import "../../market/rwa/securitize/index.js";
|
|
20
21
|
import "../../market/index.js";
|
|
21
22
|
import { LIQUIDATION_APPROVAL_BUFFER, LIQUIDATION_COMPRESSOR_V313_ADDRESS } from "./constants.js";
|
|
22
|
-
import { iLiquidationCompressorV313Abi } from "../../../abi/ILiquidationCompressorV313.js";
|
|
23
23
|
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
24
24
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
25
25
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
1
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
3
|
import "../../base/index.js";
|
|
3
4
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
4
5
|
import "../../../model/index.js";
|
|
5
6
|
import { decodeDelayedIntent } from "./intent-codec.js";
|
|
6
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
7
7
|
//#region src/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.ts
|
|
8
8
|
const abi = iRedemptionLoggerV310Abi;
|
|
9
9
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV310Abi;
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
1
|
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
|
+
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
3
|
//#region src/onchain/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
1
2
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
2
3
|
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/onchain/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";
|
|
1
4
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
2
5
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
3
6
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
4
7
|
import { getAssetType } from "../chain/chains.js";
|
|
5
8
|
import { formatBN } from "../utils/formatter.js";
|
|
6
9
|
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 { SdkRWADataNotLoadedError } from "../core/errors.js";
|
|
11
11
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
12
12
|
//#region src/onchain/base/TokensMeta.ts
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
1
2
|
import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
|
|
2
3
|
import { isV310 } from "../constants/versions.js";
|
|
3
4
|
import "../constants/index.js";
|
|
4
5
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/onchain/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = { Mainnet: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
2
1
|
import { accountMigratorAbi } from "../../../../abi/AccountMigrator.js";
|
|
2
|
+
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
3
3
|
//#region src/onchain/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";
|
|
1
2
|
import { MissingSerializedParamsError } from "../../../base/errors.js";
|
|
2
3
|
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";
|
|
1
2
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
2
3
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
4
|
import "../../base/index.js";
|
|
4
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
5
|
//#region src/onchain/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
1
2
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
3
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
3
4
|
import { RAY } from "../../constants/math.js";
|
|
@@ -7,7 +8,6 @@ import "../../utils/index.js";
|
|
|
7
8
|
import { SdkRWADataNotLoadedError } from "../../core/errors.js";
|
|
8
9
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
9
10
|
import "../../base/index.js";
|
|
10
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
11
11
|
//#region src/onchain/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
13
13
|
var PoolV310Contract = class extends BaseContract {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
1
2
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
2
3
|
import "../../utils/index.js";
|
|
3
|
-
import { iVersionAbi } from "../../../abi/iVersion.js";
|
|
4
4
|
import { iMidasDegenNFTAbi } from "../../../abi/rwa/iMidasDegenNFT.js";
|
|
5
5
|
import { DEGEN_NFT_MIDAS } from "./midas/constants.js";
|
|
6
6
|
import { MidasDegenNFT } from "./midas/MidasDegenNFT.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ZapperContract } from "./ZapperContract.js";
|
|
2
1
|
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
|
+
import { ZapperContract } from "./ZapperContract.js";
|
|
3
3
|
//#region src/onchain/market/zapper/IETHZapperContract.ts
|
|
4
4
|
const abi = iethZapperAbi;
|
|
5
5
|
var IETHZapperContract = class extends ZapperContract {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
1
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
2
3
|
import "../../base/index.js";
|
|
3
4
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
4
5
|
import "../../../model/index.js";
|
|
5
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
6
6
|
//#region src/onchain/market/zapper/ZapperContract.ts
|
|
7
7
|
/**
|
|
8
8
|
* Base contract for every Gearbox zapper. Specialized zappers (e.g.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
1
|
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
3
|
+
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
4
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
4
5
|
import "../../../model/index.js";
|
|
5
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
6
6
|
//#region src/onchain/preview/preview/previewPoolPositionOperation.ts
|
|
7
7
|
function previewRead(operation) {
|
|
8
8
|
switch (operation.operation) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { generateCastTraceCall } from "./cast.js";
|
|
3
2
|
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
|
+
import { generateCastTraceCall } from "./cast.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";
|
|
@@ -32,7 +32,8 @@ async function checkCreditOperation(args) {
|
|
|
32
32
|
minDebt: suite.creditFacade.minDebt,
|
|
33
33
|
maxDebt: suite.creditFacade.maxDebt,
|
|
34
34
|
underlying,
|
|
35
|
-
allowZero: !isOpening
|
|
35
|
+
allowZero: !isOpening,
|
|
36
|
+
ceiling: suite.maxBorrowAmount()
|
|
36
37
|
}),
|
|
37
38
|
...checkDraw(suite, preview, underlying),
|
|
38
39
|
...checkObtained(suite, preview),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { toToken } from "./helpers/token.js";
|
|
2
2
|
import "./helpers/index.js";
|
|
3
3
|
import { checkDebtLimits } from "./checks/checkDebtLimits.js";
|
|
4
|
+
import { checkQuotaCount } from "./checks/checkQuotaCount.js";
|
|
4
5
|
import "./checks/index.js";
|
|
5
6
|
import { checkAccountQuotas } from "./bundles/checkAccountQuotas.js";
|
|
6
7
|
import { checkHealthFactors } from "./bundles/checkHealthFactors.js";
|
|
@@ -26,8 +27,10 @@ import { checkMarket } from "./bundles/checkMarket.js";
|
|
|
26
27
|
* touched. The engine performed all three during the walk, so a simulation that
|
|
27
28
|
* came back `ok` has already passed them.
|
|
28
29
|
*
|
|
29
|
-
* A credit account only: a pool operation has no account
|
|
30
|
-
* three things its own state decides are read by `prepare`
|
|
30
|
+
* A credit account only, opened or adjusted: a pool operation has no account
|
|
31
|
+
* to weigh, and the three things its own state decides are read by `prepare`
|
|
32
|
+
* before it answers. An opening names its quotas `averageQuota` — the branch
|
|
33
|
+
* the planner already weighed it as.
|
|
31
34
|
*/
|
|
32
35
|
function checkSimulation(sdk, input, options = {}) {
|
|
33
36
|
const { state } = input;
|
|
@@ -39,9 +42,13 @@ function checkSimulation(sdk, input, options = {}) {
|
|
|
39
42
|
minDebt: suite.creditFacade.minDebt,
|
|
40
43
|
maxDebt: suite.creditFacade.maxDebt,
|
|
41
44
|
underlying: toToken(sdk, suite.market.pool.underlying),
|
|
42
|
-
allowZero: true
|
|
45
|
+
allowZero: true,
|
|
46
|
+
ceiling: suite.maxBorrowAmount()
|
|
43
47
|
}),
|
|
44
|
-
...
|
|
48
|
+
..."averageQuota" in state ? checkQuotaCount({
|
|
49
|
+
count: state.averageQuota.filter((q) => q.balance > 0n).length,
|
|
50
|
+
max: suite.creditManager.maxEnabledTokens
|
|
51
|
+
}) : checkAccountQuotas(suite, state),
|
|
45
52
|
...checkHealthFactors(state, options)
|
|
46
53
|
];
|
|
47
54
|
}
|
|
@@ -5,12 +5,16 @@ import "../helpers/index.js";
|
|
|
5
5
|
//#region src/onchain/validation/checks/checkDebtLimits.ts
|
|
6
6
|
/** A debt the facade would revert on. */
|
|
7
7
|
function checkDebtLimits(args) {
|
|
8
|
-
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
8
|
+
const { debt, minDebt, maxDebt, underlying, allowZero, ceiling } = args;
|
|
9
9
|
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return [];
|
|
10
10
|
return [debtOutOfRange({
|
|
11
11
|
requested: amountOf(underlying, debt),
|
|
12
12
|
minDebt: amountOf(underlying, minDebt),
|
|
13
|
-
maxDebt: amountOf(underlying, maxDebt)
|
|
13
|
+
maxDebt: amountOf(underlying, maxDebt),
|
|
14
|
+
ceiling: ceiling && {
|
|
15
|
+
amount: amountOf(underlying, ceiling.value),
|
|
16
|
+
limit: ceiling.limit
|
|
17
|
+
}
|
|
14
18
|
})];
|
|
15
19
|
}
|
|
16
20
|
//#endregion
|
|
@@ -82,6 +82,11 @@ interface DebtOutOfRangeError extends IGearboxError {
|
|
|
82
82
|
requested: TokenAmount;
|
|
83
83
|
minDebt: TokenAmount;
|
|
84
84
|
maxDebt: TokenAmount;
|
|
85
|
+
/** What the market will really lend; absent where the raiser only throws. */
|
|
86
|
+
ceiling?: {
|
|
87
|
+
amount: TokenAmount;
|
|
88
|
+
limit: BorrowLimitCause;
|
|
89
|
+
};
|
|
85
90
|
}
|
|
86
91
|
/** {@inheritDoc DebtOutOfRangeError} */
|
|
87
92
|
declare function debtOutOfRange(args: Omit<DebtOutOfRangeError, "code" | "message">): DebtOutOfRangeError;
|
|
@@ -3,13 +3,14 @@ import { DebtOutOfRangeError, InsufficientCollateralError, QuotaCountExceededErr
|
|
|
3
3
|
import "../../model/index.js";
|
|
4
4
|
import { OnchainSDK } from "../OnchainSDK.js";
|
|
5
5
|
import { OperationState } from "../accounts/intents/types.js";
|
|
6
|
+
import { OpenStrategyState } from "../accounts/intents/open-strategy.js";
|
|
6
7
|
import { HealthFactorThresholds } from "./bundles/checkHealthFactors.js";
|
|
7
8
|
import { MarketStateError } from "./bundles/checkMarket.js";
|
|
8
9
|
//#region src/onchain/validation/checkSimulation.d.ts
|
|
9
10
|
/** A simulated credit operation, as the intents engine reports one. */
|
|
10
11
|
interface CreditSimulationInput {
|
|
11
12
|
chainId: ChainId;
|
|
12
|
-
state: OperationState;
|
|
13
|
+
state: OperationState | OpenStrategyState;
|
|
13
14
|
}
|
|
14
15
|
type CheckSimulationInput = CreditSimulationInput;
|
|
15
16
|
/** {@inheritDoc checkSimulation} */
|
|
@@ -34,8 +35,10 @@ type SimulationValidationError = MarketStateError | DebtOutOfRangeError | QuotaC
|
|
|
34
35
|
* touched. The engine performed all three during the walk, so a simulation that
|
|
35
36
|
* came back `ok` has already passed them.
|
|
36
37
|
*
|
|
37
|
-
* A credit account only: a pool operation has no account
|
|
38
|
-
* three things its own state decides are read by `prepare`
|
|
38
|
+
* A credit account only, opened or adjusted: a pool operation has no account
|
|
39
|
+
* to weigh, and the three things its own state decides are read by `prepare`
|
|
40
|
+
* before it answers. An opening names its quotas `averageQuota` — the branch
|
|
41
|
+
* the planner already weighed it as.
|
|
39
42
|
*/
|
|
40
43
|
declare function checkSimulation(sdk: OnchainSDK, input: CheckSimulationInput, options?: HealthFactorThresholds): SimulationValidationError[];
|
|
41
44
|
//#endregion
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Token } from "../../../model/primitives.js";
|
|
2
2
|
import { DebtOutOfRangeError } from "../../../model/errors/operation-errors.js";
|
|
3
3
|
import "../../../model/index.js";
|
|
4
|
+
import { MaxBorrowAmount } from "../../market/credit/types.js";
|
|
5
|
+
import "../../market/index.js";
|
|
4
6
|
//#region src/onchain/validation/checks/checkDebtLimits.d.ts
|
|
5
7
|
interface DebtLimitsArgs {
|
|
6
8
|
debt: bigint;
|
|
@@ -14,6 +16,8 @@ interface DebtLimitsArgs {
|
|
|
14
16
|
* rather than assumed.
|
|
15
17
|
*/
|
|
16
18
|
allowZero: boolean;
|
|
19
|
+
/** From the caller's suite; a caller that raises to throw advises nobody. */
|
|
20
|
+
ceiling?: MaxBorrowAmount;
|
|
17
21
|
}
|
|
18
22
|
/** A debt the facade would revert on. */
|
|
19
23
|
declare function checkDebtLimits(args: DebtLimitsArgs): DebtOutOfRangeError[];
|