@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
2
|
+
import { OperationPreview } from "../../model/previews.js";
|
|
3
|
+
import "../../model/index.js";
|
|
4
|
+
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
5
|
+
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
6
|
+
import { PreviewIssue } from "../../onchain/validation/refusal.js";
|
|
7
|
+
import "../../onchain/index.js";
|
|
8
|
+
//#region src/preview/validate/checkOperation.d.ts
|
|
9
|
+
/** Omitting a bar switches its check off — there is no single right one. */
|
|
10
|
+
interface CheckOperationOptions {
|
|
11
|
+
/** Lowest acceptable health factor at main prices, in bps. */
|
|
12
|
+
minHealthFactor?: Bps;
|
|
13
|
+
/** Lowest acceptable health factor at safe prices, in bps. */
|
|
14
|
+
minSafeHealthFactor?: Bps;
|
|
15
|
+
/**
|
|
16
|
+
* Balances the operation is funded from, by token. Given, the wallet's side
|
|
17
|
+
* is checked offline; omitted, funding is left to `checkPrerequisites`.
|
|
18
|
+
*/
|
|
19
|
+
balances?: AddressMap<bigint>;
|
|
20
|
+
/**
|
|
21
|
+
* The factor the account stands at now. Given, an operation that raises it
|
|
22
|
+
* passes even from under the bar — the top-ups that rescue a position would
|
|
23
|
+
* otherwise be refused by the very check meant to protect it.
|
|
24
|
+
*/
|
|
25
|
+
currentHealthFactor?: Bps;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether a parsed operation may be signed at all — the protocol state that
|
|
29
|
+
* `checkPrerequisites` leaves out, since that one covers only what the sender
|
|
30
|
+
* can fix themselves.
|
|
31
|
+
*
|
|
32
|
+
* Synchronous: the preview carries the numbers and the market is attached.
|
|
33
|
+
* Reports the most fundamental issue it finds and stops there, which is the one
|
|
34
|
+
* a caller acts on.
|
|
35
|
+
*/
|
|
36
|
+
declare function checkOperation(input: {
|
|
37
|
+
sdk: OnchainSDK;
|
|
38
|
+
preview: OperationPreview;
|
|
39
|
+
}, options?: CheckOperationOptions): PreviewIssue | null;
|
|
40
|
+
/** The two collateral bars, shared by the preview and the simulation paths. */
|
|
41
|
+
declare function collateralIssuesOf(factors: {
|
|
42
|
+
healthFactor: Bps | undefined;
|
|
43
|
+
safeHealthFactor: Bps | undefined;
|
|
44
|
+
}, options: CheckOperationOptions): PreviewIssue | null;
|
|
45
|
+
//#endregion
|
|
46
|
+
export { CheckOperationOptions, checkOperation, collateralIssuesOf };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnchainSDK } from "../../onchain/OnchainSDK.js";
|
|
2
|
+
import { PreviewIssue } from "../../onchain/validation/refusal.js";
|
|
3
|
+
import { OperationState } from "../../onchain/accounts/intents/types.js";
|
|
4
|
+
import "../../onchain/index.js";
|
|
5
|
+
import { CheckOperationOptions } from "./checkOperation.js";
|
|
6
|
+
import { Address } from "viem";
|
|
7
|
+
//#region src/preview/validate/checkSimulation.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Whether a simulated operation clears the caller's own bars.
|
|
10
|
+
*
|
|
11
|
+
* The engine holds an account to the facade's `1.0`, because its guards answer
|
|
12
|
+
* "would this revert". A form is wiser to ask for more, and the engine's own
|
|
13
|
+
* note says so — a caller wanting the stricter bar applies it itself. This is
|
|
14
|
+
* that second opinion, over the numbers the engine already reported.
|
|
15
|
+
*
|
|
16
|
+
* Three of the checks below the engine does not make at all: both health-factor
|
|
17
|
+
* bars are its own `1.0`, and the quota count it never weighs. The other two run
|
|
18
|
+
* against the same numbers the engine used, and are here so that a change in the
|
|
19
|
+
* engine cannot pass silently.
|
|
20
|
+
*
|
|
21
|
+
* What is deliberately absent: the forbidden-token, quota-limit and funding
|
|
22
|
+
* checks all need the *delta* an operation applies, and `OperationState` reports
|
|
23
|
+
* only the state after it. Weighing them against absolutes would refuse a
|
|
24
|
+
* forbidden token the account merely holds, or a quota the operation never
|
|
25
|
+
* touched. The engine performed all three during the walk, so a simulation that
|
|
26
|
+
* came back `ok` has already passed them.
|
|
27
|
+
*/
|
|
28
|
+
declare function checkSimulation(input: {
|
|
29
|
+
sdk: OnchainSDK;
|
|
30
|
+
state: OperationState;
|
|
31
|
+
creditManager: Address;
|
|
32
|
+
}, options?: CheckOperationOptions): PreviewIssue | null;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { checkSimulation };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../onchain/validation/refusal.js";
|
|
1
2
|
import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
|
|
2
|
-
import { PreviewErrorDetails, PreviewErrorReason, PreviewRefusal } from "../onchain/accounts/intents/refusal.js";
|
|
3
3
|
import { OperationState, PathLossRate } from "../onchain/accounts/intents/types.js";
|
|
4
4
|
import { EnsureFreshChains, GearboxSDKOptions, Mode, NamespaceOptions, NoticesByMode, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, PlainMultichainSDKOptions } from "./types.js";
|
|
5
5
|
import { EntityMerger, FilterResult, ListMerger, MergeListResult } from "./utils/types.js";
|
|
@@ -33,4 +33,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
33
33
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
34
34
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
35
35
|
import "./errors/index.js";
|
|
36
|
-
export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, ChainOf, ChainRef, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategySimulate, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, GearboxSDK, GearboxSDKOptions, type LeverageBand, Liquidations, LiquidationsByMode, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpSimulate, type MergeListResult, MergedQuery, MissingSourceError, Mode, NamespaceOptions, NoSourceServedError, NoticesByMode, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenPrepareRequest, OpenStrategyParams, OpenStrategySimulate, type OperationState, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesExecute, OpportunitiesNamespace, OpportunitiesOffchainBranch, OpportunitiesOffchainOnly, OpportunitiesOnchainBranch, OpportunitiesOnchainOnly, OpportunitiesPrepare, OpportunityMergers, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PositionInput, PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsNamespace, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly, PrepareApi, PrepareOptions, PrepareRequest, Preview, PreviewByMode,
|
|
36
|
+
export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, BorrowLimitBinding, ChainOf, ChainRef, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategySimulate, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, GearboxSDK, GearboxSDKOptions, IntentPreviewError, type LeverageBand, Liquidations, LiquidationsByMode, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpSimulate, type MergeListResult, MergedQuery, MissingSourceError, Mode, NamespaceOptions, NoSourceServedError, NoticesByMode, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenPrepareRequest, OpenStrategyParams, OpenStrategySimulate, type OperationState, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesExecute, OpportunitiesNamespace, OpportunitiesOffchainBranch, OpportunitiesOffchainOnly, OpportunitiesOnchainBranch, OpportunitiesOnchainOnly, OpportunitiesPrepare, OpportunityMergers, type PathLossRate, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PositionInput, PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsNamespace, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly, PrepareApi, PrepareOptions, PrepareRequest, Preview, PreviewByMode, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewNamespace, PreviewRefusal, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, raise, refuse };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainId } from "../../model/primitives.js";
|
|
1
|
+
import { Bps, ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { DataResponse } from "../../model/response.js";
|
|
3
3
|
import "../../model/index.js";
|
|
4
4
|
import { Asset } from "../../onchain/base/types.js";
|
|
@@ -91,11 +91,11 @@ declare class PrepareApi extends MultichainConstruct implements OpportunitiesPre
|
|
|
91
91
|
/**
|
|
92
92
|
* {@inheritDoc OpportunitiesPrepare.leverageBand}
|
|
93
93
|
**/
|
|
94
|
-
leverageBand(strategy: StrategyInput, collateral: readonly Asset[]): LeverageBand | undefined;
|
|
94
|
+
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps): LeverageBand | undefined;
|
|
95
95
|
/**
|
|
96
96
|
* {@inheritDoc OpportunitiesPrepare.maxWithdrawCollateral}
|
|
97
97
|
**/
|
|
98
|
-
maxWithdrawCollateral(position: PositionInput, token: Address): Promise<DataResponse<bigint>>;
|
|
98
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<DataResponse<bigint>>;
|
|
99
99
|
}
|
|
100
100
|
//#endregion
|
|
101
101
|
export { ChainOf, PrepareApi };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
|
|
1
2
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
2
|
-
import { PreviewErrorDetails, PreviewErrorReason, PreviewRefusal } from "../../onchain/accounts/intents/refusal.js";
|
|
3
3
|
import { OperationState, PathLossRate } from "../../onchain/accounts/intents/types.js";
|
|
4
4
|
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
5
5
|
import { ChainOf, PrepareApi } from "./PrepareApi.js";
|
|
6
|
-
export { AddCollateralParams, AdjustLeverageParams, ChainOf, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, type LeverageBand, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, type OperationState, OpportunitiesPrepare, type PathLossRate, PoolInput, PositionInput, PrepareApi, PrepareOptions,
|
|
6
|
+
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, ChainOf, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, IntentPreviewError, type LeverageBand, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, type OperationState, OpportunitiesPrepare, type PathLossRate, PoolInput, PositionInput, PrepareApi, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Bps } from "../../model/primitives.js";
|
|
1
2
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
2
3
|
import { StrategyPositionKey } from "../../model/positions.js";
|
|
3
4
|
import { DataResponse } from "../../model/response.js";
|
|
@@ -6,9 +7,9 @@ import { ClaimableWithdrawal } from "../../onchain/accounts/withdrawal-compresso
|
|
|
6
7
|
import { Asset } from "../../onchain/base/types.js";
|
|
7
8
|
import { MultiCall } from "../../onchain/types/transactions.js";
|
|
8
9
|
import { PoolSimulation } from "../../onchain/pools/types.js";
|
|
10
|
+
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
|
|
9
11
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
10
12
|
import { AccountCalculatorOperation } from "../../onchain/accounts/intents/operations.js";
|
|
11
|
-
import { PreviewErrorDetails, PreviewErrorReason, PreviewRefusal } from "../../onchain/accounts/intents/refusal.js";
|
|
12
13
|
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
13
14
|
import { OpenStrategyPreview } from "../../onchain/accounts/intents/open-strategy.js";
|
|
14
15
|
import "../../onchain/index.js";
|
|
@@ -483,7 +484,7 @@ interface OpportunitiesPrepare {
|
|
|
483
484
|
* no borrowing room left. Not the same answer as "every leverage works", and
|
|
484
485
|
* a caller must not mark a range for it.
|
|
485
486
|
**/
|
|
486
|
-
leverageBand(strategy: StrategyInput, collateral: readonly Asset[]): LeverageBand | undefined;
|
|
487
|
+
leverageBand(strategy: StrategyInput, collateral: readonly Asset[], targetHF?: Bps): LeverageBand | undefined;
|
|
487
488
|
/**
|
|
488
489
|
* Largest amount of one collateral {@link withdrawCollateral} can move out
|
|
489
490
|
* while the account stays safely collateralised, in the token's units: the
|
|
@@ -491,8 +492,11 @@ interface OpportunitiesPrepare {
|
|
|
491
492
|
* capped by their quotas) and the target keeps covering what the debt still
|
|
492
493
|
* requires. Zero debt frees the whole balance — the ceiling a
|
|
493
494
|
* withdraw-collateral form should offer.
|
|
495
|
+
*
|
|
496
|
+
* `targetHF` names the health factor to leave the account at, in basis
|
|
497
|
+
* points; omitted, the SDK holds it to the bar a form would.
|
|
494
498
|
**/
|
|
495
|
-
maxWithdrawCollateral(position: PositionInput, token: Address): Promise<DataResponse<bigint>>;
|
|
499
|
+
maxWithdrawCollateral(position: PositionInput, token: Address, targetHF?: bigint): Promise<DataResponse<bigint>>;
|
|
496
500
|
/**
|
|
497
501
|
* The tail of a delayed route: claim the matured withdrawal, then whatever the
|
|
498
502
|
* operation that requested it still owes — repaying debt and paying the wallet
|
|
@@ -513,4 +517,4 @@ interface OpportunitiesPrepare {
|
|
|
513
517
|
finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategySimulate>>;
|
|
514
518
|
}
|
|
515
519
|
//#endregion
|
|
516
|
-
export { AddCollateralParams, AdjustLeverageParams, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, type LeverageBand, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, type OperationState, OpportunitiesPrepare, type PathLossRate, PoolInput, PositionInput, PrepareOptions,
|
|
520
|
+
export { AddCollateralParams, AdjustLeverageParams, BorrowLimitBinding, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, IntentPreviewError, type LeverageBand, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, type OperationState, OpportunitiesPrepare, type PathLossRate, PoolInput, PositionInput, PrepareOptions, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams, raise, refuse };
|
package/package.json
CHANGED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_onchain_utils_formatter = require("../../../../onchain/utils/formatter.js");
|
|
3
|
-
const require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn = require("./get-cm-you-can-earn.js");
|
|
4
|
-
const require_common_utils_test_utils_index = require("../../../test-utils/index.js");
|
|
5
|
-
let vitest = require("vitest");
|
|
6
|
-
//#region src/common-utils/utils/strategies/strategy-info/get-cm-you-can-earn.spec.ts
|
|
7
|
-
(0, vitest.describe)("getCMYouCanEarn", () => {
|
|
8
|
-
const collateralTokenAddress = "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee";
|
|
9
|
-
const targetTokenAddress = "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8";
|
|
10
|
-
const underlyingTokenAddress = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
|
11
|
-
const deth = "0x871ab8e36cae9af35c6a3488b049965233deb7ed";
|
|
12
|
-
const nativeTokenAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
13
|
-
const wrappedNativeTokenAddress = underlyingTokenAddress;
|
|
14
|
-
const tokenDataList = {
|
|
15
|
-
[collateralTokenAddress]: require_common_utils_test_utils_index.buildTokenData(collateralTokenAddress, "weETH"),
|
|
16
|
-
[targetTokenAddress]: require_common_utils_test_utils_index.buildTokenData(targetTokenAddress, "ethPlus"),
|
|
17
|
-
[underlyingTokenAddress]: require_common_utils_test_utils_index.buildTokenData(underlyingTokenAddress, "WETH"),
|
|
18
|
-
[nativeTokenAddress]: require_common_utils_test_utils_index.buildTokenData(nativeTokenAddress, "ETH"),
|
|
19
|
-
[deth]: require_common_utils_test_utils_index.buildTokenData(deth, "dETH")
|
|
20
|
-
};
|
|
21
|
-
const poolAddress = "0x0000000000000000000000000000000000000POOL";
|
|
22
|
-
const creditManager = require_common_utils_test_utils_index.buildCreditManager({
|
|
23
|
-
address: "0x0000000000000000000000000000000000000CM1",
|
|
24
|
-
pool: poolAddress,
|
|
25
|
-
underlyingToken: underlyingTokenAddress,
|
|
26
|
-
collateralTokens: [
|
|
27
|
-
collateralTokenAddress,
|
|
28
|
-
underlyingTokenAddress,
|
|
29
|
-
targetTokenAddress,
|
|
30
|
-
deth
|
|
31
|
-
],
|
|
32
|
-
supportedTokens: {
|
|
33
|
-
[collateralTokenAddress]: true,
|
|
34
|
-
[underlyingTokenAddress]: true,
|
|
35
|
-
[targetTokenAddress]: true,
|
|
36
|
-
[deth]: true
|
|
37
|
-
},
|
|
38
|
-
liquidationThresholds: {
|
|
39
|
-
[collateralTokenAddress]: 9300n,
|
|
40
|
-
[targetTokenAddress]: 9300n,
|
|
41
|
-
[underlyingTokenAddress]: 9500n,
|
|
42
|
-
[deth]: 8800n
|
|
43
|
-
},
|
|
44
|
-
quotas: {
|
|
45
|
-
[targetTokenAddress]: require_common_utils_test_utils_index.buildQuota({
|
|
46
|
-
isActive: true,
|
|
47
|
-
limit: 5000000000000000000000n,
|
|
48
|
-
quotaIncreaseFee: 0n,
|
|
49
|
-
rate: 100n,
|
|
50
|
-
token: "0xe72b141df173b999ae7c1adcbf60cc9833ce56a8",
|
|
51
|
-
totalQuoted: 1708445825184283030000n
|
|
52
|
-
}),
|
|
53
|
-
[collateralTokenAddress]: require_common_utils_test_utils_index.buildQuota({
|
|
54
|
-
token: collateralTokenAddress,
|
|
55
|
-
rate: 0n,
|
|
56
|
-
limit: require_onchain_utils_formatter.toBN("1000000", 18)
|
|
57
|
-
}),
|
|
58
|
-
[deth]: require_common_utils_test_utils_index.buildQuota({
|
|
59
|
-
isActive: true,
|
|
60
|
-
limit: 500000000000000000000n,
|
|
61
|
-
quotaIncreaseFee: 0n,
|
|
62
|
-
rate: 100n,
|
|
63
|
-
token: deth,
|
|
64
|
-
totalQuoted: 28666207338545540000n
|
|
65
|
-
})
|
|
66
|
-
},
|
|
67
|
-
isQuoted: (t) => t.toLowerCase() !== underlyingTokenAddress,
|
|
68
|
-
feeInterest: 2e3,
|
|
69
|
-
isPaused: false,
|
|
70
|
-
baseBorrowRate: 18991,
|
|
71
|
-
maxDebt: 250000000000000000000n,
|
|
72
|
-
minDebt: 10000000000000000000n,
|
|
73
|
-
availableToBorrow: 859640767327531138355n
|
|
74
|
-
});
|
|
75
|
-
const pools = { [poolAddress]: require_common_utils_test_utils_index.buildPool({
|
|
76
|
-
address: poolAddress,
|
|
77
|
-
chainId: 1,
|
|
78
|
-
network: "Mainnet",
|
|
79
|
-
underlyingToken: underlyingTokenAddress,
|
|
80
|
-
dieselToken: poolAddress,
|
|
81
|
-
isPaused: false,
|
|
82
|
-
version: 310,
|
|
83
|
-
expectedLiquidity: 5596004266940175413222n,
|
|
84
|
-
expectedLiquidityLimit: 6903325375622920584635n,
|
|
85
|
-
availableLiquidity: 1307321108682745171413n,
|
|
86
|
-
interestModel: {
|
|
87
|
-
interestModel: "0x12e6e5c6fe4b37576dd4052e03a97ee7b9c29e86",
|
|
88
|
-
U_1: 7000n,
|
|
89
|
-
U_2: 9200n,
|
|
90
|
-
R_base: 0n,
|
|
91
|
-
R_slope1: 113n,
|
|
92
|
-
R_slope2: 150n,
|
|
93
|
-
R_slope3: 1236n,
|
|
94
|
-
version: 310,
|
|
95
|
-
isBorrowingMoreU2Forbidden: true
|
|
96
|
-
}
|
|
97
|
-
}) };
|
|
98
|
-
const allPrices = { [poolAddress]: {
|
|
99
|
-
[collateralTokenAddress]: 347896889077n,
|
|
100
|
-
[targetTokenAddress]: 342474099875n,
|
|
101
|
-
[underlyingTokenAddress]: 320438727057n,
|
|
102
|
-
[deth]: 322630065873n
|
|
103
|
-
} };
|
|
104
|
-
const walletBalances = {
|
|
105
|
-
[underlyingTokenAddress]: 0n,
|
|
106
|
-
[collateralTokenAddress]: 6191758000000000000n,
|
|
107
|
-
[targetTokenAddress]: 0n
|
|
108
|
-
};
|
|
109
|
-
const apyList = {
|
|
110
|
-
apyList: {
|
|
111
|
-
[targetTokenAddress]: 24600,
|
|
112
|
-
[collateralTokenAddress]: 27612,
|
|
113
|
-
[deth]: 16600
|
|
114
|
-
},
|
|
115
|
-
extraCollateralAPYList: { [poolAddress]: { [targetTokenAddress]: {
|
|
116
|
-
address: targetTokenAddress,
|
|
117
|
-
pool: poolAddress,
|
|
118
|
-
symbol: "ETHPlus",
|
|
119
|
-
type: "relative",
|
|
120
|
-
value: 0
|
|
121
|
-
} } },
|
|
122
|
-
pointsList: {
|
|
123
|
-
[collateralTokenAddress]: {
|
|
124
|
-
symbol: "weETH",
|
|
125
|
-
address: "0xcd5fe23c85820f7b72d0926fc9b05b43e359b7ee",
|
|
126
|
-
debtRewards: void 0,
|
|
127
|
-
rewards: [{
|
|
128
|
-
name: "Ether.fi",
|
|
129
|
-
units: "points",
|
|
130
|
-
multiplier: 200n,
|
|
131
|
-
type: "etherfi"
|
|
132
|
-
}]
|
|
133
|
-
},
|
|
134
|
-
[deth]: {
|
|
135
|
-
address: "0x871ab8e36cae9af35c6a3488b049965233deb7ed",
|
|
136
|
-
debtRewards: void 0,
|
|
137
|
-
rewards: [{
|
|
138
|
-
name: "Makina",
|
|
139
|
-
units: "points",
|
|
140
|
-
multiplier: 36000n,
|
|
141
|
-
type: "makina"
|
|
142
|
-
}],
|
|
143
|
-
symbol: "DETH"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
extraCollateralPointsList: {},
|
|
147
|
-
poolRewardsList: {},
|
|
148
|
-
tokenExtraRewardsList: {},
|
|
149
|
-
poolExternalAPYList: {},
|
|
150
|
-
poolExtraAPYList: {}
|
|
151
|
-
};
|
|
152
|
-
(0, vitest.it)("computes expected earnings for APY-only scenario", () => {
|
|
153
|
-
const strategy = {
|
|
154
|
-
id: "test-strategy",
|
|
155
|
-
tokenOutAddress: targetTokenAddress,
|
|
156
|
-
chainId: 1,
|
|
157
|
-
network: "Mainnet"
|
|
158
|
-
};
|
|
159
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
160
|
-
creditManager,
|
|
161
|
-
pools,
|
|
162
|
-
strategy,
|
|
163
|
-
delayedPhantoms: {},
|
|
164
|
-
apyList,
|
|
165
|
-
tokensList: tokenDataList,
|
|
166
|
-
walletBalances,
|
|
167
|
-
nativeTokenAddress,
|
|
168
|
-
wrappedNativeTokenAddress,
|
|
169
|
-
allPrices,
|
|
170
|
-
slippage: 10,
|
|
171
|
-
quotaReserve: 500
|
|
172
|
-
});
|
|
173
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
174
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
175
|
-
overallAPY: 7.392,
|
|
176
|
-
overallAPYBigInt: 73920n,
|
|
177
|
-
overallAPYStatus: "calculated"
|
|
178
|
-
});
|
|
179
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
180
|
-
earnings: 496914282513333354n,
|
|
181
|
-
earningsUSD: 1592305801450150145856n
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
(0, vitest.it)("computes expected earnings for APY and points scenario", () => {
|
|
185
|
-
const strategy = {
|
|
186
|
-
id: "test-strategy",
|
|
187
|
-
tokenOutAddress: collateralTokenAddress,
|
|
188
|
-
chainId: 1,
|
|
189
|
-
network: "Mainnet"
|
|
190
|
-
};
|
|
191
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
192
|
-
creditManager,
|
|
193
|
-
pools,
|
|
194
|
-
strategy,
|
|
195
|
-
delayedPhantoms: {},
|
|
196
|
-
apyList,
|
|
197
|
-
tokensList: tokenDataList,
|
|
198
|
-
walletBalances,
|
|
199
|
-
nativeTokenAddress,
|
|
200
|
-
wrappedNativeTokenAddress,
|
|
201
|
-
allPrices,
|
|
202
|
-
slippage: 10,
|
|
203
|
-
quotaReserve: 500
|
|
204
|
-
});
|
|
205
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
206
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
207
|
-
overallAPY: 11.233,
|
|
208
|
-
overallAPYBigInt: 112330n,
|
|
209
|
-
overallAPYStatus: "calculated"
|
|
210
|
-
});
|
|
211
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
212
|
-
earnings: 755118795383153892n,
|
|
213
|
-
earningsUSD: 2419693055693930817344n
|
|
214
|
-
});
|
|
215
|
-
(0, vitest.expect)(result.data?.points?.info).toEqual(apyList.pointsList?.[collateralTokenAddress] || {});
|
|
216
|
-
(0, vitest.expect)(result.data?.points).toEqual({
|
|
217
|
-
debtRates: {
|
|
218
|
-
rewards: [],
|
|
219
|
-
rates: []
|
|
220
|
-
},
|
|
221
|
-
info: apyList.pointsList?.[collateralTokenAddress] || {},
|
|
222
|
-
rates: [2454n]
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
(0, vitest.it)("computes expected earnings for points-only scenario", () => {
|
|
226
|
-
const strategy = {
|
|
227
|
-
id: "test-strategy",
|
|
228
|
-
tokenOutAddress: deth,
|
|
229
|
-
chainId: 1,
|
|
230
|
-
network: "Mainnet"
|
|
231
|
-
};
|
|
232
|
-
const result = require_common_utils_utils_strategies_strategy_info_get_cm_you_can_earn.getCMYouCanEarn({
|
|
233
|
-
creditManager,
|
|
234
|
-
pools,
|
|
235
|
-
strategy,
|
|
236
|
-
delayedPhantoms: {},
|
|
237
|
-
apyList,
|
|
238
|
-
tokensList: tokenDataList,
|
|
239
|
-
walletBalances,
|
|
240
|
-
nativeTokenAddress,
|
|
241
|
-
wrappedNativeTokenAddress,
|
|
242
|
-
allPrices,
|
|
243
|
-
slippage: 10,
|
|
244
|
-
quotaReserve: 500
|
|
245
|
-
});
|
|
246
|
-
(0, vitest.expect)(result.status).toEqual("ok");
|
|
247
|
-
(0, vitest.expect)(result.data?.info?.maxAPY).toEqual({
|
|
248
|
-
overallAPY: void 0,
|
|
249
|
-
overallAPYBigInt: void 0,
|
|
250
|
-
overallAPYStatus: "negativeForPoints"
|
|
251
|
-
});
|
|
252
|
-
(0, vitest.expect)(result.data?.earnings).toEqual({
|
|
253
|
-
earnings: null,
|
|
254
|
-
earningsUSD: null
|
|
255
|
-
});
|
|
256
|
-
(0, vitest.expect)(result.data?.points?.info).toEqual(apyList.pointsList?.[deth] || {});
|
|
257
|
-
(0, vitest.expect)(result.data?.points).toEqual({
|
|
258
|
-
debtRates: {
|
|
259
|
-
rewards: [],
|
|
260
|
-
rates: []
|
|
261
|
-
},
|
|
262
|
-
info: apyList.pointsList?.[deth] || {},
|
|
263
|
-
rates: [259920n]
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
//#endregion
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_hf = require("./validate-hf.js");
|
|
3
|
-
const require_common_utils_utils_validation_validate_open_account_pool_quota_status = require("./validate-open-account-pool-quota-status.js");
|
|
4
|
-
const require_common_utils_utils_validation_validate_open_account_pool_status = require("./validate-open-account-pool-status.js");
|
|
5
|
-
const require_common_utils_utils_validation_is_zero_balance = require("./is-zero-balance.js");
|
|
6
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
7
|
-
const require_common_utils_utils_validation_validate_balances = require("./validate-balances.js");
|
|
8
|
-
const require_common_utils_utils_validation_validate_credit_manager = require("./validate-credit-manager.js");
|
|
9
|
-
const require_common_utils_utils_validation_validate_quota = require("./validate-quota.js");
|
|
10
|
-
const require_common_utils_utils_validation_validate_open_account = require("./validate-open-account.js");
|
|
11
|
-
const require_common_utils_utils_validation_validate_token_to_obtain = require("./validate-token-to-obtain.js");
|
|
12
|
-
require("./validation-types.js");
|
|
13
|
-
exports.MIN_HF_LIMITED = require_common_utils_utils_validation_validate_hf.MIN_HF_LIMITED;
|
|
14
|
-
exports.isZeroBalance = require_common_utils_utils_validation_is_zero_balance.isZeroBalance;
|
|
15
|
-
exports.validateBalance = require_common_utils_utils_validation_validate_balance.validateBalance;
|
|
16
|
-
exports.validateBalances = require_common_utils_utils_validation_validate_balances.validateBalances;
|
|
17
|
-
exports.validateCreditManager = require_common_utils_utils_validation_validate_credit_manager.validateCreditManager;
|
|
18
|
-
exports.validateHF = require_common_utils_utils_validation_validate_hf.validateHF;
|
|
19
|
-
exports.validateOpenAccount = require_common_utils_utils_validation_validate_open_account.validateOpenAccount;
|
|
20
|
-
exports.validateOpenAccountPoolQuotaStatus = require_common_utils_utils_validation_validate_open_account_pool_quota_status.validateOpenAccountPoolQuotaStatus;
|
|
21
|
-
exports.validateOpenAccountPoolStatus = require_common_utils_utils_validation_validate_open_account_pool_status.validateOpenAccountPoolStatus;
|
|
22
|
-
exports.validateQuota = require_common_utils_utils_validation_validate_quota.validateQuota;
|
|
23
|
-
exports.validateTokenToObtain = require_common_utils_utils_validation_validate_token_to_obtain.validateTokenToObtain;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("../constants.js");
|
|
3
|
-
const require_common_utils_utils_validation_is_zero_balance = require("./is-zero-balance.js");
|
|
4
|
-
//#region src/common-utils/utils/validation/validate-balance.ts
|
|
5
|
-
function validateBalance({ amount, tokenAddress, maxAmount = 0n, zeroCheck = true, single }) {
|
|
6
|
-
const safeAddress = tokenAddress || "";
|
|
7
|
-
if (!safeAddress) return {
|
|
8
|
-
message: "unknownToken",
|
|
9
|
-
token: safeAddress
|
|
10
|
-
};
|
|
11
|
-
if (maxAmount < amount) return {
|
|
12
|
-
message: "insufficientFunds",
|
|
13
|
-
token: safeAddress
|
|
14
|
-
};
|
|
15
|
-
if (zeroCheck && require_common_utils_utils_validation_is_zero_balance.isZeroBalance(amount)) return {
|
|
16
|
-
message: single ? "enterAmount" : "zeroBalance",
|
|
17
|
-
token: safeAddress
|
|
18
|
-
};
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
exports.validateBalance = validateBalance;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-balance.spec.ts
|
|
6
|
-
(0, vitest.describe)("validateBalance", () => {
|
|
7
|
-
(0, vitest.it)("returns null when all conditions are met", () => {
|
|
8
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
9
|
-
amount: 1000n,
|
|
10
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
11
|
-
maxAmount: 2000n,
|
|
12
|
-
zeroCheck: true,
|
|
13
|
-
single: false
|
|
14
|
-
});
|
|
15
|
-
(0, vitest.expect)(result).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
(0, vitest.it)("returns error when amount exceeds maxAmount", () => {
|
|
18
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
19
|
-
amount: 3000n,
|
|
20
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
21
|
-
maxAmount: 2000n,
|
|
22
|
-
zeroCheck: true,
|
|
23
|
-
single: false
|
|
24
|
-
});
|
|
25
|
-
(0, vitest.expect)(result).toEqual({
|
|
26
|
-
message: "insufficientFunds",
|
|
27
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
(0, vitest.it)("returns error when amount is too small with zeroCheck", () => {
|
|
31
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
32
|
-
amount: 5n,
|
|
33
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
34
|
-
maxAmount: 2000n,
|
|
35
|
-
zeroCheck: true,
|
|
36
|
-
single: false
|
|
37
|
-
});
|
|
38
|
-
(0, vitest.expect)(result).toEqual({
|
|
39
|
-
message: "zeroBalance",
|
|
40
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
(0, vitest.it)("returns null when zeroCheck is false and amount is small", () => {
|
|
44
|
-
const result = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
45
|
-
amount: 5n,
|
|
46
|
-
tokenAddress: require_common_utils_test_utils_index.mockToken1,
|
|
47
|
-
maxAmount: 2000n,
|
|
48
|
-
zeroCheck: false,
|
|
49
|
-
single: false
|
|
50
|
-
});
|
|
51
|
-
(0, vitest.expect)(result).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
//#endregion
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balance = require("./validate-balance.js");
|
|
3
|
-
//#region src/common-utils/utils/validation/validate-balances.ts
|
|
4
|
-
function validateBalances({ balances, assets, zeroCheck = true }) {
|
|
5
|
-
for (const { token: tokenAddress, balance: amount } of assets) {
|
|
6
|
-
const e = require_common_utils_utils_validation_validate_balance.validateBalance({
|
|
7
|
-
tokenAddress,
|
|
8
|
-
amount,
|
|
9
|
-
maxAmount: balances[(tokenAddress || "").toLowerCase()] || 0n,
|
|
10
|
-
zeroCheck
|
|
11
|
-
});
|
|
12
|
-
if (e !== null) return e;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
exports.validateBalances = validateBalances;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_common_utils_utils_validation_validate_balances = require("./validate-balances.js");
|
|
3
|
-
const require_common_utils_test_utils_index = require("../../test-utils/index.js");
|
|
4
|
-
let vitest = require("vitest");
|
|
5
|
-
//#region src/common-utils/utils/validation/validate-balances.spec.ts
|
|
6
|
-
(0, vitest.describe)("validateBalances", () => {
|
|
7
|
-
(0, vitest.it)("returns null when all balances are valid", () => {
|
|
8
|
-
const result = require_common_utils_utils_validation_validate_balances.validateBalances({
|
|
9
|
-
balances: {
|
|
10
|
-
[require_common_utils_test_utils_index.mockToken1]: 2000n,
|
|
11
|
-
[require_common_utils_test_utils_index.mockToken2]: 3000n
|
|
12
|
-
},
|
|
13
|
-
assets: [{
|
|
14
|
-
token: require_common_utils_test_utils_index.mockToken1,
|
|
15
|
-
balance: 1000n
|
|
16
|
-
}, {
|
|
17
|
-
token: require_common_utils_test_utils_index.mockToken2,
|
|
18
|
-
balance: 2000n
|
|
19
|
-
}],
|
|
20
|
-
zeroCheck: true
|
|
21
|
-
});
|
|
22
|
-
(0, vitest.expect)(result).toBeNull();
|
|
23
|
-
});
|
|
24
|
-
(0, vitest.it)("returns error when any balance is invalid", () => {
|
|
25
|
-
const result = require_common_utils_utils_validation_validate_balances.validateBalances({
|
|
26
|
-
balances: {
|
|
27
|
-
[require_common_utils_test_utils_index.mockToken1]: 500n,
|
|
28
|
-
[require_common_utils_test_utils_index.mockToken2]: 3000n
|
|
29
|
-
},
|
|
30
|
-
assets: [{
|
|
31
|
-
token: require_common_utils_test_utils_index.mockToken1,
|
|
32
|
-
balance: 1000n
|
|
33
|
-
}, {
|
|
34
|
-
token: require_common_utils_test_utils_index.mockToken2,
|
|
35
|
-
balance: 2000n
|
|
36
|
-
}],
|
|
37
|
-
zeroCheck: true
|
|
38
|
-
});
|
|
39
|
-
(0, vitest.expect)(result).toEqual({
|
|
40
|
-
message: "insufficientFunds",
|
|
41
|
-
token: require_common_utils_test_utils_index.mockToken1
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
//#endregion
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/common-utils/utils/validation/validate-credit-manager.ts
|
|
3
|
-
function validateCreditManager({ creditManager, allowPausedCm }) {
|
|
4
|
-
if (creditManager.isPaused && !allowPausedCm) return { message: "paused" };
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
exports.validateCreditManager = validateCreditManager;
|