@gearbox-protocol/sdk 17.13.0-next.3 → 17.13.0-next.4
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/accounts/intents/resolveQuotaUpdate.js +3 -0
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +57 -0
- 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/intents/resolveQuotaUpdate.js +3 -0
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +1 -0
- 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/sdk/prepare/PrepareApi.js +57 -0
- package/dist/types/onchain/accounts/intents/resolveQuotaUpdate.d.ts +6 -1
- package/dist/types/sdk/index.d.ts +2 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -2
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +21 -2
- package/package.json +1 -1
|
@@ -15,6 +15,9 @@ const require_onchain_accounts_quota_utils = require("../quota-utils.js");
|
|
|
15
15
|
const require_onchain_accounts_intents_utils_quotas_for_update = require("./utils/quotas-for-update.js");
|
|
16
16
|
//#region src/onchain/accounts/intents/resolveQuotaUpdate.ts
|
|
17
17
|
/**
|
|
18
|
+
* Synchronous calculation from the SDK's loaded market state; no RPC reads.
|
|
19
|
+
* @throws IntentPreviewError when quota validation rejects the change.
|
|
20
|
+
*
|
|
18
21
|
* The single `updateQuota` an `UPDATE_QUOTA` intent sends, checked against
|
|
19
22
|
* what the facade and the quota keeper would revert on.
|
|
20
23
|
*
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_constants_math = require("../../onchain/constants/math.js");
|
|
2
3
|
const require_onchain_utils_hex = require("../../onchain/utils/hex.js");
|
|
3
4
|
const require_onchain_base_MultichainConstruct = require("../../onchain/base/MultichainConstruct.js");
|
|
5
|
+
require("../../onchain/market/math.js");
|
|
4
6
|
const require_model_errors_prepare_errors = require("../../model/errors/prepare-errors.js");
|
|
5
7
|
const require_model_result = require("../../model/result.js");
|
|
6
8
|
require("../../model/index.js");
|
|
7
9
|
const require_onchain_validation_helpers_token = require("../../onchain/validation/helpers/token.js");
|
|
8
10
|
const require_onchain_validation_bundles_checkPoolOperation = require("../../onchain/validation/bundles/checkPoolOperation.js");
|
|
11
|
+
const require_onchain_validation_raise = require("../../onchain/validation/raise.js");
|
|
12
|
+
const require_onchain_accounts_intents_utils_pick_token = require("../../onchain/accounts/intents/utils/pick-token.js");
|
|
9
13
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("../../onchain/accounts/intents/utils/credit-account-slice.js");
|
|
14
|
+
const require_onchain_accounts_intents_resolveQuotaUpdate = require("../../onchain/accounts/intents/resolveQuotaUpdate.js");
|
|
10
15
|
const require_onchain_accounts_intents_index = require("../../onchain/accounts/intents/index.js");
|
|
11
16
|
require("../../onchain/index.js");
|
|
12
17
|
const require_sdk_prepare_withdrawable_collaterals = require("./withdrawable-collaterals.js");
|
|
@@ -494,6 +499,58 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
494
499
|
return refused(require_model_errors_prepare_errors.unexpectedFailure(e), state);
|
|
495
500
|
}
|
|
496
501
|
}
|
|
502
|
+
/** {@inheritDoc IOpportunitiesPrepare.getQuotaBufferState} */
|
|
503
|
+
getQuotaBufferState(position, extraQuotas = []) {
|
|
504
|
+
const sdk = [...this.sdk.chains.values()].find((chain) => chain.chainId === position.chainId);
|
|
505
|
+
if (!sdk) return void 0;
|
|
506
|
+
if (position.kind !== "strategy" || position.chainId !== sdk.chainId || !position.targetCollateral || position.error || position.totalDebt.value <= 0n) return void 0;
|
|
507
|
+
const target = position.targetCollateral;
|
|
508
|
+
if (require_onchain_accounts_intents_utils_pick_token.isPhantomToken(sdk, target.address)) return void 0;
|
|
509
|
+
const suite = sdk.marketRegister.creditManagers.find((s) => s.creditManager.address.toLowerCase() === position.creditManager.toLowerCase());
|
|
510
|
+
if (!suite) return void 0;
|
|
511
|
+
const collateral = position.collaterals.find((c) => c.collateral.token.address.toLowerCase() === target.address.toLowerCase());
|
|
512
|
+
if (!collateral || collateral.collateral.value <= 0n || collateral.quota.value <= 0n) return void 0;
|
|
513
|
+
const lt = BigInt(suite.creditManager.liquidationThresholds.get(target.address) ?? 0);
|
|
514
|
+
if (lt <= 0n) return void 0;
|
|
515
|
+
const value = suite.market.priceOracle.safeConvert(target.address, suite.market.pool.underlying, collateral.collateral.value);
|
|
516
|
+
if (value.error) return void 0;
|
|
517
|
+
const tokens = position.collaterals.map((c) => ({
|
|
518
|
+
token: c.collateral.token.address,
|
|
519
|
+
balance: c.collateral.value,
|
|
520
|
+
quota: c.quota.value
|
|
521
|
+
}));
|
|
522
|
+
tokens.push(...extraQuotas.map(({ token, quota }) => ({
|
|
523
|
+
token,
|
|
524
|
+
quota,
|
|
525
|
+
balance: 0n
|
|
526
|
+
})));
|
|
527
|
+
try {
|
|
528
|
+
const { update } = require_onchain_accounts_intents_resolveQuotaUpdate.resolveQuotaUpdate({
|
|
529
|
+
sdk,
|
|
530
|
+
creditAccount: {
|
|
531
|
+
creditManager: position.creditManager,
|
|
532
|
+
tokens
|
|
533
|
+
},
|
|
534
|
+
token: target.address,
|
|
535
|
+
quota: void 0,
|
|
536
|
+
quotaReserve: 500
|
|
537
|
+
});
|
|
538
|
+
const quotaIncrease = update.quotaIncrease.find((q) => q.token.toLowerCase() === target.address.toLowerCase())?.balance ?? 0n;
|
|
539
|
+
if (quotaIncrease <= 0n) return void 0;
|
|
540
|
+
return {
|
|
541
|
+
position: {
|
|
542
|
+
...position,
|
|
543
|
+
targetCollateral: target
|
|
544
|
+
},
|
|
545
|
+
baseQuota: value.value * lt / require_onchain_constants_math.PERCENTAGE_FACTOR,
|
|
546
|
+
currentQuota: collateral.quota.value,
|
|
547
|
+
quotaIncrease
|
|
548
|
+
};
|
|
549
|
+
} catch (error) {
|
|
550
|
+
if (error instanceof require_onchain_validation_raise.IntentPreviewError) return void 0;
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
497
554
|
};
|
|
498
555
|
function service(sdk) {
|
|
499
556
|
return new require_onchain_accounts_intents_index.CreditAccountOperationsService(sdk);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../abi/iERC20.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";
|
|
2
1
|
import { getNetworkType } from "../onchain/chain/chains.js";
|
|
3
2
|
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 { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
@@ -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";
|
|
@@ -14,6 +14,9 @@ import { roundUpQuota } from "../quota-utils.js";
|
|
|
14
14
|
import { resizedQuota } from "./utils/quotas-for-update.js";
|
|
15
15
|
//#region src/onchain/accounts/intents/resolveQuotaUpdate.ts
|
|
16
16
|
/**
|
|
17
|
+
* Synchronous calculation from the SDK's loaded market state; no RPC reads.
|
|
18
|
+
* @throws IntentPreviewError when quota validation rejects the change.
|
|
19
|
+
*
|
|
17
20
|
* The single `updateQuota` an `UPDATE_QUOTA` intent sends, checked against
|
|
18
21
|
* what the facade and the quota keeper would revert on.
|
|
19
22
|
*
|
|
@@ -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
|
import { optimalPartialLiquidation, partialLiquidationParams } from "./partialLiquidation.js";
|
|
24
24
|
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
25
25
|
//#region src/onchain/accounts/liquidations/LiquidationsService.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { iRedemptionLoggerV310Abi } from "../../../abi/iRedemptionLoggerV310.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
import "../../../model/index.js";
|
|
6
5
|
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 { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV310Abi } from "../../../abi/IWithdrawalCompressorV310.js";
|
|
3
3
|
//#region src/onchain/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/onchain/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/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";
|
|
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 { 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";
|
|
2
1
|
import "../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/onchain/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = {};
|
|
@@ -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/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";
|
|
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/onchain/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -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";
|
|
@@ -8,6 +7,7 @@ import "../../utils/index.js";
|
|
|
8
7
|
import { SdkRWADataNotLoadedError } from "../../core/errors.js";
|
|
9
8
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
10
9
|
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";
|
|
2
1
|
import { bytes32ToString } from "../../utils/bytes32ToString.js";
|
|
3
2
|
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 { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
2
|
+
import { iethZapperAbi } from "../../../abi/iETHZapper.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";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
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 { ierc20Abi } from "../../../abi/iERC20.js";
|
|
2
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
3
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../../abi/iERC20.js";
|
|
4
3
|
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
4
|
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 { 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";
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { PERCENTAGE_FACTOR } from "../../onchain/constants/math.js";
|
|
1
2
|
import { hexEq } from "../../onchain/utils/hex.js";
|
|
2
3
|
import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
|
|
4
|
+
import "../../onchain/market/math.js";
|
|
3
5
|
import { creditAccountNotEmpty, creditAccountNotFound, noRecordedIntent, noStrategyTargetCollateral, unexpectedFailure, unsupportedTokenPair } from "../../model/errors/prepare-errors.js";
|
|
4
6
|
import { sdkErr, sdkOk } from "../../model/result.js";
|
|
5
7
|
import "../../model/index.js";
|
|
6
8
|
import { toToken } from "../../onchain/validation/helpers/token.js";
|
|
7
9
|
import { checkPoolOperation } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
10
|
+
import { IntentPreviewError } from "../../onchain/validation/raise.js";
|
|
11
|
+
import { isPhantomToken } from "../../onchain/accounts/intents/utils/pick-token.js";
|
|
8
12
|
import { toCreditAccountSlice } from "../../onchain/accounts/intents/utils/credit-account-slice.js";
|
|
13
|
+
import { resolveQuotaUpdate } from "../../onchain/accounts/intents/resolveQuotaUpdate.js";
|
|
9
14
|
import { CreditAccountOperationsService } from "../../onchain/accounts/intents/index.js";
|
|
10
15
|
import "../../onchain/index.js";
|
|
11
16
|
import { withdrawableCollaterals } from "./withdrawable-collaterals.js";
|
|
@@ -493,6 +498,58 @@ var PrepareApi = class extends MultichainConstruct {
|
|
|
493
498
|
return refused(unexpectedFailure(e), state);
|
|
494
499
|
}
|
|
495
500
|
}
|
|
501
|
+
/** {@inheritDoc IOpportunitiesPrepare.getQuotaBufferState} */
|
|
502
|
+
getQuotaBufferState(position, extraQuotas = []) {
|
|
503
|
+
const sdk = [...this.sdk.chains.values()].find((chain) => chain.chainId === position.chainId);
|
|
504
|
+
if (!sdk) return void 0;
|
|
505
|
+
if (position.kind !== "strategy" || position.chainId !== sdk.chainId || !position.targetCollateral || position.error || position.totalDebt.value <= 0n) return void 0;
|
|
506
|
+
const target = position.targetCollateral;
|
|
507
|
+
if (isPhantomToken(sdk, target.address)) return void 0;
|
|
508
|
+
const suite = sdk.marketRegister.creditManagers.find((s) => s.creditManager.address.toLowerCase() === position.creditManager.toLowerCase());
|
|
509
|
+
if (!suite) return void 0;
|
|
510
|
+
const collateral = position.collaterals.find((c) => c.collateral.token.address.toLowerCase() === target.address.toLowerCase());
|
|
511
|
+
if (!collateral || collateral.collateral.value <= 0n || collateral.quota.value <= 0n) return void 0;
|
|
512
|
+
const lt = BigInt(suite.creditManager.liquidationThresholds.get(target.address) ?? 0);
|
|
513
|
+
if (lt <= 0n) return void 0;
|
|
514
|
+
const value = suite.market.priceOracle.safeConvert(target.address, suite.market.pool.underlying, collateral.collateral.value);
|
|
515
|
+
if (value.error) return void 0;
|
|
516
|
+
const tokens = position.collaterals.map((c) => ({
|
|
517
|
+
token: c.collateral.token.address,
|
|
518
|
+
balance: c.collateral.value,
|
|
519
|
+
quota: c.quota.value
|
|
520
|
+
}));
|
|
521
|
+
tokens.push(...extraQuotas.map(({ token, quota }) => ({
|
|
522
|
+
token,
|
|
523
|
+
quota,
|
|
524
|
+
balance: 0n
|
|
525
|
+
})));
|
|
526
|
+
try {
|
|
527
|
+
const { update } = resolveQuotaUpdate({
|
|
528
|
+
sdk,
|
|
529
|
+
creditAccount: {
|
|
530
|
+
creditManager: position.creditManager,
|
|
531
|
+
tokens
|
|
532
|
+
},
|
|
533
|
+
token: target.address,
|
|
534
|
+
quota: void 0,
|
|
535
|
+
quotaReserve: 500
|
|
536
|
+
});
|
|
537
|
+
const quotaIncrease = update.quotaIncrease.find((q) => q.token.toLowerCase() === target.address.toLowerCase())?.balance ?? 0n;
|
|
538
|
+
if (quotaIncrease <= 0n) return void 0;
|
|
539
|
+
return {
|
|
540
|
+
position: {
|
|
541
|
+
...position,
|
|
542
|
+
targetCollateral: target
|
|
543
|
+
},
|
|
544
|
+
baseQuota: value.value * lt / PERCENTAGE_FACTOR,
|
|
545
|
+
currentQuota: collateral.quota.value,
|
|
546
|
+
quotaIncrease
|
|
547
|
+
};
|
|
548
|
+
} catch (error) {
|
|
549
|
+
if (error instanceof IntentPreviewError) return void 0;
|
|
550
|
+
throw error;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
496
553
|
};
|
|
497
554
|
function service(sdk) {
|
|
498
555
|
return new CreditAccountOperationsService(sdk);
|
|
@@ -8,7 +8,9 @@ import { Address } from "viem";
|
|
|
8
8
|
//#region src/onchain/accounts/intents/resolveQuotaUpdate.d.ts
|
|
9
9
|
interface ResolveQuotaUpdateProps {
|
|
10
10
|
sdk: OnchainSDK;
|
|
11
|
-
creditAccount: CreditAccountSlice
|
|
11
|
+
creditAccount: Pick<CreditAccountSlice, "creditManager"> & {
|
|
12
|
+
tokens: ReadonlyArray<Pick<CreditAccountSlice["tokens"][number], "token" | "balance" | "quota">>;
|
|
13
|
+
};
|
|
12
14
|
token: Address;
|
|
13
15
|
/** Target in underlying units; `undefined` sizes it to the balance. */
|
|
14
16
|
quota: bigint | undefined;
|
|
@@ -21,6 +23,9 @@ interface ResolvedQuotaUpdate {
|
|
|
21
23
|
minQuota: Asset[];
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
26
|
+
* Synchronous calculation from the SDK's loaded market state; no RPC reads.
|
|
27
|
+
* @throws IntentPreviewError when quota validation rejects the change.
|
|
28
|
+
*
|
|
24
29
|
* The single `updateQuota` an `UPDATE_QUOTA` intent sends, checked against
|
|
25
30
|
* what the facade and the quota keeper would revert on.
|
|
26
31
|
*
|
|
@@ -5,7 +5,7 @@ import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
|
|
|
5
5
|
import { PoolOperationError } from "../onchain/validation/bundles/checkPoolOperation.js";
|
|
6
6
|
import { IAnalytics, IAnalyticsByMode } from "./analytics/types.js";
|
|
7
7
|
import { ILiquidations, ILiquidationsByMode, IsEmergencyLiquidatorProps } from "./liquidations/types.js";
|
|
8
|
-
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
8
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
9
9
|
import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
|
|
10
10
|
import "./prepare/index.js";
|
|
11
11
|
import { AccountPrepareRequest, BorrowPrepareRequest, IOpportunitiesExecute, OpenEmptyPrepareRequest, OpenPrepareRequest, PoolPrepareRequest, PrepareRequest } from "./execute/types.js";
|
|
@@ -45,4 +45,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
45
45
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
46
46
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
47
47
|
import "./errors/index.js";
|
|
48
|
-
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, BorrowParams, BorrowPrepareRequest, BorrowResult, type BorrowState, ChainOf, ChainRef, CheckOperationProps, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, EnsureFreshChains, type EntityMerger, ExecuteApi, type ExecutionCost, type FilterResult, FinalizeParams, FinalizeResult, GearboxSDK, GearboxSDKOptions, IAnalytics, IAnalyticsByMode, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, type IRewards, type IRewardsByMode, IsEmergencyLiquidatorProps, type LeverageBand, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MergeListResult, MergedQuery, MerklRequestFailedError, type MerkleXYZUserRewardsV4Response, MissingSourceError, Mode, type MultipleDelayedWithdrawalsError, NamespaceOptions, type NoDelayedRouteError, type NoRecordedIntentError, NoSourceServedError, type NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenEmptyPrepareRequest, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, type PoolOperationError, PoolPrepareRequest, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewNamespace, RepayStrategyParams, type RewardsKeys, RewardsNamespace, type RouteErrors, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, TurtleRequestFailedError, type TurtleWalletRewards, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, assertSameChains, creditAccountNotEmpty, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, unexpectedFailure };
|
|
48
|
+
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, BorrowParams, BorrowPrepareRequest, BorrowResult, type BorrowState, ChainOf, ChainRef, CheckOperationProps, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, EnsureFreshChains, type EntityMerger, ExecuteApi, type ExecutionCost, type FilterResult, FinalizeParams, FinalizeResult, GearboxSDK, GearboxSDKOptions, IAnalytics, IAnalyticsByMode, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, type IRewards, type IRewardsByMode, IsEmergencyLiquidatorProps, type LeverageBand, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MergeListResult, MergedQuery, MerklRequestFailedError, type MerkleXYZUserRewardsV4Response, MissingSourceError, Mode, type MultipleDelayedWithdrawalsError, NamespaceOptions, type NoDelayedRouteError, type NoRecordedIntentError, NoSourceServedError, type NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenEmptyPrepareRequest, OpenFlowError, OpenPrepareRequest, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, type PoolOperationError, PoolPrepareRequest, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewNamespace, QuotaBufferState, RepayStrategyParams, type RewardsKeys, RewardsNamespace, type RouteErrors, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, TurtleRequestFailedError, type TurtleWalletRewards, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, assertSameChains, creditAccountNotEmpty, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, unexpectedFailure };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bps, ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { CreditManagerPausedError, DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaAboveMaxError, QuotaInactiveError, QuotaUnchangedError } from "../../model/errors/operation-errors.js";
|
|
3
3
|
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
|
|
4
|
-
import { PositionCollateral, StrategyPosition } from "../../model/positions.js";
|
|
4
|
+
import { Position, PositionCollateral, StrategyPosition } from "../../model/positions.js";
|
|
5
5
|
import { SDKReturn } from "../../model/result.js";
|
|
6
6
|
import "../../model/index.js";
|
|
7
7
|
import { Asset } from "../../onchain/base/types.js";
|
|
@@ -14,7 +14,7 @@ import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
|
14
14
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
15
15
|
import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
16
16
|
import "../../onchain/index.js";
|
|
17
|
-
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
17
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
18
18
|
import { EnsureFreshChains } from "../types.js";
|
|
19
19
|
import { Address } from "viem";
|
|
20
20
|
//#region src/sdk/prepare/PrepareApi.d.ts
|
|
@@ -130,6 +130,10 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
|
|
|
130
130
|
* {@inheritDoc IOpportunitiesPrepare.maxBorrow}
|
|
131
131
|
**/
|
|
132
132
|
maxBorrow(strategy: StrategyInput, params: MaxBorrowParams): bigint;
|
|
133
|
+
/** {@inheritDoc IOpportunitiesPrepare.getQuotaBufferState} */
|
|
134
|
+
getQuotaBufferState(position: Position, extraQuotas?: readonly (Pick<Asset, "token"> & {
|
|
135
|
+
quota: bigint;
|
|
136
|
+
})[]): QuotaBufferState | undefined;
|
|
133
137
|
}
|
|
134
138
|
//#endregion
|
|
135
139
|
export { ChainOf, PrepareApi };
|
|
@@ -4,6 +4,6 @@ import { ExecutionCost, OperationState, PathLossRate, RouteErrors, WithPartialSt
|
|
|
4
4
|
import { BorrowState } from "../../onchain/accounts/intents/borrow.js";
|
|
5
5
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
6
6
|
import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
7
|
-
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
7
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
8
8
|
import { ChainOf, PrepareApi } from "./PrepareApi.js";
|
|
9
|
-
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareApi, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure };
|
|
9
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareApi, PrepareOptions, QuotaBufferState, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure };
|
|
@@ -3,7 +3,7 @@ import { Curator } from "../../model/curators.js";
|
|
|
3
3
|
import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaAboveMaxError, QuotaInactiveError, QuotaLimitReachedError, QuotaUnchangedError, ReservePriceLimitedError } from "../../model/errors/operation-errors.js";
|
|
4
4
|
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
|
|
5
5
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
6
|
-
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
6
|
+
import { Position, PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
7
7
|
import { SDKReturn } from "../../model/result.js";
|
|
8
8
|
import { PositionClaimableWithdrawal } from "../../model/withdrawals.js";
|
|
9
9
|
import "../../model/index.js";
|
|
@@ -19,6 +19,18 @@ import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOp
|
|
|
19
19
|
import "../../onchain/index.js";
|
|
20
20
|
import { Address } from "viem";
|
|
21
21
|
//#region src/sdk/prepare/types.d.ts
|
|
22
|
+
/** Recoverable target-token quota, computed from loaded market state. */
|
|
23
|
+
interface QuotaBufferState {
|
|
24
|
+
/** Validated strategy context, with a known target collateral. */
|
|
25
|
+
position: StrategyPosition & {
|
|
26
|
+
targetCollateral: NonNullable<StrategyPosition["targetCollateral"]>;
|
|
27
|
+
};
|
|
28
|
+
/** Target value times LT, before reserve and protocol-step rounding. */
|
|
29
|
+
baseQuota: bigint;
|
|
30
|
+
currentQuota: bigint;
|
|
31
|
+
/** Positive increase available under the pool and account limits. */
|
|
32
|
+
quotaIncrease: bigint;
|
|
33
|
+
}
|
|
22
34
|
interface MaxWithdrawCollateralOptions {
|
|
23
35
|
/** Main-price HF threshold, in basis points; defaults to 10101. */
|
|
24
36
|
targetHF?: bigint;
|
|
@@ -566,6 +578,13 @@ interface FinalizeParams extends PrepareOptions {
|
|
|
566
578
|
* with `undefined`, an empty list or `0n`.
|
|
567
579
|
**/
|
|
568
580
|
interface IOpportunitiesPrepare {
|
|
581
|
+
/** Synchronous quota-buffer state from loaded chain data. No freshness refresh
|
|
582
|
+
* or account RPC read. Ineligible positions return undefined; unexpected
|
|
583
|
+
* failures are thrown. extraQuotas includes reservations absent from the position.
|
|
584
|
+
*/
|
|
585
|
+
getQuotaBufferState(position: Position, extraQuotas?: readonly (Pick<Asset, "token"> & {
|
|
586
|
+
quota: bigint;
|
|
587
|
+
})[]): QuotaBufferState | undefined;
|
|
569
588
|
/**
|
|
570
589
|
* Depositing into a pool: underlying in, shares out.
|
|
571
590
|
*
|
|
@@ -859,4 +878,4 @@ interface IOpportunitiesPrepare {
|
|
|
859
878
|
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<FinalizeResult, (AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError) & WithPartialState<OperationState>>>;
|
|
860
879
|
}
|
|
861
880
|
//#endregion
|
|
862
|
-
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError };
|
|
881
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowParams, BorrowResult, type BorrowState, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowParams, MaxWithdrawCollateralOptions, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareOptions, QuotaBufferState, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, UpdateQuotaParams, type WithPartialState, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError };
|