@gearbox-protocol/sdk 18.2.0 → 18.3.1
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/index.js +11 -0
- package/dist/cjs/onchain/accounts/intents/maxBorrowAndWithdraw.js +31 -0
- package/dist/cjs/onchain/accounts/intents/plan.js +19 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +19 -1
- 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/index.js +12 -1
- package/dist/esm/onchain/accounts/intents/maxBorrowAndWithdraw.js +30 -0
- package/dist/esm/onchain/accounts/intents/plan.js +20 -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/sdk/prepare/PrepareApi.js +19 -1
- package/dist/types/onchain/accounts/intents/index.d.ts +5 -0
- package/dist/types/onchain/accounts/intents/maxBorrowAndWithdraw.d.ts +12 -0
- package/dist/types/onchain/accounts/intents/plan.d.ts +2 -1
- package/dist/types/onchain/accounts/intents/types.d.ts +9 -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 +20 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ const require_onchain_accounts_intents_strategyLimits = require("./strategyLimit
|
|
|
15
15
|
const require_onchain_accounts_intents_view = require("./view.js");
|
|
16
16
|
const require_onchain_accounts_intents_leverage_band = require("./leverage-band.js");
|
|
17
17
|
const require_onchain_accounts_intents_maxBorrow = require("./maxBorrow.js");
|
|
18
|
+
const require_onchain_accounts_intents_maxBorrowAndWithdraw = require("./maxBorrowAndWithdraw.js");
|
|
18
19
|
const require_onchain_accounts_intents_maxWithdrawCollateral = require("./maxWithdrawCollateral.js");
|
|
19
20
|
const require_onchain_accounts_intents_open_strategy = require("./open-strategy.js");
|
|
20
21
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
@@ -60,6 +61,7 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
60
61
|
};
|
|
61
62
|
switch (intent.type) {
|
|
62
63
|
case "ADD_COLLATERAL": return require_onchain_accounts_intents_plan.planAddCollateral(intent);
|
|
64
|
+
case "BORROW_AND_WITHDRAW": return require_onchain_accounts_intents_plan.planBorrowAndWithdraw(intent, view);
|
|
63
65
|
case "WITHDRAW_ASSET": return require_onchain_accounts_intents_plan.planWithdrawAsset(intent, view);
|
|
64
66
|
case "ADJUST_LEVERAGE": return require_onchain_accounts_intents_plan.planAdjustLeverage(intent, view);
|
|
65
67
|
case "DEPOSIT": return require_onchain_accounts_intents_plan.planDeposit(intent, view);
|
|
@@ -136,6 +138,15 @@ var CreditAccountOperationsService = class extends require_onchain_base_SDKConst
|
|
|
136
138
|
leverageBand(props) {
|
|
137
139
|
return require_onchain_accounts_intents_leverage_band.calcLeverageBand(props);
|
|
138
140
|
}
|
|
141
|
+
/** Largest additional loan, in payout units, preserving existing assets and quotas. */
|
|
142
|
+
maxBorrowAndWithdraw(props) {
|
|
143
|
+
const { targetHF = BigInt(require_onchain_validation_helpers_health_factor_limits.MIN_HEALTH_FACTOR_FORM), targetSafeHF = BigInt(require_onchain_validation_helpers_health_factor_limits.MIN_SAFE_HEALTH_FACTOR_FORM), ...rest } = props;
|
|
144
|
+
return require_onchain_accounts_intents_maxBorrowAndWithdraw.maxBorrowAndWithdraw({
|
|
145
|
+
...rest,
|
|
146
|
+
targetHF: targetHF + 2n,
|
|
147
|
+
targetSafeHF: targetSafeHF + 2n
|
|
148
|
+
});
|
|
149
|
+
}
|
|
139
150
|
/**
|
|
140
151
|
* Largest `WITHDRAW_ASSET` amount of one token the account can take out
|
|
141
152
|
* while its main and safe health factors clear their targets — the ceiling a
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_bigint_math = require("../../utils/bigint-math.js");
|
|
3
|
+
const require_onchain_constants_math = require("../../constants/math.js");
|
|
4
|
+
const require_onchain_accounts_intents_utils_common = require("./utils/common.js");
|
|
5
|
+
const require_onchain_accounts_intents_collateral_valuation = require("./collateral-valuation.js");
|
|
6
|
+
//#region src/onchain/accounts/intents/maxBorrowAndWithdraw.ts
|
|
7
|
+
function maxBorrowAndWithdraw(props) {
|
|
8
|
+
const { sdk, creditAccount, targetHF, targetSafeHF } = props;
|
|
9
|
+
const suite = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
10
|
+
const { market } = suite;
|
|
11
|
+
if (targetHF <= 0n || targetSafeHF <= 0n || suite.isPaused || suite.isExpired) return 0n;
|
|
12
|
+
const supportedDebt = (target, safePrices) => {
|
|
13
|
+
const valuation = require_onchain_accounts_intents_collateral_valuation.collateralValuation(creditAccount, sdk, safePrices);
|
|
14
|
+
let backed = 0n;
|
|
15
|
+
for (const holding of creditAccount.tokens) {
|
|
16
|
+
if (!valuation.counts(holding)) continue;
|
|
17
|
+
if (holding.quota === 0n && market.pool.pqk.hasActiveQuota(holding.token)) continue;
|
|
18
|
+
backed += valuation.weigh(holding);
|
|
19
|
+
}
|
|
20
|
+
return market.priceOracle.safeConvertFromUSD(creditAccount.underlying, backed / target).value;
|
|
21
|
+
};
|
|
22
|
+
const totalDebt = require_onchain_utils_bigint_math.BigIntMath.min(supportedDebt(targetHF, false), supportedDebt(targetSafeHF, true), suite.creditFacade.maxDebt);
|
|
23
|
+
const borrowable = suite.maxBorrowAmount().amount.value * (require_onchain_constants_math.PERCENTAGE_FACTOR - 2n) / require_onchain_constants_math.PERCENTAGE_FACTOR;
|
|
24
|
+
const additional = require_onchain_utils_bigint_math.BigIntMath.max(0n, require_onchain_utils_bigint_math.BigIntMath.min(totalDebt - creditAccount.totalDebt, borrowable));
|
|
25
|
+
const asset = sdk.tokensMeta.rwaUnderlyings.get(creditAccount.underlying)?.asset;
|
|
26
|
+
const payout = asset ? require_onchain_accounts_intents_utils_common.toTargetDecimals(additional, creditAccount.underlying, asset, sdk) : additional;
|
|
27
|
+
const increase = asset ? require_onchain_accounts_intents_utils_common.toTargetDecimals(payout, asset, creditAccount.underlying, sdk) : payout;
|
|
28
|
+
return creditAccount.totalDebt + increase < suite.creditFacade.minDebt ? 0n : payout;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.maxBorrowAndWithdraw = maxBorrowAndWithdraw;
|
|
@@ -21,6 +21,24 @@ function planWithdrawAsset(intent, view) {
|
|
|
21
21
|
assertPositive(intent.amount, "withdrawAsset");
|
|
22
22
|
return withdraw(view, intent.token, intent.amount, intent.to);
|
|
23
23
|
}
|
|
24
|
+
function planBorrowAndWithdraw(intent, view) {
|
|
25
|
+
assertPositive(intent.amount, "borrowAndWithdraw");
|
|
26
|
+
const token = view.rwaAsset ?? view.underlying;
|
|
27
|
+
const debt = view.rwaAsset ? require_onchain_accounts_intents_utils_common.toTargetDecimals(intent.amount, token, view.underlying, view.sdk) : intent.amount;
|
|
28
|
+
assertPositive(debt, "borrowAndWithdraw");
|
|
29
|
+
if (view.rwaAsset && require_onchain_accounts_intents_utils_common.toTargetDecimals(debt, view.underlying, token, view.sdk) !== intent.amount) throw new require_onchain_validation_raise.IntentPreviewError(require_model_errors_operation_errors.insufficientBalance(), "borrowAndWithdraw: payout cannot be represented in underlying units");
|
|
30
|
+
require_onchain_accounts_intents_math.assertDebtLimits(view.sdk, view.debt + debt, view.debtLimits, view.underlying);
|
|
31
|
+
return [
|
|
32
|
+
borrow(debt),
|
|
33
|
+
convert(view.underlying, token, debt),
|
|
34
|
+
{
|
|
35
|
+
kind: "withdraw",
|
|
36
|
+
token,
|
|
37
|
+
amount: intent.amount,
|
|
38
|
+
to: intent.to
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
24
42
|
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
25
43
|
function planAdjustLeverage(intent, view) {
|
|
26
44
|
const { U, delta } = leverageShape(intent, view);
|
|
@@ -432,6 +450,7 @@ exports.RAISED = RAISED;
|
|
|
432
450
|
exports.planAddCollateral = planAddCollateral;
|
|
433
451
|
exports.planAdjustLeverage = planAdjustLeverage;
|
|
434
452
|
exports.planAdjustLeverageDelayed = planAdjustLeverageDelayed;
|
|
453
|
+
exports.planBorrowAndWithdraw = planBorrowAndWithdraw;
|
|
435
454
|
exports.planDeposit = planDeposit;
|
|
436
455
|
exports.planFinishClaimOnly = planFinishClaimOnly;
|
|
437
456
|
exports.planFinishCloseAccount = planFinishCloseAccount;
|
|
@@ -365,9 +365,27 @@ var PrepareApi = class extends require_onchain_base_MultichainConstruct.Multicha
|
|
|
365
365
|
value: params.value
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
|
+
/** {@inheritDoc IOpportunitiesPrepare.maxBorrowAndWithdraw} */
|
|
369
|
+
async maxBorrowAndWithdraw(position, options) {
|
|
370
|
+
const sdk = await this.#chain(position.chainId);
|
|
371
|
+
const creditAccount = await this.#account(sdk, position);
|
|
372
|
+
return service(sdk).maxBorrowAndWithdraw({
|
|
373
|
+
sdk,
|
|
374
|
+
creditAccount,
|
|
375
|
+
...options
|
|
376
|
+
});
|
|
377
|
+
}
|
|
368
378
|
/**
|
|
369
|
-
* {@inheritDoc IOpportunitiesPrepare.
|
|
379
|
+
* {@inheritDoc IOpportunitiesPrepare.borrowAndWithdraw}
|
|
370
380
|
**/
|
|
381
|
+
async borrowAndWithdraw(position, params) {
|
|
382
|
+
return this.#startIntent(position, {}, {
|
|
383
|
+
type: "BORROW_AND_WITHDRAW",
|
|
384
|
+
amount: params.amount,
|
|
385
|
+
to: params.to
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
/** {@inheritDoc IOpportunitiesPrepare.withdrawCollateral} */
|
|
371
389
|
async withdrawCollateral(position, params) {
|
|
372
390
|
return this.#startIntent(position, params, {
|
|
373
391
|
type: "WITHDRAW_ASSET",
|
|
@@ -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";
|
|
@@ -14,9 +14,10 @@ import { strategyLimits } from "./strategyLimits.js";
|
|
|
14
14
|
import { accountView } from "./view.js";
|
|
15
15
|
import { calcLeverageBand } from "./leverage-band.js";
|
|
16
16
|
import { maxBorrow } from "./maxBorrow.js";
|
|
17
|
+
import { maxBorrowAndWithdraw } from "./maxBorrowAndWithdraw.js";
|
|
17
18
|
import { maxWithdrawCollateral } from "./maxWithdrawCollateral.js";
|
|
18
19
|
import { buildOpenStrategyState } from "./open-strategy.js";
|
|
19
|
-
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
20
|
+
import { planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planDeposit, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed } from "./plan.js";
|
|
20
21
|
import { withdrawLimits } from "./withdraw-limits.js";
|
|
21
22
|
import { realize } from "./realize.js";
|
|
22
23
|
import { planTail, projectTail } from "./tail.js";
|
|
@@ -59,6 +60,7 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
59
60
|
};
|
|
60
61
|
switch (intent.type) {
|
|
61
62
|
case "ADD_COLLATERAL": return planAddCollateral(intent);
|
|
63
|
+
case "BORROW_AND_WITHDRAW": return planBorrowAndWithdraw(intent, view);
|
|
62
64
|
case "WITHDRAW_ASSET": return planWithdrawAsset(intent, view);
|
|
63
65
|
case "ADJUST_LEVERAGE": return planAdjustLeverage(intent, view);
|
|
64
66
|
case "DEPOSIT": return planDeposit(intent, view);
|
|
@@ -135,6 +137,15 @@ var CreditAccountOperationsService = class extends SDKConstruct {
|
|
|
135
137
|
leverageBand(props) {
|
|
136
138
|
return calcLeverageBand(props);
|
|
137
139
|
}
|
|
140
|
+
/** Largest additional loan, in payout units, preserving existing assets and quotas. */
|
|
141
|
+
maxBorrowAndWithdraw(props) {
|
|
142
|
+
const { targetHF = BigInt(MIN_HEALTH_FACTOR_FORM), targetSafeHF = BigInt(MIN_SAFE_HEALTH_FACTOR_FORM), ...rest } = props;
|
|
143
|
+
return maxBorrowAndWithdraw({
|
|
144
|
+
...rest,
|
|
145
|
+
targetHF: targetHF + 2n,
|
|
146
|
+
targetSafeHF: targetSafeHF + 2n
|
|
147
|
+
});
|
|
148
|
+
}
|
|
138
149
|
/**
|
|
139
150
|
* Largest `WITHDRAW_ASSET` amount of one token the account can take out
|
|
140
151
|
* while its main and safe health factors clear their targets — the ceiling a
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BigIntMath } from "../../utils/bigint-math.js";
|
|
2
|
+
import { PERCENTAGE_FACTOR } from "../../constants/math.js";
|
|
3
|
+
import { toTargetDecimals } from "./utils/common.js";
|
|
4
|
+
import { collateralValuation } from "./collateral-valuation.js";
|
|
5
|
+
//#region src/onchain/accounts/intents/maxBorrowAndWithdraw.ts
|
|
6
|
+
function maxBorrowAndWithdraw(props) {
|
|
7
|
+
const { sdk, creditAccount, targetHF, targetSafeHF } = props;
|
|
8
|
+
const suite = sdk.marketRegister.findCreditManager(creditAccount.creditManager);
|
|
9
|
+
const { market } = suite;
|
|
10
|
+
if (targetHF <= 0n || targetSafeHF <= 0n || suite.isPaused || suite.isExpired) return 0n;
|
|
11
|
+
const supportedDebt = (target, safePrices) => {
|
|
12
|
+
const valuation = collateralValuation(creditAccount, sdk, safePrices);
|
|
13
|
+
let backed = 0n;
|
|
14
|
+
for (const holding of creditAccount.tokens) {
|
|
15
|
+
if (!valuation.counts(holding)) continue;
|
|
16
|
+
if (holding.quota === 0n && market.pool.pqk.hasActiveQuota(holding.token)) continue;
|
|
17
|
+
backed += valuation.weigh(holding);
|
|
18
|
+
}
|
|
19
|
+
return market.priceOracle.safeConvertFromUSD(creditAccount.underlying, backed / target).value;
|
|
20
|
+
};
|
|
21
|
+
const totalDebt = BigIntMath.min(supportedDebt(targetHF, false), supportedDebt(targetSafeHF, true), suite.creditFacade.maxDebt);
|
|
22
|
+
const borrowable = suite.maxBorrowAmount().amount.value * (PERCENTAGE_FACTOR - 2n) / PERCENTAGE_FACTOR;
|
|
23
|
+
const additional = BigIntMath.max(0n, BigIntMath.min(totalDebt - creditAccount.totalDebt, borrowable));
|
|
24
|
+
const asset = sdk.tokensMeta.rwaUnderlyings.get(creditAccount.underlying)?.asset;
|
|
25
|
+
const payout = asset ? toTargetDecimals(additional, creditAccount.underlying, asset, sdk) : additional;
|
|
26
|
+
const increase = asset ? toTargetDecimals(payout, asset, creditAccount.underlying, sdk) : payout;
|
|
27
|
+
return creditAccount.totalDebt + increase < suite.creditFacade.minDebt ? 0n : payout;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { maxBorrowAndWithdraw };
|
|
@@ -5,7 +5,7 @@ import { noDelayedRoute, unsupportedCollateralToken } from "../../../model/error
|
|
|
5
5
|
import "../../../model/index.js";
|
|
6
6
|
import { toToken, toTokenAmount } from "../../validation/helpers/token.js";
|
|
7
7
|
import { IntentPreviewError } from "../../validation/raise.js";
|
|
8
|
-
import { eq } from "./utils/common.js";
|
|
8
|
+
import { eq, toTargetDecimals } from "./utils/common.js";
|
|
9
9
|
import { assertDebtLimits, assertLeverageAtLeastOne, debtForLeverage, proportionalDebt } from "./math.js";
|
|
10
10
|
//#region src/onchain/accounts/intents/plan.ts
|
|
11
11
|
/** Whatever the previous convert produced. */
|
|
@@ -20,6 +20,24 @@ function planWithdrawAsset(intent, view) {
|
|
|
20
20
|
assertPositive(intent.amount, "withdrawAsset");
|
|
21
21
|
return withdraw(view, intent.token, intent.amount, intent.to);
|
|
22
22
|
}
|
|
23
|
+
function planBorrowAndWithdraw(intent, view) {
|
|
24
|
+
assertPositive(intent.amount, "borrowAndWithdraw");
|
|
25
|
+
const token = view.rwaAsset ?? view.underlying;
|
|
26
|
+
const debt = view.rwaAsset ? toTargetDecimals(intent.amount, token, view.underlying, view.sdk) : intent.amount;
|
|
27
|
+
assertPositive(debt, "borrowAndWithdraw");
|
|
28
|
+
if (view.rwaAsset && toTargetDecimals(debt, view.underlying, token, view.sdk) !== intent.amount) throw new IntentPreviewError(insufficientBalance(), "borrowAndWithdraw: payout cannot be represented in underlying units");
|
|
29
|
+
assertDebtLimits(view.sdk, view.debt + debt, view.debtLimits, view.underlying);
|
|
30
|
+
return [
|
|
31
|
+
borrow(debt),
|
|
32
|
+
convert(view.underlying, token, debt),
|
|
33
|
+
{
|
|
34
|
+
kind: "withdraw",
|
|
35
|
+
token,
|
|
36
|
+
amount: intent.amount,
|
|
37
|
+
to: intent.to
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
23
41
|
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
24
42
|
function planAdjustLeverage(intent, view) {
|
|
25
43
|
const { U, delta } = leverageShape(intent, view);
|
|
@@ -427,4 +445,4 @@ function assertPositive(amount, flow) {
|
|
|
427
445
|
if (amount <= 0n) throw new IntentPreviewError(insufficientBalance(), `${flow}: amount must be positive`);
|
|
428
446
|
}
|
|
429
447
|
//#endregion
|
|
430
|
-
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
448
|
+
export { RAISED, planAddCollateral, planAdjustLeverage, planAdjustLeverageDelayed, planBorrowAndWithdraw, planDeposit, planFinishClaimOnly, planFinishCloseAccount, planFinishDecreaseLeverage, planFinishWithdraw, planRepay, planUpdateQuota, planWithdraw, planWithdrawAsset, planWithdrawDelayed };
|
|
@@ -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 { optimalPartialLiquidation, partialLiquidationParams } from "./partialLiquidation.js";
|
|
24
24
|
import { skipLiquidatableAccount } from "./skipLiquidatableAccount.js";
|
|
25
25
|
import { isAddressEqual } from "viem";
|
|
@@ -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
|
import { decodeAbiParameters } from "viem";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
1
2
|
import "../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 = {};
|
|
@@ -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";
|
|
@@ -364,9 +364,27 @@ var PrepareApi = class extends MultichainConstruct {
|
|
|
364
364
|
value: params.value
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
|
+
/** {@inheritDoc IOpportunitiesPrepare.maxBorrowAndWithdraw} */
|
|
368
|
+
async maxBorrowAndWithdraw(position, options) {
|
|
369
|
+
const sdk = await this.#chain(position.chainId);
|
|
370
|
+
const creditAccount = await this.#account(sdk, position);
|
|
371
|
+
return service(sdk).maxBorrowAndWithdraw({
|
|
372
|
+
sdk,
|
|
373
|
+
creditAccount,
|
|
374
|
+
...options
|
|
375
|
+
});
|
|
376
|
+
}
|
|
367
377
|
/**
|
|
368
|
-
* {@inheritDoc IOpportunitiesPrepare.
|
|
378
|
+
* {@inheritDoc IOpportunitiesPrepare.borrowAndWithdraw}
|
|
369
379
|
**/
|
|
380
|
+
async borrowAndWithdraw(position, params) {
|
|
381
|
+
return this.#startIntent(position, {}, {
|
|
382
|
+
type: "BORROW_AND_WITHDRAW",
|
|
383
|
+
amount: params.amount,
|
|
384
|
+
to: params.to
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
/** {@inheritDoc IOpportunitiesPrepare.withdrawCollateral} */
|
|
370
388
|
async withdrawCollateral(position, params) {
|
|
371
389
|
return this.#startIntent(position, params, {
|
|
372
390
|
type: "WITHDRAW_ASSET",
|
|
@@ -120,6 +120,11 @@ export declare class CreditAccountOperationsService extends SDKConstruct {
|
|
|
120
120
|
* @returns The band, or nothing when the market has none to offer
|
|
121
121
|
*/
|
|
122
122
|
leverageBand(props: LeverageBandProps): LeverageBand | undefined;
|
|
123
|
+
/** Largest additional loan, in payout units, preserving existing assets and quotas. */
|
|
124
|
+
maxBorrowAndWithdraw(props: Pick<StartIntentProps, "creditAccount" | "sdk"> & {
|
|
125
|
+
targetHF?: bigint;
|
|
126
|
+
targetSafeHF?: bigint;
|
|
127
|
+
}): bigint;
|
|
123
128
|
/**
|
|
124
129
|
* Largest `WITHDRAW_ASSET` amount of one token the account can take out
|
|
125
130
|
* while its main and safe health factors clear their targets — the ceiling a
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
2
|
+
import { CreditAccountSlice } from "./types.js";
|
|
3
|
+
import "../../index.js";
|
|
4
|
+
//#region src/onchain/accounts/intents/maxBorrowAndWithdraw.d.ts
|
|
5
|
+
export interface MaxBorrowAndWithdrawProps {
|
|
6
|
+
creditAccount: CreditAccountSlice;
|
|
7
|
+
sdk: OnchainSDK;
|
|
8
|
+
targetHF: bigint;
|
|
9
|
+
targetSafeHF: bigint;
|
|
10
|
+
}
|
|
11
|
+
export declare function maxBorrowAndWithdraw(props: MaxBorrowAndWithdrawProps): bigint;
|
|
12
|
+
//#endregion
|
|
@@ -3,7 +3,7 @@ import { OperationLimitOptions } from "../../../model/errors/operation-errors.js
|
|
|
3
3
|
import "../../../model/index.js";
|
|
4
4
|
import { ClaimableWithdrawal } from "../withdrawal-compressor/types.js";
|
|
5
5
|
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
6
|
-
import { AddCollateralIntent, AdjustLeverageIntent, DepositStrategyIntent, RepayStrategyIntent, UpdateQuotaIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
|
|
6
|
+
import { AddCollateralIntent, AdjustLeverageIntent, BorrowAndWithdrawIntent, DepositStrategyIntent, RepayStrategyIntent, UpdateQuotaIntent, WithdrawAssetIntent, WithdrawStrategyIntent } from "./types.js";
|
|
7
7
|
import { DebtLimits } from "./math.js";
|
|
8
8
|
import { Address } from "viem";
|
|
9
9
|
//#region src/onchain/accounts/intents/plan.d.ts
|
|
@@ -131,6 +131,7 @@ export interface AccountView {
|
|
|
131
131
|
export declare function planAddCollateral(intent: Omit<AddCollateralIntent, "type">): Step[];
|
|
132
132
|
/** Intent 4: one asset out at fixed debt. */
|
|
133
133
|
export declare function planWithdrawAsset(intent: Omit<WithdrawAssetIntent, "type">, view: AccountView): Step[];
|
|
134
|
+
export declare function planBorrowAndWithdraw(intent: Omit<BorrowAndWithdrawIntent, "type">, view: AccountView): Step[];
|
|
134
135
|
/** Intent 6: collateral fixed, debt retargeted to `C0 · (L1 − 1)`. */
|
|
135
136
|
export declare function planAdjustLeverage(intent: Omit<AdjustLeverageIntent, "type">, view: AccountView): Step[];
|
|
136
137
|
/** Intents 1.1 / 1.2: collateral grows by `a`, debt grows to match. */
|
|
@@ -328,6 +328,14 @@ export interface AddCollateralIntent {
|
|
|
328
328
|
*/
|
|
329
329
|
value?: bigint;
|
|
330
330
|
}
|
|
331
|
+
/** A loan paid to the recipient while existing balances stay on the account. */
|
|
332
|
+
export interface BorrowAndWithdrawIntent {
|
|
333
|
+
type: "BORROW_AND_WITHDRAW";
|
|
334
|
+
/** Amount received in the underlying, or its RWA asset. */
|
|
335
|
+
amount: bigint;
|
|
336
|
+
/** Wallet receiving the loan. */
|
|
337
|
+
to: Address;
|
|
338
|
+
}
|
|
331
339
|
/**
|
|
332
340
|
* Intent 4 — move one asset that already sits on the account to the wallet.
|
|
333
341
|
*
|
|
@@ -552,7 +560,7 @@ export interface WithdrawCeilings {
|
|
|
552
560
|
*/
|
|
553
561
|
exit: bigint;
|
|
554
562
|
}
|
|
555
|
-
export type StartIntent = AddCollateralIntent | WithdrawAssetIntent | AdjustLeverageIntent | DepositStrategyIntent | RepayStrategyIntent | WithdrawStrategyIntent | UpdateQuotaIntent;
|
|
563
|
+
export type StartIntent = AddCollateralIntent | WithdrawAssetIntent | BorrowAndWithdrawIntent | AdjustLeverageIntent | DepositStrategyIntent | RepayStrategyIntent | WithdrawStrategyIntent | UpdateQuotaIntent;
|
|
556
564
|
/**
|
|
557
565
|
* The intents that can be started as a redemption rather than a swap: the two
|
|
558
566
|
* that sell a position asset. The others buy one, and buying settles at once.
|
|
@@ -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, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
8
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowAndWithdrawParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowAndWithdrawOptions, 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, 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 };
|
|
48
|
+
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, BorrowAndWithdrawParams, 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, MaxBorrowAndWithdrawOptions, 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 };
|
|
@@ -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, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
17
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowAndWithdrawParams, BorrowParams, BorrowResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowAndWithdrawOptions, 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
|
|
@@ -106,9 +106,13 @@ export declare class PrepareApi extends MultichainConstruct implements IOpportun
|
|
|
106
106
|
* {@inheritDoc IOpportunitiesPrepare.addCollateral}
|
|
107
107
|
**/
|
|
108
108
|
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError & WithPartialState<OperationState>>>;
|
|
109
|
+
/** {@inheritDoc IOpportunitiesPrepare.maxBorrowAndWithdraw} */
|
|
110
|
+
maxBorrowAndWithdraw(position: PositionInput, options?: MaxBorrowAndWithdrawOptions): Promise<bigint>;
|
|
109
111
|
/**
|
|
110
|
-
* {@inheritDoc IOpportunitiesPrepare.
|
|
112
|
+
* {@inheritDoc IOpportunitiesPrepare.borrowAndWithdraw}
|
|
111
113
|
**/
|
|
114
|
+
borrowAndWithdraw(position: PositionInput, params: BorrowAndWithdrawParams): Promise<SDKReturn<StrategyResult, (AccountFlowError | DebtOutOfRangeError | InsufficientPoolLiquidityError) & WithPartialState<OperationState>>>;
|
|
115
|
+
/** {@inheritDoc IOpportunitiesPrepare.withdrawCollateral} */
|
|
112
116
|
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError & WithPartialState<OperationState>>>;
|
|
113
117
|
/**
|
|
114
118
|
* {@inheritDoc IOpportunitiesPrepare.updateQuota}
|
|
@@ -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, QuotaBufferState, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, UpdateQuotaParams, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
7
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowAndWithdrawParams, BorrowParams, BorrowResult, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowAndWithdrawOptions, 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, 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 };
|
|
9
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, BorrowAndWithdrawParams, BorrowParams, BorrowResult, type BorrowState, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, EmptyCreditAccountResult, type ExecutionCost, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, MaxBorrowAndWithdrawOptions, 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 };
|
|
@@ -31,6 +31,12 @@ export interface QuotaBufferState {
|
|
|
31
31
|
/** Positive increase available under the pool and account limits. */
|
|
32
32
|
quotaIncrease: bigint;
|
|
33
33
|
}
|
|
34
|
+
export interface MaxBorrowAndWithdrawOptions {
|
|
35
|
+
/** Main-price HF threshold, in basis points; defaults to 10101. */
|
|
36
|
+
targetHF?: bigint;
|
|
37
|
+
/** Safe-price HF threshold, in basis points; defaults to 10001. */
|
|
38
|
+
targetSafeHF?: bigint;
|
|
39
|
+
}
|
|
34
40
|
export interface MaxWithdrawCollateralOptions {
|
|
35
41
|
/** Main-price HF threshold, in basis points; defaults to 10101. */
|
|
36
42
|
targetHF?: bigint;
|
|
@@ -385,6 +391,12 @@ export interface AddCollateralParams extends PrepareOptions {
|
|
|
385
391
|
/** Native value to attach when paying a wrapped-native market in the coin. */
|
|
386
392
|
value?: bigint;
|
|
387
393
|
}
|
|
394
|
+
export interface BorrowAndWithdrawParams {
|
|
395
|
+
/** Wallet receiving the tokens. */
|
|
396
|
+
to: Address;
|
|
397
|
+
/** Exact payout in the underlying, or the asset behind an RWA wrapper. */
|
|
398
|
+
amount: bigint;
|
|
399
|
+
}
|
|
388
400
|
export interface WithdrawCollateralParams extends PrepareOptions {
|
|
389
401
|
/** Token to move out; must already sit on the account. */
|
|
390
402
|
token: Address;
|
|
@@ -750,6 +762,14 @@ export interface IOpportunitiesPrepare {
|
|
|
750
762
|
* leverage and raises the health factor.
|
|
751
763
|
**/
|
|
752
764
|
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<SDKReturn<StrategyResult, AccountFlowError & WithPartialState<OperationState>>>;
|
|
765
|
+
/** Maximum additional loan paid out without changing existing balances or quotas.
|
|
766
|
+
* Returns payout token units; zero when no amount can be borrowed.
|
|
767
|
+
*/
|
|
768
|
+
maxBorrowAndWithdraw(position: PositionInput, options?: MaxBorrowAndWithdrawOptions): Promise<bigint>;
|
|
769
|
+
/** Increase existing debt and pay the exact amount to the supplied recipient.
|
|
770
|
+
* Ordinary markets pay underlying; RWA markets unwrap into its asset.
|
|
771
|
+
*/
|
|
772
|
+
borrowAndWithdraw(position: PositionInput, params: BorrowAndWithdrawParams): Promise<SDKReturn<StrategyResult, (AccountFlowError | DebtOutOfRangeError | InsufficientPoolLiquidityError) & WithPartialState<OperationState>>>;
|
|
753
773
|
/**
|
|
754
774
|
* Moving one asset that already sits on the account out to the wallet, at
|
|
755
775
|
* fixed debt — so TVL falls and leverage rises.
|