@gearbox-protocol/sdk 16.0.0-next.17 → 16.0.0-next.19
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/common-utils/index.js +3 -21
- package/dist/cjs/common-utils/test-utils/index.js +4 -3
- package/dist/cjs/common-utils/utils/index.js +3 -22
- package/dist/cjs/common-utils/utils/strategies/index.js +3 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
- package/dist/cjs/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +135 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
- package/dist/cjs/common-utils/utils/strategies/strategy-info/index.js +3 -0
- package/dist/cjs/onchain/accounts/index.js +2 -3
- package/dist/cjs/onchain/accounts/intents/guards.js +55 -50
- package/dist/cjs/onchain/accounts/intents/index.js +24 -16
- package/dist/cjs/onchain/accounts/intents/leverage-band.js +2 -2
- package/dist/cjs/onchain/accounts/intents/math.js +15 -22
- package/dist/cjs/onchain/accounts/intents/open-strategy.js +5 -5
- package/dist/cjs/onchain/accounts/intents/plan.js +27 -41
- package/dist/cjs/onchain/accounts/intents/realize.js +14 -21
- package/dist/cjs/onchain/accounts/intents/tail.js +2 -2
- package/dist/cjs/onchain/accounts/intents/testing/sdk-mock.js +2 -1
- package/dist/cjs/onchain/accounts/intents/view.js +1 -0
- package/dist/cjs/onchain/constants/index.js +1 -0
- package/dist/cjs/onchain/constants/math.js +11 -0
- package/dist/cjs/onchain/index.js +32 -3
- package/dist/cjs/onchain/market/credit/CreditManagerV310Contract.js +2 -2
- package/dist/cjs/onchain/market/math.js +23 -11
- package/dist/cjs/onchain/validation/checks.js +250 -0
- package/dist/cjs/onchain/validation/index.js +29 -0
- package/dist/cjs/onchain/{accounts/intents → validation}/refusal.js +12 -1
- package/dist/cjs/onchain/validation/token.js +29 -0
- package/dist/cjs/preview/index.js +10 -0
- package/dist/cjs/preview/preview/buildDelayedPreview.js +1 -0
- package/dist/cjs/preview/preview/previewAdjustCreditAccount.js +1 -0
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +1 -0
- package/dist/cjs/preview/validate/checkOperation.js +173 -0
- package/dist/cjs/preview/validate/checkSimulation.js +52 -0
- package/dist/cjs/preview/validate/index.js +6 -0
- package/dist/cjs/sdk/index.js +4 -0
- package/dist/cjs/sdk/prepare/PrepareApi.js +23 -17
- package/dist/cjs/sdk/prepare/index.js +4 -0
- package/dist/cjs/sdk/prepare/types.js +4 -0
- package/dist/esm/common-utils/index.js +2 -11
- package/dist/esm/common-utils/test-utils/index.js +4 -3
- package/dist/esm/common-utils/utils/index.js +2 -12
- package/dist/esm/common-utils/utils/strategies/index.js +2 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +5 -5
- package/dist/esm/common-utils/utils/strategies/strategy-info/credit-manager-issues.js +133 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.js +12 -23
- package/dist/esm/common-utils/utils/strategies/strategy-info/index.js +2 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +2 -2
- package/dist/esm/onchain/accounts/intents/guards.js +55 -50
- package/dist/esm/onchain/accounts/intents/index.js +23 -14
- package/dist/esm/onchain/accounts/intents/leverage-band.js +2 -2
- package/dist/esm/onchain/accounts/intents/math.js +14 -21
- package/dist/esm/onchain/accounts/intents/open-strategy.js +4 -4
- package/dist/esm/onchain/accounts/intents/plan.js +15 -29
- package/dist/esm/onchain/accounts/intents/realize.js +12 -19
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/intents/testing/sdk-mock.js +2 -1
- package/dist/esm/onchain/accounts/intents/view.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/chain/detectNetwork.js +1 -1
- package/dist/esm/onchain/constants/index.js +2 -2
- package/dist/esm/onchain/constants/math.js +11 -1
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +7 -3
- 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/credit/CreditManagerV310Contract.js +2 -2
- package/dist/esm/onchain/market/math.js +23 -11
- package/dist/esm/onchain/market/pool/PoolV310Contract.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/pools/PoolService.js +1 -1
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks.js +230 -0
- package/dist/esm/onchain/validation/index.js +4 -0
- package/dist/esm/onchain/{accounts/intents → validation}/refusal.js +12 -2
- package/dist/esm/onchain/validation/token.js +27 -0
- package/dist/esm/preview/index.js +5 -1
- package/dist/esm/preview/preview/buildDelayedPreview.js +1 -0
- package/dist/esm/preview/preview/previewAdjustCreditAccount.js +1 -0
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +1 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/preview/validate/checkOperation.js +171 -0
- package/dist/esm/preview/validate/checkSimulation.js +51 -0
- package/dist/esm/preview/validate/index.js +3 -0
- package/dist/esm/sdk/index.js +2 -1
- package/dist/esm/sdk/prepare/PrepareApi.js +21 -15
- package/dist/esm/sdk/prepare/index.js +2 -1
- package/dist/esm/sdk/prepare/types.js +2 -1
- package/dist/types/common-utils/index.d.ts +2 -12
- package/dist/types/common-utils/utils/index.d.ts +2 -13
- package/dist/types/common-utils/utils/strategies/index.d.ts +2 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/credit-manager-issues.d.ts +34 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/index.d.ts +2 -1
- package/dist/types/model/previews.d.ts +22 -0
- package/dist/types/onchain/accounts/index.d.ts +2 -2
- package/dist/types/onchain/accounts/intents/guards.d.ts +8 -4
- package/dist/types/onchain/accounts/intents/index.d.ts +20 -10
- package/dist/types/onchain/accounts/intents/leverage-band.d.ts +7 -2
- package/dist/types/onchain/accounts/intents/math.d.ts +2 -1
- package/dist/types/onchain/accounts/intents/plan.d.ts +3 -0
- package/dist/types/onchain/accounts/intents/types.d.ts +7 -1
- package/dist/types/onchain/constants/index.d.ts +2 -2
- package/dist/types/onchain/constants/math.d.ts +9 -1
- package/dist/types/onchain/index.d.ts +7 -3
- package/dist/types/onchain/market/credit/CreditManagerV310Contract.d.ts +1 -1
- package/dist/types/onchain/market/credit/types.d.ts +4 -3
- package/dist/types/onchain/market/math.d.ts +20 -9
- package/dist/types/onchain/validation/checks.d.ts +167 -0
- package/dist/types/onchain/validation/index.d.ts +4 -0
- package/dist/types/onchain/{accounts/intents → validation}/refusal.d.ts +100 -31
- package/dist/types/onchain/validation/token.d.ts +17 -0
- package/dist/types/preview/index.d.ts +5 -1
- package/dist/types/preview/validate/checkOperation.d.ts +46 -0
- package/dist/types/preview/validate/checkSimulation.d.ts +34 -0
- package/dist/types/preview/validate/index.d.ts +3 -0
- package/dist/types/sdk/index.d.ts +2 -2
- package/dist/types/sdk/prepare/PrepareApi.d.ts +3 -3
- package/dist/types/sdk/prepare/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +8 -4
- package/package.json +1 -1
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -267
- package/dist/cjs/common-utils/utils/validation/index.js +0 -23
- package/dist/cjs/common-utils/utils/validation/is-zero-balance.js +0 -7
- package/dist/cjs/common-utils/utils/validation/validate-balance.js +0 -22
- package/dist/cjs/common-utils/utils/validation/validate-balance.spec.js +0 -54
- package/dist/cjs/common-utils/utils/validation/validate-balances.js +0 -17
- package/dist/cjs/common-utils/utils/validation/validate-balances.spec.js +0 -45
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.js +0 -8
- package/dist/cjs/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
- package/dist/cjs/common-utils/utils/validation/validate-hf.js +0 -10
- package/dist/cjs/common-utils/utils/validation/validate-hf.spec.js +0 -26
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -14
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.js +0 -37
- package/dist/cjs/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
- package/dist/cjs/common-utils/utils/validation/validate-open-account.js +0 -18
- package/dist/cjs/common-utils/utils/validation/validate-open-account.spec.js +0 -56
- package/dist/cjs/common-utils/utils/validation/validate-quota.js +0 -23
- package/dist/cjs/common-utils/utils/validation/validate-quota.spec.js +0 -88
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.js +0 -18
- package/dist/cjs/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
- package/dist/cjs/common-utils/utils/validation/validation-types.js +0 -1
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.js +0 -264
- package/dist/esm/common-utils/utils/validation/index.js +0 -12
- package/dist/esm/common-utils/utils/validation/is-zero-balance.js +0 -6
- package/dist/esm/common-utils/utils/validation/validate-balance.js +0 -21
- package/dist/esm/common-utils/utils/validation/validate-balance.spec.js +0 -54
- package/dist/esm/common-utils/utils/validation/validate-balances.js +0 -16
- package/dist/esm/common-utils/utils/validation/validate-balances.spec.js +0 -45
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.js +0 -7
- package/dist/esm/common-utils/utils/validation/validate-credit-manager.spec.js +0 -36
- package/dist/esm/common-utils/utils/validation/validate-hf.js +0 -8
- package/dist/esm/common-utils/utils/validation/validate-hf.spec.js +0 -26
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.js +0 -13
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.js +0 -29
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.js +0 -36
- package/dist/esm/common-utils/utils/validation/validate-open-account-pool-status.spec.js +0 -98
- package/dist/esm/common-utils/utils/validation/validate-open-account.js +0 -17
- package/dist/esm/common-utils/utils/validation/validate-open-account.spec.js +0 -56
- package/dist/esm/common-utils/utils/validation/validate-quota.js +0 -22
- package/dist/esm/common-utils/utils/validation/validate-quota.spec.js +0 -88
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.js +0 -17
- package/dist/esm/common-utils/utils/validation/validate-token-to-obtain.spec.js +0 -36
- package/dist/esm/common-utils/utils/validation/validation-types.js +0 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/index.d.ts +0 -12
- package/dist/types/common-utils/utils/validation/is-zero-balance.d.ts +0 -4
- package/dist/types/common-utils/utils/validation/validate-balance.d.ts +0 -25
- package/dist/types/common-utils/utils/validation/validate-balance.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-balances.d.ts +0 -13
- package/dist/types/common-utils/utils/validation/validate-balances.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-credit-manager.d.ts +0 -13
- package/dist/types/common-utils/utils/validation/validate-credit-manager.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-hf.d.ts +0 -12
- package/dist/types/common-utils/utils/validation/validate-hf.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.d.ts +0 -10
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-quota-status.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.d.ts +0 -26
- package/dist/types/common-utils/utils/validation/validate-open-account-pool-status.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +0 -25
- package/dist/types/common-utils/utils/validation/validate-open-account.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +0 -24
- package/dist/types/common-utils/utils/validation/validate-quota.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.d.ts +0 -17
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.spec.d.ts +0 -1
- package/dist/types/common-utils/utils/validation/validation-types.d.ts +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_onchain_validation_refusal = require("../../validation/refusal.js");
|
|
3
3
|
const require_onchain_accounts_intents_utils_router_path = require("./utils/router-path.js");
|
|
4
4
|
const require_onchain_accounts_intents_plan = require("./plan.js");
|
|
5
5
|
const require_onchain_accounts_intents_operations = require("./operations.js");
|
|
@@ -18,7 +18,7 @@ function planTail(args) {
|
|
|
18
18
|
const { intent, claimable, view } = args;
|
|
19
19
|
const claimed = () => {
|
|
20
20
|
const output = require_onchain_accounts_intents_operations.instantOutput(claimable.outputs);
|
|
21
|
-
if (!output) throw new
|
|
21
|
+
if (!output) throw new require_onchain_validation_refusal.IntentPreviewError("insufficientSourceBalance", void 0, "finishIntent: the claim credits nothing to spend");
|
|
22
22
|
return output;
|
|
23
23
|
};
|
|
24
24
|
switch (intent.type) {
|
|
@@ -182,7 +182,7 @@ function buildMockSdk(args) {
|
|
|
182
182
|
liquidationThresholds,
|
|
183
183
|
collateralTokens,
|
|
184
184
|
feeInterest: args.feeInterest ?? 0,
|
|
185
|
-
maxLeverage: (collateral) => require_onchain_market_math.calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0)
|
|
185
|
+
maxLeverage: (collateral, targetHF) => require_onchain_market_math.calcMaxLeverage(liquidationThresholds.get(collateral) ?? 0, targetHF)
|
|
186
186
|
},
|
|
187
187
|
creditFacade: {
|
|
188
188
|
address: args.creditFacade,
|
|
@@ -297,6 +297,7 @@ function buildMockSdk(args) {
|
|
|
297
297
|
decimals: decimalsOf(token),
|
|
298
298
|
contractType: phantoms.has(token.toLowerCase()) ? "PHANTOM_TOKEN::SECURITIZE_RD" : void 0
|
|
299
299
|
}),
|
|
300
|
+
getToken: tokenOf,
|
|
300
301
|
mustGetToken: tokenOf,
|
|
301
302
|
rwaUnderlyings: { get: (token) => {
|
|
302
303
|
const asset = args.rwaAssets?.[token.toLowerCase()];
|
|
@@ -18,6 +18,7 @@ function accountView(creditAccount, sdk) {
|
|
|
18
18
|
for (const t of creditAccount.tokens) totalValue += price(t.token, underlying, t.balance);
|
|
19
19
|
return {
|
|
20
20
|
underlying,
|
|
21
|
+
sdk,
|
|
21
22
|
rwaAsset: sdk.tokensMeta.rwaUnderlyings.get(underlying)?.asset,
|
|
22
23
|
debt: creditAccount.accountDebt,
|
|
23
24
|
collateral: totalValue - creditAccount.accountDebt,
|
|
@@ -72,3 +72,4 @@ exports.botPermissionsToString = require_onchain_constants_bot_permissions.botPe
|
|
|
72
72
|
exports.halfRAY = require_onchain_constants_math.halfRAY;
|
|
73
73
|
exports.isV310 = require_onchain_constants_versions.isV310;
|
|
74
74
|
exports.isVersionRange = require_onchain_constants_versions.isVersionRange;
|
|
75
|
+
exports.isZeroBalance = require_onchain_constants_math.isZeroBalance;
|
|
@@ -21,6 +21,16 @@ const SLIPPAGE_DECIMALS = 100n;
|
|
|
21
21
|
* Token balances at or below this threshold are treated as dust and ignored.
|
|
22
22
|
**/
|
|
23
23
|
const DUST_THRESHOLD = 10n;
|
|
24
|
+
/**
|
|
25
|
+
* Whether a balance is nothing worth acting on.
|
|
26
|
+
*
|
|
27
|
+
* The threshold is a dust floor, not a zero test: rounding leaves amounts that
|
|
28
|
+
* are technically non-zero and worthless, and a form that offered to spend one
|
|
29
|
+
* would build a transaction nobody wants.
|
|
30
|
+
*/
|
|
31
|
+
function isZeroBalance(balance) {
|
|
32
|
+
return (balance ?? 0n) <= DUST_THRESHOLD;
|
|
33
|
+
}
|
|
24
34
|
//#endregion
|
|
25
35
|
exports.DUST_THRESHOLD = DUST_THRESHOLD;
|
|
26
36
|
exports.LEVERAGE_DECIMALS = LEVERAGE_DECIMALS;
|
|
@@ -40,3 +50,4 @@ exports.SLIPPAGE_DECIMALS = SLIPPAGE_DECIMALS;
|
|
|
40
50
|
exports.WAD = WAD;
|
|
41
51
|
exports.WAD_DECIMALS_POW = WAD_DECIMALS_POW;
|
|
42
52
|
exports.halfRAY = halfRAY;
|
|
53
|
+
exports.isZeroBalance = isZeroBalance;
|
|
@@ -193,7 +193,10 @@ require("./market/index.js");
|
|
|
193
193
|
const require_onchain_accounts_credit_account_compressor_CreditAccountCompressorV310Contract = require("./accounts/credit-account-compressor/CreditAccountCompressorV310Contract.js");
|
|
194
194
|
const require_onchain_accounts_credit_account_compressor_CreditAccountCompressor = require("./accounts/credit-account-compressor/CreditAccountCompressor.js");
|
|
195
195
|
const require_onchain_accounts_CreditAccountsServiceV310 = require("./accounts/CreditAccountsServiceV310.js");
|
|
196
|
-
const
|
|
196
|
+
const require_onchain_validation_checks = require("./validation/checks.js");
|
|
197
|
+
const require_onchain_validation_refusal = require("./validation/refusal.js");
|
|
198
|
+
const require_onchain_validation_token = require("./validation/token.js");
|
|
199
|
+
const require_onchain_accounts_intents_guards = require("./accounts/intents/guards.js");
|
|
197
200
|
const require_onchain_accounts_intents_utils_credit_account_slice = require("./accounts/intents/utils/credit-account-slice.js");
|
|
198
201
|
const require_onchain_accounts_intents_index = require("./accounts/intents/index.js");
|
|
199
202
|
const require_onchain_accounts_liquidations_constants = require("./accounts/liquidations/constants.js");
|
|
@@ -239,6 +242,7 @@ const require_onchain_OnchainSDK = require("./OnchainSDK.js");
|
|
|
239
242
|
const require_onchain_MultichainSDK = require("./MultichainSDK.js");
|
|
240
243
|
const require_onchain_options = require("./options.js");
|
|
241
244
|
require("./types/index.js");
|
|
245
|
+
require("./validation/index.js");
|
|
242
246
|
exports.ADDRESS_0X0 = require_onchain_constants_addresses.ADDRESS_0X0;
|
|
243
247
|
exports.ADDRESS_PROVIDER_V310 = require_onchain_constants_address_provider.ADDRESS_PROVIDER_V310;
|
|
244
248
|
exports.AP_ACCOUNT_FACTORY = require_onchain_constants_address_provider.AP_ACCOUNT_FACTORY;
|
|
@@ -337,7 +341,7 @@ exports.IERC20ZapperContract = require_onchain_market_zapper_IERC20ZapperContrac
|
|
|
337
341
|
exports.IETHZapperContract = require_onchain_market_zapper_IETHZapperContract.IETHZapperContract;
|
|
338
342
|
exports.InfinifiGatewayAdapterContract = require_onchain_market_adapters_contracts_InfinifiGatewayAdapterContract.InfinifiGatewayAdapterContract;
|
|
339
343
|
exports.InfinifiUnwindingGatewayAdapterContract = require_onchain_market_adapters_contracts_InfinifiUnwindingGatewayAdapterContract.InfinifiUnwindingGatewayAdapterContract;
|
|
340
|
-
exports.IntentPreviewError =
|
|
344
|
+
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
341
345
|
exports.InvalidDelayedIntentError = require_onchain_accounts_withdrawal_compressor_errors.InvalidDelayedIntentError;
|
|
342
346
|
exports.KelpLRTDepositPoolAdapterContract = require_onchain_market_adapters_contracts_KelpLRTDepositPoolAdapterContract.KelpLRTDepositPoolAdapterContract;
|
|
343
347
|
exports.KelpLRTWithdrawalManagerAdapterContract = require_onchain_market_adapters_contracts_KelpLRTWithdrawalManagerAdapterContract.KelpLRTWithdrawalManagerAdapterContract;
|
|
@@ -351,7 +355,11 @@ exports.MAX_INT = require_onchain_constants_math.MAX_INT;
|
|
|
351
355
|
exports.MAX_LEVERAGE_BUFFER_BPS = require_onchain_market_math.MAX_LEVERAGE_BUFFER_BPS;
|
|
352
356
|
exports.MAX_UINT16 = require_onchain_constants_math.MAX_UINT16;
|
|
353
357
|
exports.MAX_UINT256 = require_onchain_constants_math.MAX_UINT256;
|
|
358
|
+
exports.MIN_HEALTH_FACTOR_FACADE = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FACADE;
|
|
359
|
+
exports.MIN_HEALTH_FACTOR_FORM = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FORM;
|
|
360
|
+
exports.MIN_HF_LIMITED = require_onchain_validation_checks.MIN_HF_LIMITED;
|
|
354
361
|
exports.MIN_INT96 = require_onchain_constants_math.MIN_INT96;
|
|
362
|
+
exports.MIN_SAFE_HEALTH_FACTOR_FORM = require_onchain_validation_checks.MIN_SAFE_HEALTH_FACTOR_FORM;
|
|
355
363
|
exports.MULTICALL_ADDRESS = require_onchain_constants_addresses.MULTICALL_ADDRESS;
|
|
356
364
|
exports.MarketRegister = require_onchain_market_MarketRegister.MarketRegister;
|
|
357
365
|
exports.MarketSuite = require_onchain_market_MarketSuite.MarketSuite;
|
|
@@ -467,8 +475,10 @@ exports.adapterActionSelectors = require_onchain_market_adapters_abi_actionAbi.a
|
|
|
467
475
|
exports.adapterActionSignatures = require_onchain_market_adapters_abi_actionAbi.adapterActionSignatures;
|
|
468
476
|
exports.adapterConstructorAbi = require_onchain_market_adapters_abi_conctructorAbi.adapterConstructorAbi;
|
|
469
477
|
exports.allTransfersAsTokenAmounts = require_onchain_market_adapters_transferHelpers.allTransfersAsTokenAmounts;
|
|
478
|
+
exports.amountOf = require_onchain_validation_checks.amountOf;
|
|
470
479
|
exports.assetsMap = require_onchain_router_helpers.assetsMap;
|
|
471
480
|
exports.attachOptionsSchema = require_onchain_options.attachOptionsSchema;
|
|
481
|
+
exports.borrowable = require_onchain_accounts_intents_guards.borrowable;
|
|
472
482
|
exports.botPermissionsToString = require_onchain_constants_bot_permissions.botPermissionsToString;
|
|
473
483
|
exports.bpsToRay = require_onchain_market_math.bpsToRay;
|
|
474
484
|
exports.bytes32ToString = require_onchain_utils_bytes32ToString.bytes32ToString;
|
|
@@ -486,6 +496,20 @@ exports.calcTimeToLiquidationMs = require_onchain_positions_calcTimeToLiquidatio
|
|
|
486
496
|
exports.calcUtilization = require_onchain_market_math.calcUtilization;
|
|
487
497
|
exports.calcUtilizationRaw = require_onchain_market_math.calcUtilizationRaw;
|
|
488
498
|
exports.chains = require_onchain_chain_chains.chains;
|
|
499
|
+
exports.checkBorrowLimit = require_onchain_validation_checks.checkBorrowLimit;
|
|
500
|
+
exports.checkCollateralised = require_onchain_validation_checks.checkCollateralised;
|
|
501
|
+
exports.checkCreditManagerPaused = require_onchain_validation_checks.checkCreditManagerPaused;
|
|
502
|
+
exports.checkDebtInBand = require_onchain_validation_checks.checkDebtInBand;
|
|
503
|
+
exports.checkForbiddenToken = require_onchain_validation_checks.checkForbiddenToken;
|
|
504
|
+
exports.checkFunding = require_onchain_validation_checks.checkFunding;
|
|
505
|
+
exports.checkLeverageAtLeastOne = require_onchain_validation_checks.checkLeverageAtLeastOne;
|
|
506
|
+
exports.checkMarketExpired = require_onchain_validation_checks.checkMarketExpired;
|
|
507
|
+
exports.checkPoolPaused = require_onchain_validation_checks.checkPoolPaused;
|
|
508
|
+
exports.checkPoolPayout = require_onchain_validation_checks.checkPoolPayout;
|
|
509
|
+
exports.checkPoolSunset = require_onchain_validation_checks.checkPoolSunset;
|
|
510
|
+
exports.checkPreviewError = require_onchain_validation_checks.checkPreviewError;
|
|
511
|
+
exports.checkQuotaCount = require_onchain_validation_checks.checkQuotaCount;
|
|
512
|
+
exports.checkQuotaLimit = require_onchain_validation_checks.checkQuotaLimit;
|
|
489
513
|
exports.childLogger = require_onchain_utils_childLogger.childLogger;
|
|
490
514
|
exports.classifyCurveOperation = require_onchain_market_adapters_transferHelpers.classifyCurveOperation;
|
|
491
515
|
exports.createAdapter = require_onchain_market_adapters_createAdapter.createAdapter;
|
|
@@ -617,6 +641,7 @@ exports.iVelodromeV2RouterAbi = require_onchain_market_adapters_abi_targetContra
|
|
|
617
641
|
exports.iVelodromeV2RouterAdapterAbi = require_onchain_market_adapters_abi_adapters_iVelodromeV2RouterAdapter.iVelodromeV2RouterAdapterAbi;
|
|
618
642
|
exports.isDust = require_onchain_utils_isDust.isDust;
|
|
619
643
|
exports.isLPPriceFeed = require_onchain_market_pricefeeds_AbstractLPPriceFeed.isLPPriceFeed;
|
|
644
|
+
exports.isMalformedPreviewError = require_onchain_validation_checks.isMalformedPreviewError;
|
|
620
645
|
exports.isPublicNetwork = require_onchain_chain_chains.isPublicNetwork;
|
|
621
646
|
exports.isRWAFactory = require_onchain_market_rwa_types.isRWAFactory;
|
|
622
647
|
exports.isRWAToken = require_onchain_chain_chains.isRWAToken;
|
|
@@ -627,6 +652,7 @@ exports.isSupportedNetwork = require_onchain_chain_chains.isSupportedNetwork;
|
|
|
627
652
|
exports.isUpdatablePriceFeed = require_onchain_market_pricefeeds_isUpdatablePriceFeed.isUpdatablePriceFeed;
|
|
628
653
|
exports.isV310 = require_onchain_constants_versions.isV310;
|
|
629
654
|
exports.isVersionRange = require_onchain_constants_versions.isVersionRange;
|
|
655
|
+
exports.isZeroBalance = require_onchain_constants_math.isZeroBalance;
|
|
630
656
|
exports.iwstETHAbi = require_onchain_market_adapters_abi_targetContractAbi.iwstETHAbi;
|
|
631
657
|
exports.iwstEthv1AdapterAbi = require_onchain_market_adapters_abi_adapters_iwstEthv1Adapter.iwstEthv1AdapterAbi;
|
|
632
658
|
exports.json_parse = require_onchain_utils_json.json_parse;
|
|
@@ -643,9 +669,10 @@ exports.parseAdapterDeployParams = require_onchain_market_adapters_abi_utils.par
|
|
|
643
669
|
exports.parsePosNegAmount = require_onchain_market_adapters_transferHelpers.parsePosNegAmount;
|
|
644
670
|
exports.percentFmt = require_onchain_utils_formatter.percentFmt;
|
|
645
671
|
exports.pickStrategyTargetCollateral = require_onchain_market_credit_collateralUtils.pickStrategyTargetCollateral;
|
|
672
|
+
exports.raise = require_onchain_validation_refusal.raise;
|
|
646
673
|
exports.rayToBps = require_onchain_market_math.rayToBps;
|
|
647
674
|
exports.rayToNumber = require_onchain_utils_formatter.rayToNumber;
|
|
648
|
-
exports.refuse =
|
|
675
|
+
exports.refuse = require_onchain_validation_refusal.refuse;
|
|
649
676
|
exports.retry = require_onchain_utils_retry.retry;
|
|
650
677
|
exports.rewardsFromTransfers = require_onchain_market_adapters_transferHelpers.rewardsFromTransfers;
|
|
651
678
|
exports.sendRawTx = require_onchain_utils_viem_sendRawTx.sendRawTx;
|
|
@@ -668,6 +695,8 @@ exports.toRequestableWithdrawal = require_onchain_accounts_withdrawal_compressor
|
|
|
668
695
|
exports.toShares = require_onchain_pools_PoolService.toShares;
|
|
669
696
|
exports.toSharesUp = require_onchain_pools_PoolService.toSharesUp;
|
|
670
697
|
exports.toSignificant = require_onchain_utils_formatter.toSignificant;
|
|
698
|
+
exports.toToken = require_onchain_validation_token.toToken;
|
|
699
|
+
exports.toTokenAmount = require_onchain_validation_token.toTokenAmount;
|
|
671
700
|
exports.toWithdrawalStatus = require_onchain_accounts_withdrawal_compressor_types.toWithdrawalStatus;
|
|
672
701
|
exports.usdToNumber = require_onchain_market_math.usdToNumber;
|
|
673
702
|
exports.watchBlocksAsync = require_onchain_utils_viem_watchBlocksAsync.watchBlocksAsync;
|
|
@@ -66,8 +66,8 @@ var CreditManagerV310Contract = class extends require_onchain_base_BaseContract.
|
|
|
66
66
|
/**
|
|
67
67
|
* {@inheritDoc ICreditManagerContract.maxLeverage}
|
|
68
68
|
*/
|
|
69
|
-
maxLeverage(collateral) {
|
|
70
|
-
return require_onchain_market_math.calcMaxLeverage(this.liquidationThresholds.mustGet(collateral));
|
|
69
|
+
maxLeverage(collateral, targetHF) {
|
|
70
|
+
return require_onchain_market_math.calcMaxLeverage(this.liquidationThresholds.mustGet(collateral), targetHF);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* {@inheritDoc ICreditManagerContract.liquidationPremium}
|
|
@@ -163,24 +163,36 @@ function calcNetStrategyApy(opportunity, totalCollateralApy, leverage, mode = "s
|
|
|
163
163
|
**/
|
|
164
164
|
const MAX_LEVERAGE_BUFFER_BPS = 500;
|
|
165
165
|
/**
|
|
166
|
-
* Highest total-value leverage a liquidation threshold allows, floored
|
|
167
|
-
*
|
|
168
|
-
* `liquidationThreshold × totalValue`, leaving
|
|
169
|
-
* equity per unit of exposure;
|
|
170
|
-
*
|
|
166
|
+
* Highest total-value leverage a liquidation threshold allows, floored.
|
|
167
|
+
*
|
|
168
|
+
* At HF = 1, debt is `liquidationThreshold × totalValue`, leaving
|
|
169
|
+
* `1 − liquidationThreshold` of equity per unit of exposure; a maxed position
|
|
170
|
+
* has to stay some way off that boundary. Given a `targetHF`, that distance is
|
|
171
|
+
* solved for — `HF = liquidationThreshold × L / (L − 1)` inverts to
|
|
172
|
+
* `L = targetHF / (targetHF − liquidationThreshold)`.
|
|
173
|
+
*
|
|
174
|
+
* Without one it falls back on a flat {@link MAX_LEVERAGE_BUFFER_BPS}, which
|
|
175
|
+
* under-buffers as the threshold rises — at 95% it allows 19x, or HF ≈ 1.0028.
|
|
176
|
+
* That branch is scaffolding, kept so this parameter moves no number before
|
|
177
|
+
* the callers name a target, and goes away with the constant.
|
|
178
|
+
*
|
|
179
|
+
* @param targetHF - Health factor the maxed position should leave, in basis
|
|
180
|
+
* points. Omitted keeps the legacy buffer.
|
|
171
181
|
*
|
|
172
182
|
* @example
|
|
173
183
|
* ```ts
|
|
174
184
|
* // liquidationThreshold: 9000 bps = 90%
|
|
175
|
-
* calcMaxLeverage(9000)
|
|
185
|
+
* calcMaxLeverage(9000) // floor((1 − 0.05) / (1 − 0.9)) = 9x
|
|
186
|
+
* calcMaxLeverage(9000, 10100) // floor(1.01 / (1.01 − 0.9)) = 9x
|
|
176
187
|
* ```
|
|
177
|
-
* @throws If `liquidationThreshold` is 100% or more,
|
|
178
|
-
* leverage
|
|
188
|
+
* @throws If `liquidationThreshold` is 100% or more, or reaches a named
|
|
189
|
+
* `targetHF` — either way no leverage clears the bar.
|
|
179
190
|
**/
|
|
180
|
-
function calcMaxLeverage(liquidationThreshold) {
|
|
191
|
+
function calcMaxLeverage(liquidationThreshold, targetHF) {
|
|
181
192
|
if (liquidationThreshold >= FULL) throw new Error("cannot compute max leverage: liquidation threshold is 100% or more");
|
|
182
|
-
|
|
183
|
-
|
|
193
|
+
if (targetHF === void 0) return Math.max(Math.floor((FULL - 500) / (FULL - liquidationThreshold)), 1);
|
|
194
|
+
if (liquidationThreshold >= targetHF) throw new Error("cannot compute max leverage: liquidation threshold reaches the target health factor");
|
|
195
|
+
return Math.max(Math.floor(targetHF / (targetHF - liquidationThreshold)), 1);
|
|
184
196
|
}
|
|
185
197
|
/**
|
|
186
198
|
* Converts a credit account's health factor from the 18-decimal fixed point the
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/onchain/validation/checks.ts
|
|
3
|
+
/**
|
|
4
|
+
* Every verdict the protocol can pass on an operation, as values.
|
|
5
|
+
*
|
|
6
|
+
* Each check is handed the numbers it compares — never a suite, a market or an
|
|
7
|
+
* SDK — so the engine, `checkOperation` and the strategy lists share one
|
|
8
|
+
* implementation.
|
|
9
|
+
*
|
|
10
|
+
* Ladders stay with the caller because they differ deliberately: the engine
|
|
11
|
+
* reports the tightest ceiling it found, the account-opening path the first one
|
|
12
|
+
* exceeded in its own order.
|
|
13
|
+
*/
|
|
14
|
+
/** A factor at or below this is refused; kept for the callers that size on it. */
|
|
15
|
+
const MIN_HF_LIMITED = 10100n;
|
|
16
|
+
/** The same bar as a `required` argument — the lowest factor that passes. */
|
|
17
|
+
const MIN_HEALTH_FACTOR_FORM = 10101;
|
|
18
|
+
/** The bar the facade itself enforces: an account may end exactly at 1.0. */
|
|
19
|
+
const MIN_HEALTH_FACTOR_FACADE = 1e4;
|
|
20
|
+
/**
|
|
21
|
+
* The safe-price bar a form holds an account to. A step above the facade's,
|
|
22
|
+
* because a factor of exactly 1.0 at safe prices is already a refusal.
|
|
23
|
+
*/
|
|
24
|
+
const MIN_SAFE_HEALTH_FACTOR_FORM = 10001;
|
|
25
|
+
/** A refusal names what a limit was measured in, never what it is worth. */
|
|
26
|
+
function amountOf(token, value) {
|
|
27
|
+
return {
|
|
28
|
+
token,
|
|
29
|
+
value,
|
|
30
|
+
valueUsd: null
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The credit manager takes no multicall while it is paused. */
|
|
34
|
+
function checkCreditManagerPaused(args) {
|
|
35
|
+
if (!args.isPaused) return null;
|
|
36
|
+
return {
|
|
37
|
+
reason: "marketPaused",
|
|
38
|
+
detail: { creditManager: args.creditManager }
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Past its expiration date the facade takes no more multicalls. */
|
|
42
|
+
function checkMarketExpired(args) {
|
|
43
|
+
if (!args.isExpired) return null;
|
|
44
|
+
return {
|
|
45
|
+
reason: "marketExpired",
|
|
46
|
+
detail: {
|
|
47
|
+
creditManager: args.creditManager,
|
|
48
|
+
expirationDate: args.expirationDate
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** A paused pool neither takes deposits nor pays out. */
|
|
53
|
+
function checkPoolPaused(args) {
|
|
54
|
+
return args.isPaused ? {
|
|
55
|
+
reason: "marketPaused",
|
|
56
|
+
detail: { pool: args.pool }
|
|
57
|
+
} : null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A pool winding down still pays out, so only what puts money in is refused.
|
|
61
|
+
*/
|
|
62
|
+
function checkPoolSunset(args) {
|
|
63
|
+
return args.isSunset && args.isDeposit ? {
|
|
64
|
+
reason: "poolSunset",
|
|
65
|
+
detail: { pool: args.pool }
|
|
66
|
+
} : null;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* What the pool will hand over, against what is asked for.
|
|
70
|
+
*
|
|
71
|
+
* `binding` and `available` are the caller's answer to "which ceiling stands in
|
|
72
|
+
* the way", not this check's: see the ladder note above. `solutionAmount` is
|
|
73
|
+
* the largest position still openable, left out when none is.
|
|
74
|
+
*/
|
|
75
|
+
function checkBorrowLimit(args) {
|
|
76
|
+
if (args.requested <= args.available) return null;
|
|
77
|
+
return {
|
|
78
|
+
reason: "insufficientPoolLiquidity",
|
|
79
|
+
detail: {
|
|
80
|
+
requested: amountOf(args.underlying, args.requested),
|
|
81
|
+
available: amountOf(args.underlying, args.available),
|
|
82
|
+
binding: args.binding,
|
|
83
|
+
...args.solutionAmount === void 0 ? {} : { solutionAmount: amountOf(args.underlying, args.solutionAmount) }
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* What the pool can pay out, against what is being taken out.
|
|
89
|
+
*
|
|
90
|
+
* The operator is not `checkBorrowLimit`'s: a pool holding exactly the amount
|
|
91
|
+
* asked for still cannot serve it, so equality is already a refusal. That is
|
|
92
|
+
* the rule the legacy withdrawal validator enforced and it is preserved to the
|
|
93
|
+
* unit.
|
|
94
|
+
*/
|
|
95
|
+
function checkPoolPayout(args) {
|
|
96
|
+
if (args.requested < args.available) return null;
|
|
97
|
+
return {
|
|
98
|
+
reason: "insufficientPoolLiquidity",
|
|
99
|
+
detail: {
|
|
100
|
+
requested: amountOf(args.underlying, args.requested),
|
|
101
|
+
available: amountOf(args.underlying, args.available),
|
|
102
|
+
binding: "poolAvailableLiquidity"
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A debt the facade would revert on.
|
|
108
|
+
*
|
|
109
|
+
* `allowZero` is the one place the two callers genuinely disagree: an account
|
|
110
|
+
* being adjusted may end owing nothing, while one being opened may not — so the
|
|
111
|
+
* exemption is stated rather than assumed.
|
|
112
|
+
*/
|
|
113
|
+
function checkDebtInBand(args) {
|
|
114
|
+
const { debt, minDebt, maxDebt, underlying, allowZero } = args;
|
|
115
|
+
if (!(debt > maxDebt || debt < minDebt && !(allowZero && debt === 0n))) return null;
|
|
116
|
+
return {
|
|
117
|
+
reason: "debtOutOfRange",
|
|
118
|
+
detail: {
|
|
119
|
+
requested: amountOf(underlying, debt),
|
|
120
|
+
minDebt: amountOf(underlying, minDebt),
|
|
121
|
+
maxDebt: amountOf(underlying, maxDebt)
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Leverage below 1x is not a position, it is a withdrawal. */
|
|
126
|
+
function checkLeverageAtLeastOne(args) {
|
|
127
|
+
return args.leverage < args.min ? {
|
|
128
|
+
reason: "leverageOutOfRange",
|
|
129
|
+
detail: {
|
|
130
|
+
requested: args.leverage,
|
|
131
|
+
min: args.min
|
|
132
|
+
}
|
|
133
|
+
} : null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The account against its debt, at whichever bar the caller holds it to.
|
|
137
|
+
*
|
|
138
|
+
* An unread factor counts as failing: a check that cannot see the number is not
|
|
139
|
+
* evidence that the number is fine.
|
|
140
|
+
*/
|
|
141
|
+
function checkCollateralised(args) {
|
|
142
|
+
const { healthFactor, required, safePrices, improvesFrom } = args;
|
|
143
|
+
if (healthFactor === void 0) return {
|
|
144
|
+
reason: "insufficientCollateral",
|
|
145
|
+
detail: {
|
|
146
|
+
healthFactor: 0,
|
|
147
|
+
required,
|
|
148
|
+
safePrices
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
if (healthFactor >= required || improvesFrom !== void 0 && healthFactor > improvesFrom) return null;
|
|
152
|
+
return {
|
|
153
|
+
reason: "insufficientCollateral",
|
|
154
|
+
detail: {
|
|
155
|
+
healthFactor,
|
|
156
|
+
required,
|
|
157
|
+
safePrices
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** A token the market will not let the account hold. */
|
|
162
|
+
function checkForbiddenToken(args) {
|
|
163
|
+
return args.isForbidden ? {
|
|
164
|
+
reason: "forbiddenToken",
|
|
165
|
+
detail: { token: args.token }
|
|
166
|
+
} : null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The room the keeper still has for a token's quota, in the underlying.
|
|
170
|
+
*
|
|
171
|
+
* `requested` is absent for a token the market opened no quota for at all —
|
|
172
|
+
* nothing was weighed against a limit, the token simply counts as no collateral.
|
|
173
|
+
*/
|
|
174
|
+
function checkQuotaLimit(args) {
|
|
175
|
+
const { token, requested, available, underlying } = args;
|
|
176
|
+
if (requested !== void 0 && requested <= available) return null;
|
|
177
|
+
return {
|
|
178
|
+
reason: "quotaLimitReached",
|
|
179
|
+
detail: {
|
|
180
|
+
token,
|
|
181
|
+
requested: requested === void 0 ? void 0 : amountOf(underlying, requested),
|
|
182
|
+
available: amountOf(underlying, available)
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** How many quoted tokens the facade enables at once. */
|
|
187
|
+
function checkQuotaCount(args) {
|
|
188
|
+
return args.count > args.max ? {
|
|
189
|
+
reason: "quotaCountExceeded",
|
|
190
|
+
detail: {
|
|
191
|
+
count: args.count,
|
|
192
|
+
max: args.max
|
|
193
|
+
}
|
|
194
|
+
} : null;
|
|
195
|
+
}
|
|
196
|
+
/** What the operation is funded from, against what is there. */
|
|
197
|
+
function checkFunding(args) {
|
|
198
|
+
const { token, required, held } = args;
|
|
199
|
+
if (required <= held) return null;
|
|
200
|
+
return {
|
|
201
|
+
reason: "insufficientSourceBalance",
|
|
202
|
+
detail: {
|
|
203
|
+
required: amountOf(token, required),
|
|
204
|
+
held: amountOf(token, held)
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* The SDK could not replay the transaction.
|
|
210
|
+
*
|
|
211
|
+
* Only the 1xxx class lands here. A 2xxx error says the transaction is fine and
|
|
212
|
+
* the SDK could not fully evaluate it, which is a caveat on the numbers rather
|
|
213
|
+
* than a reason to refuse — it stays on the preview for the caller to surface.
|
|
214
|
+
*/
|
|
215
|
+
function checkPreviewError(error) {
|
|
216
|
+
if (!error || !isMalformedPreviewError(error)) return null;
|
|
217
|
+
return {
|
|
218
|
+
reason: "malformedTransaction",
|
|
219
|
+
detail: error
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The class boundary the preview error codes are written against: 1xxx means
|
|
224
|
+
* the transaction itself is malformed, 2xxx that only the evaluation was
|
|
225
|
+
* incomplete. A range, so a future 1007 classifies itself.
|
|
226
|
+
*/
|
|
227
|
+
function isMalformedPreviewError(error) {
|
|
228
|
+
return error.code >= 1e3 && error.code < 2e3;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
exports.MIN_HEALTH_FACTOR_FACADE = MIN_HEALTH_FACTOR_FACADE;
|
|
232
|
+
exports.MIN_HEALTH_FACTOR_FORM = MIN_HEALTH_FACTOR_FORM;
|
|
233
|
+
exports.MIN_HF_LIMITED = MIN_HF_LIMITED;
|
|
234
|
+
exports.MIN_SAFE_HEALTH_FACTOR_FORM = MIN_SAFE_HEALTH_FACTOR_FORM;
|
|
235
|
+
exports.amountOf = amountOf;
|
|
236
|
+
exports.checkBorrowLimit = checkBorrowLimit;
|
|
237
|
+
exports.checkCollateralised = checkCollateralised;
|
|
238
|
+
exports.checkCreditManagerPaused = checkCreditManagerPaused;
|
|
239
|
+
exports.checkDebtInBand = checkDebtInBand;
|
|
240
|
+
exports.checkForbiddenToken = checkForbiddenToken;
|
|
241
|
+
exports.checkFunding = checkFunding;
|
|
242
|
+
exports.checkLeverageAtLeastOne = checkLeverageAtLeastOne;
|
|
243
|
+
exports.checkMarketExpired = checkMarketExpired;
|
|
244
|
+
exports.checkPoolPaused = checkPoolPaused;
|
|
245
|
+
exports.checkPoolPayout = checkPoolPayout;
|
|
246
|
+
exports.checkPoolSunset = checkPoolSunset;
|
|
247
|
+
exports.checkPreviewError = checkPreviewError;
|
|
248
|
+
exports.checkQuotaCount = checkQuotaCount;
|
|
249
|
+
exports.checkQuotaLimit = checkQuotaLimit;
|
|
250
|
+
exports.isMalformedPreviewError = isMalformedPreviewError;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_validation_checks = require("./checks.js");
|
|
3
|
+
const require_onchain_validation_refusal = require("./refusal.js");
|
|
4
|
+
const require_onchain_validation_token = require("./token.js");
|
|
5
|
+
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
6
|
+
exports.MIN_HEALTH_FACTOR_FACADE = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FACADE;
|
|
7
|
+
exports.MIN_HEALTH_FACTOR_FORM = require_onchain_validation_checks.MIN_HEALTH_FACTOR_FORM;
|
|
8
|
+
exports.MIN_HF_LIMITED = require_onchain_validation_checks.MIN_HF_LIMITED;
|
|
9
|
+
exports.MIN_SAFE_HEALTH_FACTOR_FORM = require_onchain_validation_checks.MIN_SAFE_HEALTH_FACTOR_FORM;
|
|
10
|
+
exports.amountOf = require_onchain_validation_checks.amountOf;
|
|
11
|
+
exports.checkBorrowLimit = require_onchain_validation_checks.checkBorrowLimit;
|
|
12
|
+
exports.checkCollateralised = require_onchain_validation_checks.checkCollateralised;
|
|
13
|
+
exports.checkCreditManagerPaused = require_onchain_validation_checks.checkCreditManagerPaused;
|
|
14
|
+
exports.checkDebtInBand = require_onchain_validation_checks.checkDebtInBand;
|
|
15
|
+
exports.checkForbiddenToken = require_onchain_validation_checks.checkForbiddenToken;
|
|
16
|
+
exports.checkFunding = require_onchain_validation_checks.checkFunding;
|
|
17
|
+
exports.checkLeverageAtLeastOne = require_onchain_validation_checks.checkLeverageAtLeastOne;
|
|
18
|
+
exports.checkMarketExpired = require_onchain_validation_checks.checkMarketExpired;
|
|
19
|
+
exports.checkPoolPaused = require_onchain_validation_checks.checkPoolPaused;
|
|
20
|
+
exports.checkPoolPayout = require_onchain_validation_checks.checkPoolPayout;
|
|
21
|
+
exports.checkPoolSunset = require_onchain_validation_checks.checkPoolSunset;
|
|
22
|
+
exports.checkPreviewError = require_onchain_validation_checks.checkPreviewError;
|
|
23
|
+
exports.checkQuotaCount = require_onchain_validation_checks.checkQuotaCount;
|
|
24
|
+
exports.checkQuotaLimit = require_onchain_validation_checks.checkQuotaLimit;
|
|
25
|
+
exports.isMalformedPreviewError = require_onchain_validation_checks.isMalformedPreviewError;
|
|
26
|
+
exports.raise = require_onchain_validation_refusal.raise;
|
|
27
|
+
exports.refuse = require_onchain_validation_refusal.refuse;
|
|
28
|
+
exports.toToken = require_onchain_validation_token.toToken;
|
|
29
|
+
exports.toTokenAmount = require_onchain_validation_token.toTokenAmount;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/onchain/
|
|
2
|
+
//#region src/onchain/validation/refusal.ts
|
|
3
3
|
/** Builds the refusal a caller sees. */
|
|
4
4
|
function refuse(reason, detail) {
|
|
5
5
|
return {
|
|
@@ -23,6 +23,17 @@ var IntentPreviewError = class extends Error {
|
|
|
23
23
|
this.detail = detail;
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Throws the issue a check found, with the sentence the engine logs for it.
|
|
28
|
+
*
|
|
29
|
+
* Returns normally when there is nothing to raise, so it cannot narrow a type
|
|
30
|
+
* the way a bare `throw` does — a site that guards a value for the code below
|
|
31
|
+
* it keeps throwing directly.
|
|
32
|
+
*/
|
|
33
|
+
function raise(issue, message) {
|
|
34
|
+
if (issue) throw new IntentPreviewError(issue.reason, issue.detail, message);
|
|
35
|
+
}
|
|
26
36
|
//#endregion
|
|
27
37
|
exports.IntentPreviewError = IntentPreviewError;
|
|
38
|
+
exports.raise = raise;
|
|
28
39
|
exports.refuse = refuse;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_onchain_utils_formatter = require("../utils/formatter.js");
|
|
3
|
+
const require_onchain_validation_checks = require("./checks.js");
|
|
4
|
+
//#region src/onchain/validation/token.ts
|
|
5
|
+
/**
|
|
6
|
+
* The token behind an address, for the refusal details that inline one.
|
|
7
|
+
*
|
|
8
|
+
* A token the registry does not know falls back to its own shortened address
|
|
9
|
+
* as a symbol and `decimals: 0` — an unknown token has no scale, and guessing
|
|
10
|
+
* 18 would silently misformat every amount denominated in it.
|
|
11
|
+
*/
|
|
12
|
+
function toToken(sdk, address) {
|
|
13
|
+
const known = sdk.tokensMeta.getToken(address);
|
|
14
|
+
if (known) return known;
|
|
15
|
+
return {
|
|
16
|
+
chainId: sdk.chainId,
|
|
17
|
+
address,
|
|
18
|
+
symbol: require_onchain_utils_formatter.shortAddress(address),
|
|
19
|
+
name: "",
|
|
20
|
+
decimals: 0
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** {@link toToken} plus an amount denominated in it. */
|
|
24
|
+
function toTokenAmount(sdk, address, value) {
|
|
25
|
+
return require_onchain_validation_checks.amountOf(toToken(sdk, address), value);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.toToken = toToken;
|
|
29
|
+
exports.toTokenAmount = toTokenAmount;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_onchain_market_zapper_errors = require("../onchain/market/zapper/errors.js");
|
|
3
|
+
const require_onchain_validation_refusal = require("../onchain/validation/refusal.js");
|
|
3
4
|
const require_preview_trace_errors = require("./trace/errors.js");
|
|
4
5
|
const require_preview_trace_extractAdapterCallTraces = require("./trace/extractAdapterCallTraces.js");
|
|
5
6
|
const require_preview_trace_extractTransfers = require("./trace/extractTransfers.js");
|
|
@@ -32,9 +33,13 @@ const require_preview_preview_previewCloseOrRepayCreditAccount = require("./prev
|
|
|
32
33
|
const require_preview_preview_previewOperation = require("./preview/previewOperation.js");
|
|
33
34
|
require("./preview/index.js");
|
|
34
35
|
require("./types.js");
|
|
36
|
+
const require_preview_validate_checkOperation = require("./validate/checkOperation.js");
|
|
37
|
+
const require_preview_validate_checkSimulation = require("./validate/checkSimulation.js");
|
|
38
|
+
require("./validate/index.js");
|
|
35
39
|
exports.AllowancePrerequisite = require_preview_prerequisites_AllowancePrerequisite.AllowancePrerequisite;
|
|
36
40
|
exports.BalancePrerequisite = require_preview_prerequisites_BalancePrerequisite.BalancePrerequisite;
|
|
37
41
|
exports.CreditAccountState = require_preview_preview_CreditAccountState.CreditAccountState;
|
|
42
|
+
exports.IntentPreviewError = require_onchain_validation_refusal.IntentPreviewError;
|
|
38
43
|
exports.Prerequisite = require_preview_prerequisites_Prerequisite.Prerequisite;
|
|
39
44
|
exports.RWAOpenRequirementsPrerequisite = require_preview_prerequisites_RWAOpenRequirementsPrerequisite.RWAOpenRequirementsPrerequisite;
|
|
40
45
|
exports.TransferAlignmentError = require_preview_trace_errors.TransferAlignmentError;
|
|
@@ -47,9 +52,12 @@ exports.UnsupportedTargetError = require_preview_parse_errors.UnsupportedTargetE
|
|
|
47
52
|
exports.UnsupportedZapperFunctionError = require_onchain_market_zapper_errors.UnsupportedZapperFunctionError;
|
|
48
53
|
exports.WithdrawCollateralAlignmentError = require_preview_trace_errors.WithdrawCollateralAlignmentError;
|
|
49
54
|
exports.buildDelayedPreview = require_preview_preview_buildDelayedPreview.buildDelayedPreview;
|
|
55
|
+
exports.checkOperation = require_preview_validate_checkOperation.checkOperation;
|
|
50
56
|
exports.checkPrerequisites = require_preview_prerequisites_checkPrerequisites.checkPrerequisites;
|
|
57
|
+
exports.checkSimulation = require_preview_validate_checkSimulation.checkSimulation;
|
|
51
58
|
exports.classifyCloseOrRepay = require_preview_preview_detectCloseOrRepay.classifyCloseOrRepay;
|
|
52
59
|
exports.classifyInnerOperations = require_preview_parse_classifyInnerOperations.classifyInnerOperations;
|
|
60
|
+
exports.collateralIssuesOf = require_preview_validate_checkOperation.collateralIssuesOf;
|
|
53
61
|
exports.detectDelayedClaim = require_preview_preview_detectDelayedClaim.detectDelayedClaim;
|
|
54
62
|
exports.detectDelayedOperation = require_preview_preview_detectDelayedOperation.detectDelayedOperation;
|
|
55
63
|
exports.extractAdapterCallTraces = require_preview_trace_extractAdapterCallTraces.extractAdapterCallTraces;
|
|
@@ -66,6 +74,8 @@ exports.parseRWAFactoryOperationCalldata = require_preview_parse_parseRWAFactory
|
|
|
66
74
|
exports.previewAdjustCreditAccount = require_preview_preview_previewAdjustCreditAccount.previewAdjustCreditAccount;
|
|
67
75
|
exports.previewCloseOrRepayCreditAccount = require_preview_preview_previewCloseOrRepayCreditAccount.previewCloseOrRepayCreditAccount;
|
|
68
76
|
exports.previewOperation = require_preview_preview_previewOperation.previewOperation;
|
|
77
|
+
exports.raise = require_onchain_validation_refusal.raise;
|
|
78
|
+
exports.refuse = require_onchain_validation_refusal.refuse;
|
|
69
79
|
exports.replayInnerOperations = require_preview_preview_replayInnerOperations.replayInnerOperations;
|
|
70
80
|
exports.replayMulticall = require_preview_preview_replayMulticall.replayMulticall;
|
|
71
81
|
exports.resolveDelayedClaimIntent = require_preview_preview_detectDelayedClaim.resolveDelayedClaimIntent;
|
|
@@ -204,6 +204,7 @@ function buildAdjustPreview(post, before, collateralWithdrawn, converter, sdk) {
|
|
|
204
204
|
assetsChange: post.balances.difference(before.balances).toAssets(require_onchain_constants_math.DUST_THRESHOLD).map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
205
205
|
error: converter.error,
|
|
206
206
|
healthFactor: sdk.positions.healthFactor(snap),
|
|
207
|
+
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
207
208
|
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: before.totalDebt - post.totalDebt }),
|
|
208
209
|
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: before.totalDebt - post.totalDebt }),
|
|
209
210
|
liquidationPrice: sdk.positions.liquidationPrice(snap),
|
|
@@ -61,6 +61,7 @@ async function previewAdjustCreditAccount(input, operation, options) {
|
|
|
61
61
|
assetsChange: assetsChange.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
62
62
|
error,
|
|
63
63
|
healthFactor: sdk.positions.healthFactor(snap),
|
|
64
|
+
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
64
65
|
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt }),
|
|
65
66
|
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: before.totalDebt - account.totalDebt }),
|
|
66
67
|
liquidationPrice: sdk.positions.liquidationPrice(snap),
|
|
@@ -51,6 +51,7 @@ async function previewOpenCreditAccount(input, operation) {
|
|
|
51
51
|
assets: assets.map((a) => oracle.toTokenAmount(a.token, a.balance)),
|
|
52
52
|
error,
|
|
53
53
|
healthFactor: sdk.positions.healthFactor(snap),
|
|
54
|
+
safeHealthFactor: sdk.positions.healthFactor(snap, { safePrices: true }),
|
|
54
55
|
borrowRate: sdk.positions.borrowRate(snap, { availableLiquidityChange: -account.totalDebt }),
|
|
55
56
|
timeToLiquidation: sdk.positions.timeToLiquidation(snap, { availableLiquidityChange: -account.totalDebt }),
|
|
56
57
|
liquidationPrice: sdk.positions.liquidationPrice(snap),
|