@gearbox-protocol/sdk 16.0.0-next.18 → 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 +7 -8
- 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 +1 -0
- 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/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 +17 -13
- 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 +5 -5
- 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 +1 -0
- 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/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 +15 -11
- 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 +4 -3
- 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/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/index.d.ts +2 -2
- package/dist/types/sdk/prepare/types.d.ts +2 -2
- 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,9 +1,7 @@
|
|
|
1
|
-
import { Bps } from "
|
|
2
|
-
import "
|
|
3
|
-
import { Asset } from "../../base/types.js";
|
|
4
|
-
import "../../index.js";
|
|
1
|
+
import { Bps, Token, TokenAmount } from "../../model/primitives.js";
|
|
2
|
+
import "../../model/index.js";
|
|
5
3
|
import { Address } from "viem";
|
|
6
|
-
//#region src/onchain/
|
|
4
|
+
//#region src/onchain/validation/refusal.d.ts
|
|
7
5
|
/**
|
|
8
6
|
* Why a preview could not be produced.
|
|
9
7
|
*
|
|
@@ -57,21 +55,33 @@ type PreviewErrorReason =
|
|
|
57
55
|
* The account would end the transaction owing more than its collateral is
|
|
58
56
|
* worth under liquidation thresholds, which the facade refuses to allow.
|
|
59
57
|
*/
|
|
60
|
-
"insufficientCollateral"
|
|
58
|
+
"insufficientCollateral" |
|
|
59
|
+
/** The pool is winding down: it still pays out, but takes no more deposits. */
|
|
60
|
+
"poolSunset" |
|
|
61
|
+
/**
|
|
62
|
+
* The account would end up with more quoted tokens than the facade enables
|
|
63
|
+
* at once. A count, not an amount — unlike `quotaLimitReached`.
|
|
64
|
+
*/
|
|
65
|
+
"quotaCountExceeded" |
|
|
66
|
+
/**
|
|
67
|
+
* The transaction could not be replayed: it is malformed, and every field
|
|
68
|
+
* derived from replayed balances is guesswork.
|
|
69
|
+
*/
|
|
70
|
+
"malformedTransaction";
|
|
61
71
|
/**
|
|
62
72
|
* The numbers behind each refusal, so a caller reads the limit that was missed
|
|
63
73
|
* instead of re-deriving it.
|
|
64
74
|
*
|
|
65
|
-
* Anything with a token and an amount is
|
|
66
|
-
* token. `undefined` marks a reason raised from several places, only some of
|
|
75
|
+
* Anything with a token and an amount is a {@link TokenAmount}; ratios carry
|
|
76
|
+
* no token. `undefined` marks a reason raised from several places, only some of
|
|
67
77
|
* which hold the numbers.
|
|
68
78
|
*/
|
|
69
79
|
interface PreviewErrorDetails {
|
|
70
80
|
/** All three in the market's underlying. */
|
|
71
81
|
debtOutOfRange: {
|
|
72
|
-
requested:
|
|
73
|
-
minDebt:
|
|
74
|
-
maxDebt:
|
|
82
|
+
requested: TokenAmount;
|
|
83
|
+
minDebt: TokenAmount;
|
|
84
|
+
maxDebt: TokenAmount;
|
|
75
85
|
};
|
|
76
86
|
/**
|
|
77
87
|
* Scaled by `LEVERAGE_DECIMALS` (`100n` = 1x), as the intent states it — not
|
|
@@ -84,44 +94,57 @@ interface PreviewErrorDetails {
|
|
|
84
94
|
} | undefined;
|
|
85
95
|
/** `undefined` where the request never got as far as naming an amount. */
|
|
86
96
|
insufficientSourceBalance: {
|
|
87
|
-
required:
|
|
88
|
-
held:
|
|
97
|
+
required: TokenAmount;
|
|
98
|
+
held: TokenAmount;
|
|
89
99
|
} | undefined;
|
|
90
100
|
unsupportedCollateralToken: {
|
|
91
|
-
token:
|
|
101
|
+
token: Token;
|
|
92
102
|
};
|
|
93
103
|
/**
|
|
94
104
|
* `to` is absent where the market named no output for `from`. The whole
|
|
95
105
|
* detail is absent only when the pathfinder reverted rather than answered.
|
|
96
106
|
*/
|
|
97
107
|
unsupportedTokenPair: {
|
|
98
|
-
from:
|
|
99
|
-
to:
|
|
108
|
+
from: Token;
|
|
109
|
+
to: Token | undefined;
|
|
100
110
|
} | undefined;
|
|
101
111
|
noDelayedRoute: {
|
|
102
|
-
token:
|
|
112
|
+
token: Token;
|
|
103
113
|
} | undefined;
|
|
104
114
|
multipleDelayedWithdrawals: {
|
|
105
|
-
token:
|
|
115
|
+
token: Token;
|
|
106
116
|
venues: number;
|
|
107
117
|
};
|
|
108
118
|
/** The phantom token standing for the redemption already in flight. */
|
|
109
119
|
withdrawalInProgress: {
|
|
110
|
-
inFlight:
|
|
120
|
+
inFlight: TokenAmount;
|
|
111
121
|
};
|
|
112
122
|
noRecordedIntent: undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Which contract is paused. A credit account operation names the manager, an
|
|
125
|
+
* LP operation the pool — the two are never both present.
|
|
126
|
+
*/
|
|
113
127
|
marketPaused: {
|
|
114
128
|
creditManager: Address;
|
|
129
|
+
} | {
|
|
130
|
+
pool: Address;
|
|
115
131
|
};
|
|
116
132
|
/** `expirationDate` is unix seconds, as the facade reports it. */
|
|
117
133
|
marketExpired: {
|
|
118
134
|
creditManager: Address;
|
|
119
135
|
expirationDate: number;
|
|
120
136
|
};
|
|
121
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Both in the market's underlying. `binding` names which of the four ceilings
|
|
139
|
+
* ran out first, so a caller can say what would fix it — waiting for lenders
|
|
140
|
+
* and asking governance are opposite answers. `solutionAmount` is the largest
|
|
141
|
+
* position still openable, absent when even the minimum debt does not fit.
|
|
142
|
+
*/
|
|
122
143
|
insufficientPoolLiquidity: {
|
|
123
|
-
requested:
|
|
124
|
-
available:
|
|
144
|
+
requested: TokenAmount;
|
|
145
|
+
available: TokenAmount;
|
|
146
|
+
binding: BorrowLimitBinding;
|
|
147
|
+
solutionAmount?: TokenAmount;
|
|
125
148
|
};
|
|
126
149
|
/**
|
|
127
150
|
* `token` is the one whose quota is asked for; the amounts are in the
|
|
@@ -130,16 +153,18 @@ interface PreviewErrorDetails {
|
|
|
130
153
|
* against a limit.
|
|
131
154
|
*/
|
|
132
155
|
quotaLimitReached: {
|
|
133
|
-
token:
|
|
134
|
-
requested:
|
|
135
|
-
available:
|
|
156
|
+
token: Token;
|
|
157
|
+
requested: TokenAmount | undefined;
|
|
158
|
+
available: TokenAmount;
|
|
136
159
|
};
|
|
137
160
|
forbiddenToken: {
|
|
138
|
-
token:
|
|
161
|
+
token: Token;
|
|
139
162
|
};
|
|
140
163
|
/**
|
|
141
|
-
* `required` is the
|
|
142
|
-
*
|
|
164
|
+
* `required` is the bar the factor was weighed against — the facade's own
|
|
165
|
+
* `1.0` for a check that asks whether the transaction lands, a form's higher
|
|
166
|
+
* bar for one that asks whether it is wise. `healthFactor` is the factor
|
|
167
|
+
* compared, which for a call that hands funds over is the safe-price one;
|
|
143
168
|
* `safePrices` says which, since a preview always reports main prices.
|
|
144
169
|
*/
|
|
145
170
|
insufficientCollateral: {
|
|
@@ -147,18 +172,54 @@ interface PreviewErrorDetails {
|
|
|
147
172
|
required: Bps;
|
|
148
173
|
safePrices: boolean;
|
|
149
174
|
};
|
|
175
|
+
poolSunset: {
|
|
176
|
+
pool: Address;
|
|
177
|
+
};
|
|
178
|
+
/** How many quoted tokens the account would end with, against the cap. */
|
|
179
|
+
quotaCountExceeded: {
|
|
180
|
+
count: number;
|
|
181
|
+
max: number;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* The SDK's own preview error code (the `ERROR_*` 1xxx constants) and its
|
|
185
|
+
* human-readable detail.
|
|
186
|
+
*/
|
|
187
|
+
malformedTransaction: {
|
|
188
|
+
code: number;
|
|
189
|
+
message: string;
|
|
190
|
+
};
|
|
150
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Which ceiling ran out when a borrow could not be served.
|
|
194
|
+
*
|
|
195
|
+
* The names are the expressions, not the legacy labels, because the two do not
|
|
196
|
+
* line up: the legacy `insufficientDebtLimit` was the manager's own headroom
|
|
197
|
+
* (`managerDebtAvailable`), `insufficientPoolDebtLimit` was `poolDebtLimit`,
|
|
198
|
+
* and `insufficientPoolLiquidity` was what the manager could still draw
|
|
199
|
+
* (`poolAvailableLiquidity`).
|
|
200
|
+
*
|
|
201
|
+
* `borrowable()` weighs only three of these — the pool's free liquidity, the
|
|
202
|
+
* manager's remaining allowance and the facade's per-block cap. `poolDebtLimit`
|
|
203
|
+
* is read by the account-opening path alone, which is why it is not among them.
|
|
204
|
+
*/
|
|
205
|
+
type BorrowLimitBinding = "poolAvailableLiquidity" | "poolDebtLimit" | "managerDebtAvailable" | "facadePerBlockCap";
|
|
151
206
|
/**
|
|
152
207
|
* The failure half every simulation shares.
|
|
153
208
|
*
|
|
154
209
|
* Distributed over the reasons rather than written as `{ reason; detail }`, so
|
|
155
210
|
* that narrowing on `reason` narrows `detail` with it.
|
|
156
211
|
*/
|
|
157
|
-
type
|
|
158
|
-
ok: false;
|
|
212
|
+
type PreviewIssue = { [R in PreviewErrorReason]: {
|
|
159
213
|
reason: R;
|
|
160
214
|
detail: PreviewErrorDetails[R];
|
|
161
215
|
}; }[PreviewErrorReason];
|
|
216
|
+
/**
|
|
217
|
+
* The failure half every simulation shares: an issue, plus the `ok: false`
|
|
218
|
+
* that tells it apart from a preview.
|
|
219
|
+
*/
|
|
220
|
+
type PreviewRefusal = {
|
|
221
|
+
ok: false;
|
|
222
|
+
} & PreviewIssue;
|
|
162
223
|
/** Builds the refusal a caller sees. */
|
|
163
224
|
declare function refuse<R extends PreviewErrorReason>(reason: R, detail: PreviewErrorDetails[R]): PreviewRefusal;
|
|
164
225
|
/**
|
|
@@ -171,5 +232,13 @@ declare class IntentPreviewError<R extends PreviewErrorReason = PreviewErrorReas
|
|
|
171
232
|
readonly detail: PreviewErrorDetails[R];
|
|
172
233
|
constructor(reason: R, detail: PreviewErrorDetails[R], message?: string);
|
|
173
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Throws the issue a check found, with the sentence the engine logs for it.
|
|
237
|
+
*
|
|
238
|
+
* Returns normally when there is nothing to raise, so it cannot narrow a type
|
|
239
|
+
* the way a bare `throw` does — a site that guards a value for the code below
|
|
240
|
+
* it keeps throwing directly.
|
|
241
|
+
*/
|
|
242
|
+
declare function raise(issue: PreviewIssue | null, message: string): void;
|
|
174
243
|
//#endregion
|
|
175
|
-
export { IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewRefusal, refuse };
|
|
244
|
+
export { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Token, TokenAmount } from "../../model/primitives.js";
|
|
2
|
+
import "../../model/index.js";
|
|
3
|
+
import { OnchainSDK } from "../OnchainSDK.js";
|
|
4
|
+
import { Address } from "viem";
|
|
5
|
+
//#region src/onchain/validation/token.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The token behind an address, for the refusal details that inline one.
|
|
8
|
+
*
|
|
9
|
+
* A token the registry does not know falls back to its own shortened address
|
|
10
|
+
* as a symbol and `decimals: 0` — an unknown token has no scale, and guessing
|
|
11
|
+
* 18 would silently misformat every amount denominated in it.
|
|
12
|
+
*/
|
|
13
|
+
declare function toToken(sdk: OnchainSDK, address: Address): Token;
|
|
14
|
+
/** {@link toToken} plus an amount denominated in it. */
|
|
15
|
+
declare function toTokenAmount(sdk: OnchainSDK, address: Address, value: bigint): TokenAmount;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { toToken, toTokenAmount };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UnsupportedZapperFunctionError } from "../onchain/market/zapper/errors.js";
|
|
2
|
+
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../onchain/validation/refusal.js";
|
|
2
3
|
import { AdapterOperation, AdapterOperationBase, TokenTransfer, TraceAdapterExt } from "./parse/types-adapters.js";
|
|
3
4
|
import { AddCollateralOp, CloseCreditAccountOperation, CompareBalancesOp, CreditAccountOperation, DecreaseDebtOp, DirectTokenTransferOperation, FacadeOperationMetadata, IncreaseDebtOp, InnerFacadeOperation, InnerOperation, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, OperationMetadata, OuterFacadeOperation, PartialLiquidationOperation, StoreExpectedBalancesOp, UpdateQuotaOp, WithdrawCollateralOp } from "./parse/types-facades.js";
|
|
4
5
|
import { PoolDepositOperation, PoolMintOperation, PoolOperation, PoolRedeemOperation, PoolWithdrawOperation } from "./parse/types-pools.js";
|
|
@@ -37,4 +38,7 @@ import { previewOperation } from "./preview/previewOperation.js";
|
|
|
37
38
|
import { ReplayState, makeReplayState, replayInnerOperations } from "./preview/replayInnerOperations.js";
|
|
38
39
|
import { ReplayMulticallResult, ReplayableOperation, replayMulticall } from "./preview/replayMulticall.js";
|
|
39
40
|
import "./preview/index.js";
|
|
40
|
-
|
|
41
|
+
import { CheckOperationOptions, checkOperation, collateralIssuesOf } from "./validate/checkOperation.js";
|
|
42
|
+
import { checkSimulation } from "./validate/checkSimulation.js";
|
|
43
|
+
import "./validate/index.js";
|
|
44
|
+
export { AdapterOperation, AdapterOperationBase, AddCollateralOp, AllowanceDetail, AllowancePrerequisite, AllowanceResult, BalanceDetail, BalancePrerequisite, BalanceResult, BorrowLimitBinding, CheckOperationOptions, ClassifyInnerOperationsProps, CloseCreditAccountOperation, CloseOrRepayOperation, CompareBalancesOp, ConvertFn, CreditAccountOperation, CreditAccountState, CreditAccountStateProps, DecreaseDebtOp, DetectedDelayedClaim, DetectedDelayedOperation, DirectTokenTransferOperation, ExtractTransfersResult, FacadeCallType, FacadeOperationMetadata, FacadeParsedCall, IncreaseDebtOp, InnerFacadeOperation, InnerOperation, IntentPreviewError, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, Operation, OperationMetadata, OuterFacadeOperation, PartialLiquidationOperation, PoolDepositOperation, PoolMintOperation, PoolOperation, PoolRedeemOperation, PoolWithdrawOperation, Prerequisite, PrerequisiteContext, PrerequisiteError, PrerequisiteKind, PrerequisiteOutcome, PrerequisiteResult, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewOperationInput, PreviewOperationOptions, PreviewRefusal, RWAMulticallOperation, RWAOpenCreditAccountOperation, RWAOpenRequirementsDetail, RWAOpenRequirementsPrerequisite, RWAOpenRequirementsResult, RWAOperation, RWAOperationMetadata, ReplayMulticallResult, ReplayState, ReplayableOperation, StoreExpectedBalancesOp, TokenTransfer, TraceAdapterExt, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, UnsupportedOperationError, UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError, UpdateQuotaOp, WithdrawCollateralAlignmentError, WithdrawCollateralEventInfo, WithdrawCollateralOp, buildDelayedPreview, checkOperation, checkPrerequisites, checkSimulation, classifyCloseOrRepay, classifyInnerOperations, collateralIssuesOf, detectDelayedClaim, detectDelayedOperation, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustCreditAccount, previewCloseOrRepayCreditAccount, previewOperation, raise, refuse, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -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,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 };
|
|
@@ -7,9 +7,9 @@ import { ClaimableWithdrawal } from "../../onchain/accounts/withdrawal-compresso
|
|
|
7
7
|
import { Asset } from "../../onchain/base/types.js";
|
|
8
8
|
import { MultiCall } from "../../onchain/types/transactions.js";
|
|
9
9
|
import { PoolSimulation } from "../../onchain/pools/types.js";
|
|
10
|
+
import { BorrowLimitBinding, IntentPreviewError, PreviewErrorDetails, PreviewErrorReason, PreviewIssue, PreviewRefusal, raise, refuse } from "../../onchain/validation/refusal.js";
|
|
10
11
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
11
12
|
import { AccountCalculatorOperation } from "../../onchain/accounts/intents/operations.js";
|
|
12
|
-
import { PreviewErrorDetails, PreviewErrorReason, PreviewRefusal } from "../../onchain/accounts/intents/refusal.js";
|
|
13
13
|
import { DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteRefusals } from "../../onchain/accounts/intents/types.js";
|
|
14
14
|
import { OpenStrategyPreview } from "../../onchain/accounts/intents/open-strategy.js";
|
|
15
15
|
import "../../onchain/index.js";
|
|
@@ -517,4 +517,4 @@ interface OpportunitiesPrepare {
|
|
|
517
517
|
finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategySimulate>>;
|
|
518
518
|
}
|
|
519
519
|
//#endregion
|
|
520
|
-
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 };
|