@gearbox-protocol/sdk 16.3.0-next.2 → 16.3.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/errors/index.js +0 -1
- package/dist/cjs/model/errors/operation-errors.js +1 -1
- package/dist/cjs/model/errors/prepare-errors.js +0 -8
- package/dist/cjs/model/index.js +2 -3
- package/dist/cjs/model/rwa.js +4 -4
- package/dist/cjs/model/rwa.schema.js +4 -4
- package/dist/cjs/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/cjs/onchain/accounts/CreditAccountsServiceV310.js +1 -3
- package/dist/cjs/onchain/accounts/intents/guards.js +4 -4
- package/dist/cjs/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/cjs/onchain/market/credit/CreditSuite.js +26 -12
- package/dist/cjs/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +56 -12
- package/dist/cjs/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
- package/dist/cjs/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
- package/dist/cjs/onchain/opportunities/OpportunitiesService.js +16 -4
- package/dist/cjs/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
- package/dist/cjs/onchain/validation/bundles/checkCreditOperation.js +3 -2
- package/dist/cjs/onchain/validation/bundles/checkDraw.js +3 -3
- package/dist/cjs/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
- package/dist/cjs/onchain/validation/bundles/checkRWAOpening.js +6 -5
- package/dist/cjs/onchain/validation/checkSimulation.js +11 -14
- package/dist/cjs/onchain/validation/checks/checkDebtLimits.js +3 -2
- package/dist/cjs/sdk/execute/ExecuteApi.js +2 -2
- package/dist/cjs/sdk/index.js +0 -1
- package/dist/cjs/sdk/opportunities/OpportunitiesNamespace.js +9 -3
- package/dist/cjs/sdk/prepare/PrepareApi.js +27 -8
- package/dist/cjs/sdk/prepare/index.js +0 -1
- package/dist/esm/model/errors/index.js +2 -2
- package/dist/esm/model/errors/operation-errors.js +1 -1
- package/dist/esm/model/errors/prepare-errors.js +1 -8
- package/dist/esm/model/index.js +4 -4
- package/dist/esm/model/rwa.js +4 -4
- package/dist/esm/model/rwa.schema.js +5 -5
- package/dist/esm/offchain/opportunities/OffchainOpportunities.js +1 -1
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +1 -3
- package/dist/esm/onchain/accounts/intents/guards.js +4 -4
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/market/credit/CreditSuite.js +26 -12
- package/dist/esm/onchain/market/rwa/midas/MidasDegenNFT.js +45 -5
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeDegenNFT.js +55 -10
- package/dist/esm/onchain/market/rwa/securitize/SecuritizeRWAFactory.js +0 -37
- package/dist/esm/onchain/opportunities/MultichainOpportunitiesService.js +8 -2
- package/dist/esm/onchain/opportunities/OpportunitiesService.js +16 -4
- package/dist/esm/onchain/preview/parse/parseRWAFactoryOperationCalldata.js +2 -2
- package/dist/esm/onchain/validation/bundles/checkCreditOperation.js +3 -2
- package/dist/esm/onchain/validation/bundles/checkDraw.js +3 -3
- package/dist/esm/onchain/validation/bundles/checkRWAOpenRequirements.js +9 -9
- package/dist/esm/onchain/validation/bundles/checkRWAOpening.js +6 -5
- package/dist/esm/onchain/validation/checkSimulation.js +11 -14
- package/dist/esm/onchain/validation/checks/checkDebtLimits.js +3 -2
- package/dist/esm/sdk/execute/ExecuteApi.js +2 -2
- package/dist/esm/sdk/index.js +2 -2
- package/dist/esm/sdk/opportunities/OpportunitiesNamespace.js +9 -3
- package/dist/esm/sdk/prepare/PrepareApi.js +28 -9
- package/dist/esm/sdk/prepare/index.js +2 -2
- package/dist/types/model/errors/index.d.ts +2 -2
- package/dist/types/model/errors/operation-errors.d.ts +10 -4
- package/dist/types/model/errors/prepare-errors.d.ts +1 -10
- package/dist/types/model/index.d.ts +4 -4
- package/dist/types/model/opportunities.d.ts +4 -5
- package/dist/types/model/rwa.d.ts +47 -27
- package/dist/types/model/rwa.schema.d.ts +3 -3
- package/dist/types/offchain/opportunities/OffchainOpportunities.d.ts +1 -2
- package/dist/types/offchain/opportunities/types.d.ts +1 -4
- package/dist/types/onchain/accounts/types.d.ts +4 -2
- package/dist/types/onchain/index.d.ts +3 -3
- package/dist/types/onchain/market/credit/CreditSuite.d.ts +8 -3
- package/dist/types/onchain/market/credit/types.d.ts +2 -2
- package/dist/types/onchain/market/index.d.ts +2 -2
- package/dist/types/onchain/market/rwa/index.d.ts +2 -2
- package/dist/types/onchain/market/rwa/midas/MidasDegenNFT.d.ts +19 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeDegenNFT.d.ts +24 -4
- package/dist/types/onchain/market/rwa/securitize/SecuritizeRWAFactory.d.ts +2 -14
- package/dist/types/onchain/market/rwa/types.d.ts +39 -37
- package/dist/types/onchain/opportunities/MultichainOpportunitiesService.d.ts +5 -1
- package/dist/types/onchain/opportunities/OpportunitiesService.d.ts +10 -3
- package/dist/types/onchain/opportunities/types.d.ts +6 -1
- package/dist/types/onchain/validation/bundles/checkRWAOpenRequirements.d.ts +2 -2
- package/dist/types/onchain/validation/bundles/checkRWAOpening.d.ts +3 -3
- package/dist/types/onchain/validation/checkSimulation.d.ts +9 -20
- package/dist/types/onchain/validation/checks/checkDebtLimits.d.ts +4 -0
- package/dist/types/onchain/validation/index.d.ts +2 -2
- package/dist/types/sdk/index.d.ts +4 -3
- package/dist/types/sdk/opportunities/OpportunitiesNamespace.d.ts +5 -1
- package/dist/types/sdk/opportunities/types.d.ts +9 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +6 -5
- package/dist/types/sdk/prepare/index.d.ts +4 -3
- package/dist/types/sdk/prepare/types.d.ts +47 -21
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RWA_FACTORY_SECURITIZE,
|
|
1
|
+
import { RWA_FACTORY_SECURITIZE, SecuritizeOperationArgs } from "../../../../model/rwa.js";
|
|
2
2
|
import "../../../../model/index.js";
|
|
3
3
|
import { DStokenData, SecuritizeInvestorData, SecuritizeRWAFactoryStateHuman } from "./types.js";
|
|
4
4
|
import { SecuritizeDegenNFT } from "./SecuritizeDegenNFT.js";
|
|
5
|
-
import { GetInvestorOptions,
|
|
5
|
+
import { GetInvestorOptions, IRWAFactory, RWACompressorInvestorData, RWAFactoryData } from "../types.js";
|
|
6
6
|
import { MultiCall, RawTx } from "../../../types/transactions.js";
|
|
7
7
|
import { OnchainSDK } from "../../../OnchainSDK.js";
|
|
8
8
|
import "../../../types/index.js";
|
|
@@ -497,18 +497,6 @@ declare class SecuritizeRWAFactory extends BaseContract<abi> implements IRWAFact
|
|
|
497
497
|
* {@inheritDoc IRWAFactory.multicall}
|
|
498
498
|
*/
|
|
499
499
|
multicall(creditAccount: Address, calls: MultiCall[], args?: SecuritizeOperationArgs): RawTx;
|
|
500
|
-
/**
|
|
501
|
-
* {@inheritDoc IRWAFactory.getOpenAccountRequirements}
|
|
502
|
-
*/
|
|
503
|
-
getOpenAccountRequirements(investor: Address, props: GetOpenAccountRequirementsProps): Promise<SecuritizeOpenAccountRequirements | undefined>;
|
|
504
|
-
/**
|
|
505
|
-
* {@inheritDoc IRWAFactory.getMissingRequirements}
|
|
506
|
-
*
|
|
507
|
-
* A required signature is omitted when `providedArgs.signaturesToCache`
|
|
508
|
-
* already carries a signature for the same token: the transaction caches it
|
|
509
|
-
* on-chain as part of the operation.
|
|
510
|
-
*/
|
|
511
|
-
getMissingRequirements(requirements: SecuritizeOpenAccountRequirements, providedArgs?: SecuritizeOperationArgs): SecuritizeMissingOpenAccountRequirements | undefined;
|
|
512
500
|
/**
|
|
513
501
|
* {@inheritDoc IRWAFactory.openCreditAccount}
|
|
514
502
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { iRWACompressorAbi } from "../../../abi/rwa/iRWACompressor.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RWAFactoryType, RWAMissingOpenAccountRequirements, RWAOpenAccountRequirements, RWAOperationArgs, RWAProtocol, RWA_FACTORY_SECURITIZE } from "../../../model/rwa.js";
|
|
3
3
|
import "../../../model/index.js";
|
|
4
4
|
import { IBaseContract, Unarray } from "../../base/types.js";
|
|
5
5
|
import { SecuritizeInvestorData, SecuritizeRWAFactoryStateHuman } from "./securitize/types.js";
|
|
@@ -19,10 +19,15 @@ import { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
|
|
|
19
19
|
**/
|
|
20
20
|
interface RWAFactoryTypeMap {
|
|
21
21
|
[RWA_FACTORY_SECURITIZE]: {
|
|
22
|
+
protocol: "securitize";
|
|
22
23
|
investorData: SecuritizeInvestorData;
|
|
23
24
|
stateHuman: SecuritizeRWAFactoryStateHuman;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* {@link RWAProtocol} of the factory type `T`.
|
|
29
|
+
**/
|
|
30
|
+
type RWAFactoryProtocol<T extends RWAFactoryType> = RWAFactoryTypeMap[T]["protocol"];
|
|
26
31
|
/**
|
|
27
32
|
* Investor data decoded from the RWA compressor, defaults to union of all factory types
|
|
28
33
|
* Can be discriminated by type
|
|
@@ -151,26 +156,7 @@ interface IRWAFactory<T extends RWAFactoryType = RWAFactoryType> extends IBaseCo
|
|
|
151
156
|
* @param args - factory-specific args (e.g. tokens to register, signatures to cache).
|
|
152
157
|
* Undefined value means that no RWA actions are required
|
|
153
158
|
**/
|
|
154
|
-
multicall(creditAccount: Address, calls: MultiCall[], args?: RWAOperationArgs<T
|
|
155
|
-
/**
|
|
156
|
-
* Checks if the user can open a credit account with this factory.
|
|
157
|
-
* @param investor - investor address
|
|
158
|
-
* @param props - {@link GetOpenAccountRequirementsProps}
|
|
159
|
-
* @returns open account requirements for the investor, or `undefined` if the
|
|
160
|
-
* user can open a credit account without any further actions
|
|
161
|
-
**/
|
|
162
|
-
getOpenAccountRequirements(investor: Address, props: GetOpenAccountRequirementsProps): Promise<RWAOpenAccountRequirements<T> | undefined>;
|
|
163
|
-
/**
|
|
164
|
-
* Computes the subset of `requirements` still unfulfilled, given the
|
|
165
|
-
* factory-specific params already carried by the transaction calldata.
|
|
166
|
-
*
|
|
167
|
-
* @param requirements - requirements fetched via {@link getOpenAccountRequirements}
|
|
168
|
-
* @param providedArgs - params decoded from the transaction calldata, if
|
|
169
|
-
* any; e.g. signatures already included there need not be signed again
|
|
170
|
-
* @returns the missing requirements, or `undefined` when everything is
|
|
171
|
-
* satisfied
|
|
172
|
-
**/
|
|
173
|
-
getMissingRequirements(requirements: RWAOpenAccountRequirements<T>, providedArgs?: RWAOperationArgs<T>): RWAMissingOpenAccountRequirements<T> | undefined;
|
|
159
|
+
multicall(creditAccount: Address, calls: MultiCall[], args?: RWAOperationArgs<RWAFactoryProtocol<T>>): RawTx;
|
|
174
160
|
/**
|
|
175
161
|
* Creates a raw transaction to open a credit account.
|
|
176
162
|
* Similar to {@link CreditFacadeV310Contract.openCreditAccount}.
|
|
@@ -180,25 +166,41 @@ interface IRWAFactory<T extends RWAFactoryType = RWAFactoryType> extends IBaseCo
|
|
|
180
166
|
* @param args - factory-specific args (e.g. tokens to register, signatures to cache).
|
|
181
167
|
* Undefined value means that no RWA actions are required (e.g. when we open second credit account)
|
|
182
168
|
**/
|
|
183
|
-
openCreditAccount(creditManager: Address, calls: MultiCall[], args?: RWAOperationArgs<T
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
eligible: boolean;
|
|
190
|
-
/** Token the wallet must be registered for. */
|
|
191
|
-
token: Address;
|
|
169
|
+
openCreditAccount(creditManager: Address, calls: MultiCall[], args?: RWAOperationArgs<RWAFactoryProtocol<T>>): RawTx;
|
|
170
|
+
/**
|
|
171
|
+
* Degen NFT this factory deploys as the KYC gate. Midas has no factory;
|
|
172
|
+
* its NFT is loaded separately via {@link createDegenNFT}.
|
|
173
|
+
**/
|
|
174
|
+
readonly degenNFT: IDegenNFT<RWAFactoryProtocol<T>>;
|
|
192
175
|
}
|
|
193
176
|
/**
|
|
194
|
-
* Degen NFT that gates credit-account opening behind
|
|
195
|
-
|
|
196
|
-
interface IDegenNFT extends IBaseContract {
|
|
197
|
-
readonly protocol:
|
|
177
|
+
* Degen NFT that gates credit-account opening behind an RWA KYC provider.
|
|
178
|
+
**/
|
|
179
|
+
interface IDegenNFT<P extends RWAProtocol = RWAProtocol> extends IBaseContract {
|
|
180
|
+
readonly protocol: P;
|
|
181
|
+
readonly registrationLink: string;
|
|
182
|
+
/**
|
|
183
|
+
* Tokens this gate is about: Securitize DS tokens, or the Midas mToken.
|
|
184
|
+
*/
|
|
185
|
+
getTokens(): Promise<Address[]>;
|
|
186
|
+
/**
|
|
187
|
+
* What `wallet` still has to do before this gate lets it open on the
|
|
188
|
+
* strategy token in `props`.
|
|
189
|
+
*/
|
|
190
|
+
getOpenAccountRequirements(wallet: Address, props: GetOpenAccountRequirementsProps): Promise<RWAOpenAccountRequirements<P>>;
|
|
191
|
+
/**
|
|
192
|
+
* Protocol-side KYC is done: registered at Securitize for every requested
|
|
193
|
+
* DS token, or greenlisted by Midas.
|
|
194
|
+
*
|
|
195
|
+
* User might still be required to do additional actions on Gearbox side,
|
|
196
|
+
* e.g. sign EIP-712 messages for Securitize
|
|
197
|
+
*/
|
|
198
|
+
isRegistered(requirements: RWAOpenAccountRequirements<P>): boolean;
|
|
198
199
|
/**
|
|
199
|
-
*
|
|
200
|
+
* Leftover Gearbox-tx work given `providedArgs` already on the calldata.
|
|
201
|
+
* Always `undefined` for Midas (no tx args).
|
|
200
202
|
*/
|
|
201
|
-
|
|
203
|
+
getMissingRequirements(requirements: RWAOpenAccountRequirements<P>, providedArgs?: RWAOperationArgs<P>): RWAMissingOpenAccountRequirements<P> | undefined;
|
|
202
204
|
}
|
|
203
205
|
/**
|
|
204
206
|
* Narrows any contract to an {@link IRWAFactory}.
|
|
@@ -211,4 +213,4 @@ interface IDegenNFT extends IBaseContract {
|
|
|
211
213
|
**/
|
|
212
214
|
declare function isRWAFactory<T extends RWAFactoryType = RWAFactoryType>(contract: IBaseContract, type?: T): contract is IRWAFactory<T>;
|
|
213
215
|
//#endregion
|
|
214
|
-
export { GetInvestorOptions, GetOpenAccountRequirementsProps, IDegenNFT, IRWAFactory,
|
|
216
|
+
export { GetInvestorOptions, GetOpenAccountRequirementsProps, IDegenNFT, IRWAFactory, RWACompressorCall, RWACompressorInvestorData, RWACompressorResponse, RWAFactoryData, RWAFactoryProtocol, RWAFactoryStateHuman, RWAInvestorData, RWAState, RWAStateHuman, RWAUnderlyingData, isRWAFactory };
|
|
@@ -33,7 +33,11 @@ declare class MultichainOpportunitiesService<const Plugins extends PluginsMap =
|
|
|
33
33
|
*
|
|
34
34
|
* See {@link MultichainOpportunitiesService.getPool}.
|
|
35
35
|
**/
|
|
36
|
-
getStrategy(key: StrategyOpportunityKey
|
|
36
|
+
getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
|
|
37
|
+
/**
|
|
38
|
+
* {@inheritDoc OpportunitiesService.isEligibleForStrategy}
|
|
39
|
+
**/
|
|
40
|
+
isEligibleForStrategy(key: StrategyOpportunityKey, wallet: Address): Promise<boolean>;
|
|
37
41
|
}
|
|
38
42
|
//#endregion
|
|
39
43
|
export { MultichainOpportunitiesService };
|
|
@@ -34,13 +34,20 @@ declare class OpportunitiesService extends SDKConstruct {
|
|
|
34
34
|
* A single strategy opportunity plus the rate curve of the pool it borrows
|
|
35
35
|
* from and the price feeds its liquidation price depends on.
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
* with the strategy's KYC provider first; `null` otherwise.
|
|
37
|
+
* `kyc` is the strategy's KYC gate, independent of any wallet.
|
|
39
38
|
*
|
|
40
39
|
* @throws If the credit manager is unknown, or does not currently offer a
|
|
41
40
|
* strategy.
|
|
42
41
|
**/
|
|
43
|
-
getStrategy(key: StrategyOpportunityKey
|
|
42
|
+
getStrategy(key: StrategyOpportunityKey): Promise<StrategyOpportunityDetail>;
|
|
43
|
+
/**
|
|
44
|
+
* Whether `wallet` may open this strategy today: `true` when it is not
|
|
45
|
+
* KYC-gated or the wallet already passed the gate.
|
|
46
|
+
*
|
|
47
|
+
* @throws If the credit manager is unknown, or does not currently offer a
|
|
48
|
+
* strategy.
|
|
49
|
+
**/
|
|
50
|
+
isEligibleForStrategy(key: StrategyOpportunityKey, wallet: Address): Promise<boolean>;
|
|
44
51
|
}
|
|
45
52
|
//#endregion
|
|
46
53
|
export { OpportunitiesService };
|
|
@@ -22,7 +22,12 @@ interface IMultichainOpportunitiesService {
|
|
|
22
22
|
/**
|
|
23
23
|
* Detailed view of one strategy opportunity.
|
|
24
24
|
**/
|
|
25
|
-
getStrategy(key: StrategyOpportunityKey
|
|
25
|
+
getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
|
|
26
|
+
/**
|
|
27
|
+
* Whether `wallet` may open this strategy today. Throws when that chain
|
|
28
|
+
* cannot answer.
|
|
29
|
+
**/
|
|
30
|
+
isEligibleForStrategy(key: StrategyOpportunityKey, wallet: Address): Promise<boolean>;
|
|
26
31
|
}
|
|
27
32
|
//#endregion
|
|
28
33
|
export { IMultichainOpportunitiesService };
|
|
@@ -10,10 +10,10 @@ interface CheckRWAOpenRequirementsInput {
|
|
|
10
10
|
wallet: Address;
|
|
11
11
|
creditManager: Address;
|
|
12
12
|
token: Address;
|
|
13
|
-
providedArgs
|
|
13
|
+
providedArgs?: RWAOperationArgs;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* The
|
|
16
|
+
* The degen NFT is satisfied that `wallet` may open on `token` with the
|
|
17
17
|
* registration args already on the transaction.
|
|
18
18
|
*/
|
|
19
19
|
declare function checkRWAOpenRequirements(input: CheckRWAOpenRequirementsInput): Promise<(RWAOpenRequirementsError | UnexpectedFailureError)[]>;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { RWAOpenRequirementsError } from "../../../model/errors/operation-errors.js";
|
|
2
2
|
import { UnexpectedFailureError } from "../../../model/errors/prepare-errors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { OpenStrategyPositionPreview } from "../../../model/previews.js";
|
|
4
4
|
import "../../../model/index.js";
|
|
5
5
|
import { OnchainSDK } from "../../OnchainSDK.js";
|
|
6
6
|
import { Address } from "viem";
|
|
7
7
|
//#region src/onchain/validation/bundles/checkRWAOpening.d.ts
|
|
8
8
|
interface CheckRWAOpeningInput {
|
|
9
9
|
sdk: OnchainSDK;
|
|
10
|
-
preview:
|
|
10
|
+
preview: OpenStrategyPositionPreview;
|
|
11
11
|
sender: Address;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
* Per
|
|
14
|
+
* Per KYC-gated token among `collateralAdded ∪ quotas`, whether the
|
|
15
15
|
* borrower still has to register or sign before this opening can land.
|
|
16
16
|
*/
|
|
17
17
|
declare function checkRWAOpening(input: CheckRWAOpeningInput): Promise<(RWAOpenRequirementsError | UnexpectedFailureError)[]>;
|
|
@@ -1,33 +1,20 @@
|
|
|
1
1
|
import { ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { DebtOutOfRangeError, InsufficientCollateralError, QuotaCountExceededError } from "../../model/errors/operation-errors.js";
|
|
3
3
|
import "../../model/index.js";
|
|
4
|
-
import { PoolSimulation } from "../pools/types.js";
|
|
5
4
|
import { OnchainSDK } from "../OnchainSDK.js";
|
|
6
5
|
import { OperationState } from "../accounts/intents/types.js";
|
|
6
|
+
import { OpenStrategyState } from "../accounts/intents/open-strategy.js";
|
|
7
7
|
import { HealthFactorThresholds } from "./bundles/checkHealthFactors.js";
|
|
8
8
|
import { MarketStateError } from "./bundles/checkMarket.js";
|
|
9
|
-
import { PoolOperationError } from "./bundles/checkPoolOperation.js";
|
|
10
|
-
import { Address } from "viem";
|
|
11
9
|
//#region src/onchain/validation/checkSimulation.d.ts
|
|
12
10
|
/** A simulated credit operation, as the intents engine reports one. */
|
|
13
11
|
interface CreditSimulationInput {
|
|
14
12
|
chainId: ChainId;
|
|
15
|
-
state: OperationState;
|
|
13
|
+
state: OperationState | OpenStrategyState;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
* A simulated pool operation. The pool comes alongside the state, which names
|
|
19
|
-
* the tokens moving through it but not the market they belong to.
|
|
20
|
-
*/
|
|
21
|
-
interface PoolSimulationInput {
|
|
22
|
-
chainId: ChainId;
|
|
23
|
-
pool: Address;
|
|
24
|
-
state: PoolSimulation;
|
|
25
|
-
/** Whether the operation puts liquidity in rather than taking it out. */
|
|
26
|
-
isDeposit: boolean;
|
|
27
|
-
}
|
|
28
|
-
type CheckSimulationInput = CreditSimulationInput | PoolSimulationInput;
|
|
15
|
+
type CheckSimulationInput = CreditSimulationInput;
|
|
29
16
|
/** {@inheritDoc checkSimulation} */
|
|
30
|
-
type SimulationValidationError = MarketStateError | DebtOutOfRangeError | QuotaCountExceededError | InsufficientCollateralError
|
|
17
|
+
type SimulationValidationError = MarketStateError | DebtOutOfRangeError | QuotaCountExceededError | InsufficientCollateralError;
|
|
31
18
|
/**
|
|
32
19
|
* Whether a simulated operation clears the caller's own thresholds.
|
|
33
20
|
*
|
|
@@ -48,9 +35,11 @@ type SimulationValidationError = MarketStateError | DebtOutOfRangeError | QuotaC
|
|
|
48
35
|
* touched. The engine performed all three during the walk, so a simulation that
|
|
49
36
|
* came back `ok` has already passed them.
|
|
50
37
|
*
|
|
51
|
-
* A
|
|
52
|
-
*
|
|
38
|
+
* A credit account only, opened or adjusted: a pool operation has no account
|
|
39
|
+
* to weigh, and the three things its own state decides are read by `prepare`
|
|
40
|
+
* before it answers. An opening names its quotas `averageQuota` — the branch
|
|
41
|
+
* the planner already weighed it as.
|
|
53
42
|
*/
|
|
54
43
|
declare function checkSimulation(sdk: OnchainSDK, input: CheckSimulationInput, options?: HealthFactorThresholds): SimulationValidationError[];
|
|
55
44
|
//#endregion
|
|
56
|
-
export { CheckSimulationInput, CreditSimulationInput,
|
|
45
|
+
export { CheckSimulationInput, CreditSimulationInput, SimulationValidationError, checkSimulation };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Token } from "../../../model/primitives.js";
|
|
2
2
|
import { DebtOutOfRangeError } from "../../../model/errors/operation-errors.js";
|
|
3
3
|
import "../../../model/index.js";
|
|
4
|
+
import { MaxBorrowAmount } from "../../market/credit/types.js";
|
|
5
|
+
import "../../market/index.js";
|
|
4
6
|
//#region src/onchain/validation/checks/checkDebtLimits.d.ts
|
|
5
7
|
interface DebtLimitsArgs {
|
|
6
8
|
debt: bigint;
|
|
@@ -14,6 +16,8 @@ interface DebtLimitsArgs {
|
|
|
14
16
|
* rather than assumed.
|
|
15
17
|
*/
|
|
16
18
|
allowZero: boolean;
|
|
19
|
+
/** From the caller's suite; a caller that raises to throw advises nobody. */
|
|
20
|
+
maxBorrowAmount?: MaxBorrowAmount;
|
|
17
21
|
}
|
|
18
22
|
/** A debt the facade would revert on. */
|
|
19
23
|
declare function checkDebtLimits(args: DebtLimitsArgs): DebtOutOfRangeError[];
|
|
@@ -19,7 +19,7 @@ import { CheckWalletBalanceInput, checkWalletBalance } from "./bundles/checkWall
|
|
|
19
19
|
import "./bundles/index.js";
|
|
20
20
|
import { CheckLiquidationInput, CheckLiquidationOptions, LiquidationValidationError, checkLiquidation } from "./checkLiquidation.js";
|
|
21
21
|
import { CheckOperationInput, CheckOperationOptions, OperationValidationError, checkOperation } from "./checkOperation.js";
|
|
22
|
-
import { CheckSimulationInput, CreditSimulationInput,
|
|
22
|
+
import { CheckSimulationInput, CreditSimulationInput, SimulationValidationError, checkSimulation } from "./checkSimulation.js";
|
|
23
23
|
import { BorrowLimitArgs, checkBorrowLimit } from "./checks/checkBorrowLimit.js";
|
|
24
24
|
import { CollateralisedArgs, checkCollateralised } from "./checks/checkCollateralised.js";
|
|
25
25
|
import { CreditAccountFrozenArgs, checkCreditAccountFrozen } from "./checks/checkCreditAccountFrozen.js";
|
|
@@ -40,4 +40,4 @@ import { amountOf } from "./helpers/amount.js";
|
|
|
40
40
|
import { MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM } from "./helpers/health-factor-limits.js";
|
|
41
41
|
import { toToken, toTokenAmount } from "./helpers/token.js";
|
|
42
42
|
import "./helpers/index.js";
|
|
43
|
-
export { BorrowLimitArgs, CheckCollateralFundingInput, CheckLiquidationEligibilityInput, CheckLiquidationFundingInput, CheckLiquidationInput, CheckLiquidationOptions, CheckOperationInput, CheckOperationOptions, CheckPoolFundingInput, CheckRWAOpenRequirementsInput, CheckRWAOpeningInput, CheckSimulationInput, CheckWalletAllowanceInput, CheckWalletBalanceInput, CheckWalletInput, CollateralFundingPreview, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, CreditOperationArgs, CreditOperationError, CreditOperationPreview, CreditSimulationInput, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, HealthFactorThresholds, type IntentValidationError, LeverageArgs, LiquidationEligibilityError, LiquidationValidationError, LiquidatorEligibleArgs, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, MarketExpiredArgs, MarketStateError, OperationValidationError, PoolLiquidityArgs, PoolOperationArgs, PoolOperationError, PoolPausedArgs,
|
|
43
|
+
export { BorrowLimitArgs, CheckCollateralFundingInput, CheckLiquidationEligibilityInput, CheckLiquidationFundingInput, CheckLiquidationInput, CheckLiquidationOptions, CheckOperationInput, CheckOperationOptions, CheckPoolFundingInput, CheckRWAOpenRequirementsInput, CheckRWAOpeningInput, CheckSimulationInput, CheckWalletAllowanceInput, CheckWalletBalanceInput, CheckWalletInput, CollateralFundingPreview, CollateralisedArgs, CreditAccountFrozenArgs, CreditManagerPausedArgs, CreditOperationArgs, CreditOperationError, CreditOperationPreview, CreditSimulationInput, DebtLimitsArgs, EmergencyLiquidatorArgs, ForbiddenTokenArgs, HealthFactorThresholds, type IntentValidationError, LeverageArgs, LiquidationEligibilityError, LiquidationValidationError, LiquidatorEligibleArgs, MIN_HEALTH_FACTOR_FACADE, MIN_HEALTH_FACTOR_FORM, MIN_HF_LIMITED, MIN_SAFE_HEALTH_FACTOR_FORM, MarketExpiredArgs, MarketStateError, OperationValidationError, PoolLiquidityArgs, PoolOperationArgs, PoolOperationError, PoolPausedArgs, PoolSunsetArgs, QuotaCountArgs, QuotaLimitArgs, SimulationValidationError, WalletFundingError, WeighedFactors, amountOf, checkAccountQuotas, checkBorrowLimit, checkCollateralFunding, checkCollateralised, checkCreditAccountFrozen, checkCreditManagerPaused, checkCreditOperation, checkDebtLimits, checkDraw, checkEmergencyLiquidator, checkForbiddenToken, checkHealthFactors, checkLeverage, checkLiquidation, checkLiquidationEligibility, checkLiquidationFunding, checkLiquidatorEligible, checkMarket, checkMarketExpired, checkObtained, checkOperation, checkPoolFunding, checkPoolLiquidity, checkPoolOperation, checkPoolPaused, checkPoolSunset, checkQuotaCount, checkQuotaLimit, checkQuotasAsked, checkRWAOpenRequirements, checkRWAOpening, checkSimulation, checkWallet, checkWalletAllowance, checkWalletBalance, raise, toToken, toTokenAmount };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { CreditAccountNotEmptyError, CreditAccountNotFoundError,
|
|
1
|
+
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure } from "../model/errors/prepare-errors.js";
|
|
2
2
|
import { LeverageBand } from "../onchain/accounts/intents/leverage-band.js";
|
|
3
3
|
import { OperationState, PathLossRate, RouteErrors, WithdrawCeilings } from "../onchain/accounts/intents/types.js";
|
|
4
|
+
import { PoolOperationError } from "../onchain/validation/bundles/checkPoolOperation.js";
|
|
4
5
|
import { IAnalytics, IAnalyticsByMode } from "./analytics/types.js";
|
|
5
6
|
import { ILiquidations, ILiquidationsByMode } from "./liquidations/types.js";
|
|
6
|
-
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
7
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
7
8
|
import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
|
|
8
9
|
import "./prepare/index.js";
|
|
9
10
|
import { AccountPrepareRequest, IOpportunitiesExecute, OpenPrepareRequest, PoolPrepareRequest, PrepareRequest } from "./execute/types.js";
|
|
@@ -37,4 +38,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
37
38
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
38
39
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
39
40
|
import "./errors/index.js";
|
|
40
|
-
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, ChainOf, ChainRef, CheckOperationProps, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategyResult, DepositStrategyParams,
|
|
41
|
+
export { AbstractNamespace, AccountFlowError, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, AnalyticsNamespace, ChainOf, ChainRef, CheckOperationProps, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, DelayedStrategyResult, DepositStrategyParams, EnsureFreshChains, type EntityMerger, ExecuteApi, type FilterResult, FinalizeParams, FinalizeResult, GearboxSDK, GearboxSDKOptions, IAnalytics, IAnalyticsByMode, IGearboxSDK, ILiquidations, ILiquidationsByMode, INotices, INoticesByMode, IOpportunities, IOpportunitiesBase, IOpportunitiesByMode, IOpportunitiesExecute, IOpportunitiesOffchainBranch, IOpportunitiesOffchainOnly, IOpportunitiesOnchainBranch, IOpportunitiesOnchainOnly, IOpportunitiesPrepare, IOpportunityMergers, IPositionMergers, IPositions, IPositionsBase, IPositionsByMode, IPositionsOffchainBranch, IPositionsOffchainOnly, IPositionsOnchainBranch, IPositionsOnchainOnly, IPreview, IPreviewByMode, type LeverageBand, LiquidationsNamespace, type ListMerger, LpParams, LpRedeemParams, LpResult, LpState, type MergeListResult, MergedQuery, MissingSourceError, Mode, type MultipleDelayedWithdrawalsError, NamespaceOptions, type NoDelayedRouteError, type NoRecordedIntentError, NoSourceServedError, type NoStrategyTargetCollateralError, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenFlowError, OpenPrepareRequest, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, type OperationState, OpportunitiesNamespace, type PathLossRate, PlainMultichainSDKOptions, PoolInput, type PoolOperationError, PoolPrepareRequest, PositionInput, PositionsNamespace, PrepareApi, PrepareOptions, PrepareRequest, PreviewNamespace, RepayStrategyParams, type RouteErrors, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, assertSameChains, creditAccountNotEmpty, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, unexpectedFailure };
|
|
@@ -47,7 +47,11 @@ declare class OpportunitiesNamespace extends AbstractNamespace<MultichainSDK["op
|
|
|
47
47
|
/**
|
|
48
48
|
* {@inheritDoc IOpportunitiesBase.getStrategy}
|
|
49
49
|
**/
|
|
50
|
-
getStrategy(key: StrategyOpportunityKey
|
|
50
|
+
getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
|
|
51
|
+
/**
|
|
52
|
+
* {@inheritDoc IOpportunitiesOnchainOnly.isEligibleForStrategy}
|
|
53
|
+
**/
|
|
54
|
+
isEligibleForStrategy(key: StrategyOpportunityKey, wallet: Address): Promise<boolean>;
|
|
51
55
|
/**
|
|
52
56
|
* {@inheritDoc IOpportunitiesBase.filter}
|
|
53
57
|
**/
|
|
@@ -30,10 +30,11 @@ interface IOpportunitiesBase {
|
|
|
30
30
|
**/
|
|
31
31
|
getPool(key: PoolOpportunityKey): Promise<DataResponse<PoolOpportunityDetail>>;
|
|
32
32
|
/**
|
|
33
|
-
* Detailed view of one strategy opportunity.
|
|
34
|
-
*
|
|
33
|
+
* Detailed view of one strategy opportunity. `kyc` is the strategy's KYC
|
|
34
|
+
* gate, independent of any wallet. Use {@link IOpportunitiesOnchainOnly.isEligibleForStrategy}
|
|
35
|
+
* for a wallet verdict.
|
|
35
36
|
**/
|
|
36
|
-
getStrategy(key: StrategyOpportunityKey
|
|
37
|
+
getStrategy(key: StrategyOpportunityKey): Promise<DataResponse<StrategyOpportunityDetail>>;
|
|
37
38
|
/**
|
|
38
39
|
* Narrows an already-read list, rows and metadata alike. `undefined` passes
|
|
39
40
|
* through, so a read still in flight stays that way, and a list already read
|
|
@@ -88,6 +89,11 @@ interface IOpportunitiesOnchainOnly {
|
|
|
88
89
|
* same reason as {@link prepare}: it encodes against live chain state.
|
|
89
90
|
**/
|
|
90
91
|
readonly execute: IOpportunitiesExecute;
|
|
92
|
+
/**
|
|
93
|
+
* Whether `wallet` may open this strategy today: `true` when it is not
|
|
94
|
+
* KYC-gated or the wallet already passed the gate. Chain-only.
|
|
95
|
+
**/
|
|
96
|
+
isEligibleForStrategy(key: StrategyOpportunityKey, wallet: Address): Promise<boolean>;
|
|
91
97
|
}
|
|
92
98
|
/**
|
|
93
99
|
* The chain on its own, for a consumer that shows each source as it arrives.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bps, ChainId } from "../../model/primitives.js";
|
|
2
2
|
import { DebtOutOfRangeError, InsufficientPoolLiquidityError, LeverageOutOfRangeError } from "../../model/errors/operation-errors.js";
|
|
3
|
-
import { CreditAccountNotEmptyError, CreditAccountNotFoundError,
|
|
3
|
+
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
|
|
4
4
|
import { PositionCollateral, StrategyPosition } from "../../model/positions.js";
|
|
5
5
|
import { SDKReturn } from "../../model/result.js";
|
|
6
6
|
import "../../model/index.js";
|
|
@@ -10,6 +10,7 @@ import { MultichainSDK } from "../../onchain/MultichainSDK.js";
|
|
|
10
10
|
import { MultichainConstruct } from "../../onchain/base/MultichainConstruct.js";
|
|
11
11
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
12
12
|
import { WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
|
|
13
|
+
import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
13
14
|
import "../../onchain/index.js";
|
|
14
15
|
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, OpenFlowError, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
15
16
|
import { EnsureFreshChains } from "../types.js";
|
|
@@ -54,19 +55,19 @@ declare class PrepareApi extends MultichainConstruct implements IOpportunitiesPr
|
|
|
54
55
|
/**
|
|
55
56
|
* {@inheritDoc IOpportunitiesPrepare.deposit}
|
|
56
57
|
**/
|
|
57
|
-
deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
58
|
+
deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
58
59
|
/**
|
|
59
60
|
* {@inheritDoc IOpportunitiesPrepare.withdraw}
|
|
60
61
|
**/
|
|
61
|
-
withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
62
|
+
withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
62
63
|
/**
|
|
63
64
|
* {@inheritDoc IOpportunitiesPrepare.redeem}
|
|
64
65
|
**/
|
|
65
|
-
redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
66
|
+
redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
66
67
|
/**
|
|
67
68
|
* {@inheritDoc IOpportunitiesPrepare.openNewStrategy}
|
|
68
69
|
**/
|
|
69
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError |
|
|
70
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
|
|
70
71
|
/**
|
|
71
72
|
* {@inheritDoc IOpportunitiesPrepare.depositStrategy}
|
|
72
73
|
**/
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { CreditAccountNotEmptyError, CreditAccountNotFoundError,
|
|
1
|
+
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure } from "../../model/errors/prepare-errors.js";
|
|
2
2
|
import "../../model/index.js";
|
|
3
3
|
import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
4
4
|
import { OperationState, PathLossRate, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
|
|
5
|
-
import {
|
|
5
|
+
import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
6
|
+
import { AccountFlowError, AddCollateralParams, AdjustLeverageParams, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, LpParams, LpRedeemParams, LpResult, LpState, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyResult, StrategyRoutesResult, WithRouteErrors, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
6
7
|
import { ChainOf, PrepareApi } from "./PrepareApi.js";
|
|
7
|
-
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams,
|
|
8
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, ChainOf, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareApi, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError, creditAccountNotEmpty, creditAccountNotFound, noStrategyTargetCollateral, unexpectedFailure };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bps, Timestamp, TokenAmount } from "../../model/primitives.js";
|
|
2
2
|
import { Curator } from "../../model/curators.js";
|
|
3
3
|
import { CreditManagerPausedError, DebtOutOfRangeError, ForbiddenTokenError, InsufficientBalanceError, InsufficientCollateralError, InsufficientPoolLiquidityError, LeverageOutOfRangeError, MarketExpiredError, QuotaLimitReachedError } from "../../model/errors/operation-errors.js";
|
|
4
|
-
import { CreditAccountNotEmptyError, CreditAccountNotFoundError,
|
|
4
|
+
import { CreditAccountNotEmptyError, CreditAccountNotFoundError, MultipleDelayedWithdrawalsError, NoDelayedRouteError, NoRecordedIntentError, NoStrategyTargetCollateralError, UnexpectedFailureError, UnsupportedCollateralTokenError, UnsupportedTokenPairError, WithdrawalInProgressError } from "../../model/errors/prepare-errors.js";
|
|
5
5
|
import { PoolOpportunityKey, StrategyOpportunityKey } from "../../model/opportunities.js";
|
|
6
6
|
import { PositionCollateral, StrategyPosition, StrategyPositionKey } from "../../model/positions.js";
|
|
7
7
|
import { SDKReturn } from "../../model/result.js";
|
|
@@ -14,6 +14,7 @@ import { LeverageBand } from "../../onchain/accounts/intents/leverage-band.js";
|
|
|
14
14
|
import { AccountCalculatorOperation } from "../../onchain/accounts/intents/operations.js";
|
|
15
15
|
import { ClaimRemainder, DelayedStart, OperationState, PathLossRate, ResumableIntent, RouteErrors, WithdrawCeilings } from "../../onchain/accounts/intents/types.js";
|
|
16
16
|
import { OpenStrategyState } from "../../onchain/accounts/intents/open-strategy.js";
|
|
17
|
+
import { PoolOperationError } from "../../onchain/validation/bundles/checkPoolOperation.js";
|
|
17
18
|
import "../../onchain/index.js";
|
|
18
19
|
import { Address } from "viem";
|
|
19
20
|
//#region src/sdk/prepare/types.d.ts
|
|
@@ -337,7 +338,15 @@ interface WithdrawCollateralParams extends PrepareOptions {
|
|
|
337
338
|
/** Wallet receiving the tokens. */
|
|
338
339
|
to: Address;
|
|
339
340
|
}
|
|
340
|
-
|
|
341
|
+
/**
|
|
342
|
+
* Opening a position, in one of the two shapes an opening comes in.
|
|
343
|
+
*
|
|
344
|
+
* The union is the check: an empty opening names nothing to open with, so
|
|
345
|
+
* collateral it meant to spend or an account it meant to reuse cannot be
|
|
346
|
+
* silently dropped — those arguments do not typecheck against `empty: true`.
|
|
347
|
+
**/
|
|
348
|
+
type OpenStrategyParams = OpenStrategyFundedParams | OpenStrategyEmptyParams;
|
|
349
|
+
interface OpenStrategyFundedParams extends PrepareOptions {
|
|
341
350
|
/** Collateral coming from the wallet, in their own tokens. */
|
|
342
351
|
collateral: Asset[];
|
|
343
352
|
/**
|
|
@@ -355,25 +364,42 @@ interface OpenStrategyParams extends PrepareOptions {
|
|
|
355
364
|
* Existing credit account to open the position on, instead of creating one.
|
|
356
365
|
*
|
|
357
366
|
* Must belong to `strategy.creditManager` and carry no debt and no quotas —
|
|
358
|
-
* an account pre-opened by an {@link
|
|
367
|
+
* an account pre-opened by an {@link OpenStrategyEmptyParams} opening.
|
|
359
368
|
* The projection is identical either way; only the transaction differs, and
|
|
360
369
|
* `execute.buildTx` reads which one to build off the result's own
|
|
361
370
|
* `state.creditAccount`.
|
|
362
371
|
**/
|
|
363
372
|
creditAccount?: Address;
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
373
|
+
empty?: false;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Opening an account that holds nothing: no collateral, no debt, no quotas, and
|
|
377
|
+
* no route quoted. A wallet holds one so a position can be put on it later, by
|
|
378
|
+
* an opening that names it as
|
|
379
|
+
* {@link OpenStrategyFundedParams.creditAccount}.
|
|
380
|
+
*
|
|
381
|
+
* The market is the whole request. There is nothing else to say: with no
|
|
382
|
+
* collateral the debt is zero at any leverage, and there is nothing to route
|
|
383
|
+
* anywhere — so leverage and a target token are not merely ignored here, they
|
|
384
|
+
* cannot be named.
|
|
385
|
+
**/
|
|
386
|
+
interface OpenStrategyEmptyParams {
|
|
387
|
+
empty: true;
|
|
388
|
+
/**
|
|
389
|
+
* The three an empty opening would otherwise have to drop, spelled out as
|
|
390
|
+
* `never` rather than merely left out.
|
|
391
|
+
*
|
|
392
|
+
* A bare `{ empty: true }` is a structural type, and excess-property checking
|
|
393
|
+
* only fires on a fresh object literal — so params built up in a variable, as
|
|
394
|
+
* a form builds them, would pass on the extra members and have them silently
|
|
395
|
+
* dropped. Naming them closes that: the shape is refused wherever it is
|
|
396
|
+
* written, and `empty` typed as a plain `boolean` is refused by both branches.
|
|
397
|
+
**/
|
|
398
|
+
collateral?: never;
|
|
399
|
+
leverage?: never;
|
|
400
|
+
creditAccount?: never;
|
|
401
|
+
targetToken?: never;
|
|
402
|
+
leftoverBalances?: never;
|
|
377
403
|
}
|
|
378
404
|
interface LpParams {
|
|
379
405
|
/**
|
|
@@ -460,7 +486,7 @@ interface IOpportunitiesPrepare {
|
|
|
460
486
|
* loaded already; the wait is for the one thing that is not, the shares the
|
|
461
487
|
* wallet holds, without which {@link LpState.netValue} cannot be said.
|
|
462
488
|
**/
|
|
463
|
-
deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
489
|
+
deposit(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
464
490
|
/**
|
|
465
491
|
* Taking underlying out of a pool: `amount` is the `tokenOut` the wallet
|
|
466
492
|
* wants back, and the pool burns whatever shares that costs.
|
|
@@ -468,19 +494,19 @@ interface IOpportunitiesPrepare {
|
|
|
468
494
|
* The LP counterpart of {@link withdrawStrategy} / {@link withdrawCollateral},
|
|
469
495
|
* which act on credit accounts.
|
|
470
496
|
**/
|
|
471
|
-
withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
497
|
+
withdraw(pool: PoolInput, params: LpParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
472
498
|
/**
|
|
473
499
|
* Redeeming pool shares: `amount` is the `tokenIn` the wallet parts with,
|
|
474
500
|
* and the reported state is the underlying it converts to.
|
|
475
501
|
**/
|
|
476
|
-
redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError>>;
|
|
502
|
+
redeem(pool: PoolInput, params: LpRedeemParams): Promise<SDKReturn<LpResult, UnsupportedTokenPairError | UnexpectedFailureError | PoolOperationError>>;
|
|
477
503
|
/**
|
|
478
504
|
* Opening a leveraged position from wallet collateral.
|
|
479
505
|
*
|
|
480
506
|
* The one flow with no account yet, so the result carries no operation list —
|
|
481
507
|
* it feeds `sdk.accounts.openCA` instead.
|
|
482
508
|
**/
|
|
483
|
-
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError |
|
|
509
|
+
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<SDKReturn<OpenStrategyResult, OpenFlowError | DebtOutOfRangeError | LeverageOutOfRangeError | UnsupportedTokenPairError | InsufficientPoolLiquidityError | NoStrategyTargetCollateralError | CreditAccountNotFoundError | CreditAccountNotEmptyError>>;
|
|
484
510
|
/**
|
|
485
511
|
* Growing a position: collateral in, debt drawn on top, both converted into
|
|
486
512
|
* the position token.
|
|
@@ -662,4 +688,4 @@ interface IOpportunitiesPrepare {
|
|
|
662
688
|
finalize(position: PositionInput, params: FinalizeParams): Promise<SDKReturn<FinalizeResult, AccountFlowError | NoRecordedIntentError | NoDelayedRouteError | WithdrawalInProgressError | UnsupportedTokenPairError>>;
|
|
663
689
|
}
|
|
664
690
|
//#endregion
|
|
665
|
-
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams,
|
|
691
|
+
export { AccountFlowError, AddCollateralParams, AdjustLeverageParams, type CreditAccountNotEmptyError, type CreditAccountNotFoundError, DelayedStrategyResult, DepositStrategyParams, FinalizeParams, FinalizeResult, IOpportunitiesPrepare, type LeverageBand, LpParams, LpRedeemParams, LpResult, LpState, type MultipleDelayedWithdrawalsError, type NoDelayedRouteError, type NoRecordedIntentError, type NoStrategyTargetCollateralError, OpenFlowError, OpenStrategyEmptyParams, OpenStrategyFundedParams, OpenStrategyParams, OpenStrategyResult, type OperationState, type PathLossRate, PoolInput, type PoolOperationError, PositionInput, PrepareOptions, RepayStrategyParams, type RouteErrors, StrategyInput, StrategyResult, StrategyRoutesResult, type UnexpectedFailureError, type UnsupportedCollateralTokenError, type UnsupportedTokenPairError, WithRouteErrors, type WithdrawCeilings, WithdrawCollateralParams, WithdrawStrategyParams, type WithdrawalInProgressError };
|