@gearbox-protocol/sdk 15.1.0-next.12 → 15.1.0-next.13
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/new-sdk/index.js +3 -3
- package/dist/cjs/new-sdk/opportunities/OpportunitiesNamespace.js +8 -8
- package/dist/cjs/new-sdk/{simulate/SimulateApi.js → prepare/PrepareApi.js} +21 -49
- package/dist/cjs/new-sdk/prepare/index.js +4 -0
- package/dist/esm/common-utils/index.js +3 -3
- package/dist/esm/common-utils/utils/index.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/new-sdk/index.js +3 -3
- package/dist/esm/new-sdk/opportunities/OpportunitiesNamespace.js +8 -8
- package/dist/esm/new-sdk/{simulate/SimulateApi.js → prepare/PrepareApi.js} +21 -49
- package/dist/esm/new-sdk/prepare/index.js +3 -0
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +1 -1
- package/dist/esm/plugins/apy/ApyPlugin.js +2 -2
- package/dist/esm/preview/simulate/simulatePoolOperation.js +1 -1
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV310Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.js +1 -1
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +1 -1
- package/dist/esm/sdk/base/TokensMeta.js +3 -3
- package/dist/esm/sdk/chain/detectNetwork.js +1 -1
- package/dist/esm/sdk/core/createAddressProvider.js +1 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +1 -1
- package/dist/esm/sdk/market/pool/PoolV310Contract.js +1 -1
- package/dist/esm/sdk/market/zapper/IETHZapperContract.js +1 -1
- package/dist/esm/sdk/market/zapper/ZapperContract.js +1 -1
- package/dist/esm/sdk/pools/PoolService.js +1 -1
- package/dist/esm/sdk/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/types/new-sdk/execute/ExecuteApi.d.ts +9 -9
- package/dist/types/new-sdk/index.d.ts +4 -4
- package/dist/types/new-sdk/opportunities/OpportunitiesNamespace.d.ts +4 -4
- package/dist/types/new-sdk/opportunities/types.d.ts +5 -5
- package/dist/types/new-sdk/{simulate/SimulateApi.d.ts → prepare/PrepareApi.d.ts} +19 -19
- package/dist/types/new-sdk/prepare/index.d.ts +3 -0
- package/dist/types/new-sdk/{simulate → prepare}/types.d.ts +35 -61
- package/dist/types/sdk/accounts/intents/testing/sdk-mock.d.ts +1 -1
- package/dist/types/sdk/accounts/intents/types.d.ts +12 -12
- package/package.json +1 -1
- package/dist/cjs/new-sdk/simulate/index.js +0 -4
- package/dist/esm/new-sdk/simulate/index.js +0 -3
- package/dist/types/new-sdk/simulate/index.d.ts +0 -3
- /package/dist/cjs/new-sdk/{simulate → prepare}/types.js +0 -0
- /package/dist/esm/new-sdk/{simulate → prepare}/types.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
2
1
|
import { AbstractWithdrawalCompressorContract } from "./AbstractWithdrawalCompressorContract.js";
|
|
2
|
+
import { iWithdrawalCompressorV311Abi } from "../../../abi/IWithdrawalCompressorV311.js";
|
|
3
3
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV311Contract.ts
|
|
4
4
|
const abi = iWithdrawalCompressorV311Abi;
|
|
5
5
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
2
1
|
import { encodeDelayedIntent } from "./intent-codec.js";
|
|
3
2
|
import { AbstractWithdrawalCompressorContract, iCreditAccountAbi, toClaimableWithdrawal, toPendingWithdrawal, toRequestableWithdrawal } from "./AbstractWithdrawalCompressorContract.js";
|
|
3
|
+
import { iWithdrawalCompressorV313Abi } from "../../../abi/IWithdrawalCompressorV313.js";
|
|
4
4
|
import { toWithdrawalStatus } from "./types.js";
|
|
5
5
|
//#region src/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.ts
|
|
6
6
|
const abi = iWithdrawalCompressorV313Abi;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
2
|
-
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
3
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
4
1
|
import { AddressMap } from "../utils/AddressMap.js";
|
|
5
2
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
6
3
|
import { bytes32ToString } from "../utils/bytes32ToString.js";
|
|
7
4
|
import { getAssetType } from "../chain/chains.js";
|
|
8
5
|
import { formatBN } from "../utils/formatter.js";
|
|
9
6
|
import "../utils/index.js";
|
|
7
|
+
import { iExpirableAbi } from "../../abi/iExpirable.js";
|
|
8
|
+
import { iStateSerializerAbi } from "../../abi/iStateSerializer.js";
|
|
9
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
10
10
|
import { executeMulticallBatches } from "../utils/viem/executeMulticallBatches.js";
|
|
11
11
|
//#region src/sdk/base/TokensMeta.ts
|
|
12
12
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
2
1
|
import { AP_MARKET_COMPRESSOR, AP_PRICE_FEED_COMPRESSOR } from "../constants/address-provider.js";
|
|
3
2
|
import { isV310 } from "../constants/versions.js";
|
|
4
3
|
import "../constants/index.js";
|
|
5
4
|
import { hexEq } from "../utils/hex.js";
|
|
5
|
+
import { iVersionAbi } from "../../abi/iVersion.js";
|
|
6
6
|
import { AddressProviderV310Contract } from "./AddressProviderV310Contract.js";
|
|
7
7
|
//#region src/sdk/core/createAddressProvider.ts
|
|
8
8
|
const OVERRIDE_ADDRESSES = { Mainnet: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iCreditFacadeMulticallV310Abi, iCreditFacadeV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
4
3
|
import "../../base/index.js";
|
|
4
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
5
5
|
//#region src/sdk/market/credit/CreditFacadeV310BaseContract.ts
|
|
6
6
|
const abi = [
|
|
7
7
|
...iCreditFacadeV310Abi,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../../abi/310/generated.js";
|
|
3
2
|
import { AddressMap } from "../../utils/AddressMap.js";
|
|
4
3
|
import { RAY } from "../../constants/math.js";
|
|
@@ -7,6 +6,7 @@ import { formatBN, formatBNvalue, percentFmt } from "../../utils/formatter.js";
|
|
|
7
6
|
import "../../utils/index.js";
|
|
8
7
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
9
8
|
import "../../base/index.js";
|
|
9
|
+
import { iPausableAbi } from "../../../abi/iPausable.js";
|
|
10
10
|
import { calcUtilization } from "../math.js";
|
|
11
11
|
//#region src/sdk/market/pool/PoolV310Contract.ts
|
|
12
12
|
const abi = [...iPoolV310Abi, ...iPausableAbi];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
2
|
+
import { iethZapperAbi } from "../../../abi/iETHZapper.js";
|
|
3
3
|
//#region src/sdk/market/zapper/IETHZapperContract.ts
|
|
4
4
|
const abi = iethZapperAbi;
|
|
5
5
|
var IETHZapperContract = class extends ZapperContract {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
2
1
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
2
|
import "../../base/index.js";
|
|
3
|
+
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
4
4
|
import { UnsupportedZapperFunctionError } from "./errors.js";
|
|
5
5
|
//#region src/sdk/market/zapper/ZapperContract.ts
|
|
6
6
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { AddressSet } from "../utils/AddressSet.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import "../constants/addresses.js";
|
|
4
4
|
import { PERCENTAGE_FACTOR, RAY } from "../constants/math.js";
|
|
5
5
|
import "../constants/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { errorAbis } from "../../../abi/errors.js";
|
|
2
|
-
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
3
2
|
import { generateCastTraceCall } from "./cast.js";
|
|
3
|
+
import { iUpdatablePriceFeedAbi } from "../../../abi/iUpdatablePriceFeed.js";
|
|
4
4
|
import { simulateMulticall } from "./simulateMulticall.js";
|
|
5
5
|
import { BaseError, CallExecutionError, ContractFunctionRevertedError, decodeFunctionData, decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
|
|
6
6
|
import { getAction, parseAccount } from "viem/utils";
|
|
@@ -4,15 +4,15 @@ import "../../model/index.js";
|
|
|
4
4
|
import { SecuritizeRegisterMessage } from "../../sdk/market/rwa/securitize/types.js";
|
|
5
5
|
import { RawTx } from "../../sdk/types/transactions.js";
|
|
6
6
|
import "../../sdk/index.js";
|
|
7
|
-
import { LpSimulate, OpenStrategySimulate, StrategySimulate } from "../
|
|
8
|
-
import { ChainOf } from "../
|
|
9
|
-
import "../
|
|
7
|
+
import { LpSimulate, OpenStrategySimulate, StrategySimulate } from "../prepare/types.js";
|
|
8
|
+
import { ChainOf } from "../prepare/PrepareApi.js";
|
|
9
|
+
import "../prepare/index.js";
|
|
10
10
|
import { Address } from "viem";
|
|
11
11
|
//#region src/new-sdk/execute/ExecuteApi.d.ts
|
|
12
12
|
/**
|
|
13
13
|
* A pool deposit, withdrawal or redemption, as
|
|
14
|
-
* {@link
|
|
15
|
-
* / {@link
|
|
14
|
+
* {@link OpportunitiesPrepare.deposit} / {@link OpportunitiesPrepare.withdraw}
|
|
15
|
+
* / {@link OpportunitiesPrepare.redeem} priced it. The simulation carries the
|
|
16
16
|
* tokens on both sides and the zapper, so nothing else is needed to encode
|
|
17
17
|
* the call.
|
|
18
18
|
**/
|
|
@@ -28,7 +28,7 @@ interface PoolPrepareRequest {
|
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Opening a new position, from a viable
|
|
31
|
-
* {@link
|
|
31
|
+
* {@link OpportunitiesPrepare.openNewStrategy} result. The preview values
|
|
32
32
|
* collateral in underlying only, so the wallet's actual collateral assets and
|
|
33
33
|
* the native value to attach come from the caller.
|
|
34
34
|
**/
|
|
@@ -70,19 +70,19 @@ interface AccountPrepareRequest {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* What {@link OpportunitiesExecute.buildTx} turns into a transaction: a
|
|
73
|
-
*
|
|
73
|
+
* `prepare` result plus the few facts about the wallet the simulation does not
|
|
74
74
|
* carry.
|
|
75
75
|
**/
|
|
76
76
|
type PrepareRequest = PoolPrepareRequest | OpenPrepareRequest | AccountPrepareRequest;
|
|
77
77
|
/**
|
|
78
|
-
* The write side of the opportunities namespace: turns what `
|
|
78
|
+
* The write side of the opportunities namespace: turns what `prepare`
|
|
79
79
|
* answered into the transaction to sign. Sending, and whatever the wallet has
|
|
80
80
|
* to do first (allowances, permits, RWA signatures), stays with the caller —
|
|
81
81
|
* `checkPrerequisites` reports the former on the built transaction.
|
|
82
82
|
**/
|
|
83
83
|
interface OpportunitiesExecute {
|
|
84
84
|
/**
|
|
85
|
-
* The transaction to sign, from a
|
|
85
|
+
* The transaction to sign, from a `prepare` result. No second round of math:
|
|
86
86
|
* `account` requests submit the simulation's own multicall, `open` requests
|
|
87
87
|
* hand the preview's router path and quotas to `openCA`, `pool` requests
|
|
88
88
|
* encode the deposit / redeem the simulation priced.
|
|
@@ -4,9 +4,9 @@ import { filterResponse } from "./utils/filterResponse.js";
|
|
|
4
4
|
import { DEFAULT_MAX_OFFCHAIN_LAG, mergeChainList, mergeChainOne } from "./utils/mergeChains.js";
|
|
5
5
|
import "./utils/index.js";
|
|
6
6
|
import { AbstractNamespace, MergedQuery } from "./AbstractNamespace.js";
|
|
7
|
-
import { AddCollateralParams, AdjustLeverageParams,
|
|
8
|
-
import { ChainOf,
|
|
9
|
-
import "./
|
|
7
|
+
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./prepare/types.js";
|
|
8
|
+
import { ChainOf, PrepareApi } from "./prepare/PrepareApi.js";
|
|
9
|
+
import "./prepare/index.js";
|
|
10
10
|
import { AccountPrepareRequest, ExecuteApi, OpenPrepareRequest, OpportunitiesExecute, PoolPrepareRequest, PrepareRequest } from "./execute/ExecuteApi.js";
|
|
11
11
|
import "./execute/index.js";
|
|
12
12
|
import { Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesMerged, OpportunitiesOffchainBranch, OpportunitiesOffchainOnly, OpportunitiesOnchainBranch, OpportunitiesOnchainOnly, OpportunityMergers } from "./opportunities/types.js";
|
|
@@ -24,4 +24,4 @@ import { SourceUnavailableError } from "./errors/SourceUnavailableError.js";
|
|
|
24
24
|
import { assertSameChains } from "./errors/assertSameChains.js";
|
|
25
25
|
import { everyChainFailed } from "./errors/everyChainFailed.js";
|
|
26
26
|
import "./errors/index.js";
|
|
27
|
-
export { AbstractNamespace, AccountPrepareRequest, AddCollateralParams, AdjustLeverageParams, AllSourcesFailedError, ChainOf, ChainRef, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE,
|
|
27
|
+
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 ListMerger, LpParams, LpRedeemParams, LpSimulate, type MergeListResult, MergedQuery, MissingSourceError, Mode, NamespaceOptions, NoSourceServedError, NoticesByMode, OffchainByMode, OffchainSource, OnchainByMode, OnchainSource, OpenPrepareRequest, OpenStrategyParams, OpenStrategySimulate, Opportunities, OpportunitiesBase, OpportunitiesByMode, OpportunitiesExecute, OpportunitiesMerged, OpportunitiesNamespace, OpportunitiesOffchainBranch, OpportunitiesOffchainOnly, OpportunitiesOnchainBranch, OpportunitiesOnchainOnly, OpportunitiesPrepare, OpportunityMergers, PlainMultichainSDKOptions, PoolInput, PoolPrepareRequest, PositionInput, PositionMergers, Positions, PositionsBase, PositionsByMode, PositionsMerged, PositionsNamespace, PositionsOffchainBranch, PositionsOffchainOnly, PositionsOnchainBranch, PositionsOnchainOnly, PrepareApi, PrepareOptions, PrepareRequest, RepayStrategyParams, SourceChainMismatchError, SourceUnavailableError, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams, assertSameChains, everyChainFailed, filterResponse, mergeChainList, mergeChainOne };
|
|
@@ -10,8 +10,8 @@ import { NamespaceOptions } from "../types.js";
|
|
|
10
10
|
import { FilterResult } from "../utils/types.js";
|
|
11
11
|
import "../utils/index.js";
|
|
12
12
|
import { AbstractNamespace } from "../AbstractNamespace.js";
|
|
13
|
-
import {
|
|
14
|
-
import "../
|
|
13
|
+
import { OpportunitiesPrepare } from "../prepare/types.js";
|
|
14
|
+
import "../prepare/index.js";
|
|
15
15
|
import { OpportunitiesExecute } from "../execute/ExecuteApi.js";
|
|
16
16
|
import "../execute/index.js";
|
|
17
17
|
import { OpportunitiesBase, OpportunitiesOffchainOnly, OpportunitiesOnchainOnly, OpportunityMergers } from "./types.js";
|
|
@@ -28,9 +28,9 @@ declare class OpportunitiesNamespace extends AbstractNamespace<MultichainSDK["op
|
|
|
28
28
|
readonly merge: OpportunityMergers;
|
|
29
29
|
constructor(onchain: MultichainSDK | undefined, offchain: GearboxAPI | undefined, options: NamespaceOptions);
|
|
30
30
|
/**
|
|
31
|
-
* {@inheritDoc OpportunitiesOnchainOnly.
|
|
31
|
+
* {@inheritDoc OpportunitiesOnchainOnly.prepare}
|
|
32
32
|
**/
|
|
33
|
-
get
|
|
33
|
+
get prepare(): OpportunitiesPrepare;
|
|
34
34
|
/**
|
|
35
35
|
* {@inheritDoc OpportunitiesOnchainOnly.execute}
|
|
36
36
|
**/
|
|
@@ -9,8 +9,8 @@ import "../../offchain/index.js";
|
|
|
9
9
|
import { Mode } from "../types.js";
|
|
10
10
|
import { EntityMerger, FilterResult, ListMerger } from "../utils/types.js";
|
|
11
11
|
import "../utils/index.js";
|
|
12
|
-
import {
|
|
13
|
-
import "../
|
|
12
|
+
import { OpportunitiesPrepare } from "../prepare/types.js";
|
|
13
|
+
import "../prepare/index.js";
|
|
14
14
|
import { OpportunitiesExecute } from "../execute/ExecuteApi.js";
|
|
15
15
|
import "../execute/index.js";
|
|
16
16
|
//#region src/new-sdk/opportunities/types.d.ts
|
|
@@ -80,11 +80,11 @@ interface OpportunitiesOnchainOnly {
|
|
|
80
80
|
* state, and the strategy flows additionally need the pathfinder for real swap
|
|
81
81
|
* paths, so there is nothing the backend could answer with.
|
|
82
82
|
**/
|
|
83
|
-
readonly
|
|
83
|
+
readonly prepare: OpportunitiesPrepare;
|
|
84
84
|
/**
|
|
85
|
-
* The transaction a
|
|
85
|
+
* The transaction a prepared operation stands for, see
|
|
86
86
|
* {@link OpportunitiesExecute.buildTx}. Absent in `offchain` mode for the
|
|
87
|
-
* same reason as {@link
|
|
87
|
+
* same reason as {@link prepare}: it encodes against live chain state.
|
|
88
88
|
**/
|
|
89
89
|
execute: OpportunitiesExecute;
|
|
90
90
|
}
|
|
@@ -6,8 +6,8 @@ import { MultichainSDK } from "../../sdk/MultichainSDK.js";
|
|
|
6
6
|
import { ChainQueryOneProps, MultichainConstruct } from "../../sdk/base/MultichainConstruct.js";
|
|
7
7
|
import "../../sdk/index.js";
|
|
8
8
|
import { EnsureFreshChains } from "../types.js";
|
|
9
|
-
import { AddCollateralParams, AdjustLeverageParams,
|
|
10
|
-
//#region src/new-sdk/
|
|
9
|
+
import { AddCollateralParams, AdjustLeverageParams, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
10
|
+
//#region src/new-sdk/prepare/PrepareApi.d.ts
|
|
11
11
|
/**
|
|
12
12
|
* The chain's SDK, resolved on the spot.
|
|
13
13
|
*
|
|
@@ -17,7 +17,7 @@ import { AddCollateralParams, AdjustLeverageParams, DelayedSimulate, DepositStra
|
|
|
17
17
|
**/
|
|
18
18
|
type ChainOf = (chainId: ChainId) => OnchainSDK;
|
|
19
19
|
/**
|
|
20
|
-
* {@inheritDoc
|
|
20
|
+
* {@inheritDoc OpportunitiesPrepare}
|
|
21
21
|
*
|
|
22
22
|
* Holds no state of its own: it owns the mapping from the public,
|
|
23
23
|
* read-model-shaped request to the engine's intent, and nothing else. All
|
|
@@ -29,62 +29,62 @@ type ChainOf = (chainId: ChainId) => OnchainSDK;
|
|
|
29
29
|
* to, hence a chain the SDK does not cover, or one that fails the read, throws
|
|
30
30
|
* rather than answering with empty metadata.
|
|
31
31
|
**/
|
|
32
|
-
declare class
|
|
32
|
+
declare class PrepareApi extends MultichainConstruct implements OpportunitiesPrepare {
|
|
33
33
|
#private;
|
|
34
34
|
constructor(sdk: MultichainSDK, ensureFresh?: EnsureFreshChains);
|
|
35
35
|
protected queryChain<T>(props: ChainQueryOneProps<T>): Promise<DataResponse<T>>;
|
|
36
36
|
/**
|
|
37
|
-
* {@inheritDoc
|
|
37
|
+
* {@inheritDoc OpportunitiesPrepare.finalize}
|
|
38
38
|
**/
|
|
39
|
-
|
|
39
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategySimulate>>;
|
|
40
40
|
/**
|
|
41
|
-
* {@inheritDoc
|
|
41
|
+
* {@inheritDoc OpportunitiesPrepare.deposit}
|
|
42
42
|
**/
|
|
43
43
|
deposit(pool: PoolInput, params: LpParams): LpSimulate;
|
|
44
44
|
/**
|
|
45
|
-
* {@inheritDoc
|
|
45
|
+
* {@inheritDoc OpportunitiesPrepare.withdraw}
|
|
46
46
|
**/
|
|
47
47
|
withdraw(pool: PoolInput, params: LpParams): LpSimulate;
|
|
48
48
|
/**
|
|
49
|
-
* {@inheritDoc
|
|
49
|
+
* {@inheritDoc OpportunitiesPrepare.redeem}
|
|
50
50
|
**/
|
|
51
51
|
redeem(pool: PoolInput, params: LpRedeemParams): LpSimulate;
|
|
52
52
|
/**
|
|
53
|
-
* {@inheritDoc
|
|
53
|
+
* {@inheritDoc OpportunitiesPrepare.openNewStrategy}
|
|
54
54
|
**/
|
|
55
55
|
openNewStrategy(strategy: StrategyInput, params: OpenStrategyParams): Promise<DataResponse<OpenStrategySimulate>>;
|
|
56
56
|
/**
|
|
57
|
-
* {@inheritDoc
|
|
57
|
+
* {@inheritDoc OpportunitiesPrepare.depositStrategy}
|
|
58
58
|
**/
|
|
59
59
|
depositStrategy(position: PositionInput, params: DepositStrategyParams): Promise<DataResponse<StrategySimulate>>;
|
|
60
60
|
/**
|
|
61
|
-
* {@inheritDoc
|
|
61
|
+
* {@inheritDoc OpportunitiesPrepare.withdrawStrategy}
|
|
62
62
|
**/
|
|
63
63
|
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<StrategyRoutesSimulate>>;
|
|
64
64
|
/**
|
|
65
|
-
* {@inheritDoc
|
|
65
|
+
* {@inheritDoc OpportunitiesPrepare.maxWithdraw}
|
|
66
66
|
**/
|
|
67
67
|
maxWithdraw(position: PositionInput): Promise<DataResponse<bigint>>;
|
|
68
68
|
/**
|
|
69
|
-
* {@inheritDoc
|
|
69
|
+
* {@inheritDoc OpportunitiesPrepare.repayStrategy}
|
|
70
70
|
**/
|
|
71
71
|
repayStrategy(position: PositionInput, params: RepayStrategyParams): Promise<DataResponse<StrategySimulate>>;
|
|
72
72
|
/**
|
|
73
|
-
* {@inheritDoc
|
|
73
|
+
* {@inheritDoc OpportunitiesPrepare.maxRepay}
|
|
74
74
|
**/
|
|
75
75
|
maxRepay(position: PositionInput): Promise<DataResponse<bigint>>;
|
|
76
76
|
/**
|
|
77
|
-
* {@inheritDoc
|
|
77
|
+
* {@inheritDoc OpportunitiesPrepare.adjustLeverage}
|
|
78
78
|
**/
|
|
79
79
|
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<StrategyRoutesSimulate>>;
|
|
80
80
|
/**
|
|
81
|
-
* {@inheritDoc
|
|
81
|
+
* {@inheritDoc OpportunitiesPrepare.addCollateral}
|
|
82
82
|
**/
|
|
83
83
|
addCollateral(position: PositionInput, params: AddCollateralParams): Promise<DataResponse<StrategySimulate>>;
|
|
84
84
|
/**
|
|
85
|
-
* {@inheritDoc
|
|
85
|
+
* {@inheritDoc OpportunitiesPrepare.withdrawCollateral}
|
|
86
86
|
**/
|
|
87
87
|
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<DataResponse<StrategySimulate>>;
|
|
88
88
|
}
|
|
89
89
|
//#endregion
|
|
90
|
-
export { ChainOf,
|
|
90
|
+
export { ChainOf, PrepareApi };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AddCollateralParams, AdjustLeverageParams, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams } from "./types.js";
|
|
2
|
+
import { ChainOf, PrepareApi } from "./PrepareApi.js";
|
|
3
|
+
export { AddCollateralParams, AdjustLeverageParams, ChainOf, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, PrepareApi, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams };
|
|
@@ -11,7 +11,7 @@ import { DelayedStart, OperationState, PreviewErrorReason, ResumableIntent, Rout
|
|
|
11
11
|
import { AccountCalculatorOperation } from "../../sdk/accounts/intents/operations.js";
|
|
12
12
|
import "../../sdk/index.js";
|
|
13
13
|
import { Address } from "viem";
|
|
14
|
-
//#region src/new-sdk/
|
|
14
|
+
//#region src/new-sdk/prepare/types.d.ts
|
|
15
15
|
/**
|
|
16
16
|
* What a pool deposit or withdrawal would yield.
|
|
17
17
|
*
|
|
@@ -105,8 +105,8 @@ type DelayedStrategySimulate = {
|
|
|
105
105
|
};
|
|
106
106
|
/**
|
|
107
107
|
* What one of the two flows that sell a position asset —
|
|
108
|
-
* {@link
|
|
109
|
-
* {@link
|
|
108
|
+
* {@link OpportunitiesPrepare.withdrawStrategy} and
|
|
109
|
+
* {@link OpportunitiesPrepare.adjustLeverage} — would yield each way it can be
|
|
110
110
|
* served.
|
|
111
111
|
*
|
|
112
112
|
* Whether the account can sell that asset on the router, redeem it through its
|
|
@@ -126,9 +126,9 @@ type StrategyRoutesSimulate = {
|
|
|
126
126
|
}> | undefined;
|
|
127
127
|
/**
|
|
128
128
|
* The request half of the redemption route, which
|
|
129
|
-
* {@link
|
|
130
|
-
* when the route does not exist — no redemption venue for the
|
|
131
|
-
* request that settles at once anyway — see `refused.delayed`.
|
|
129
|
+
* {@link OpportunitiesPrepare.finalize} completes once it matures.
|
|
130
|
+
* `undefined` when the route does not exist — no redemption venue for the
|
|
131
|
+
* asset, or a request that settles at once anyway — see `refused.delayed`.
|
|
132
132
|
**/
|
|
133
133
|
delayed: Extract<DelayedStrategySimulate, {
|
|
134
134
|
ok: true;
|
|
@@ -165,7 +165,7 @@ type OpenStrategySimulate = {
|
|
|
165
165
|
/**
|
|
166
166
|
* Shared knobs. Both default to the SDK's own defaults when omitted.
|
|
167
167
|
**/
|
|
168
|
-
interface
|
|
168
|
+
interface PrepareOptions {
|
|
169
169
|
/** Router slippage in PERCENTAGE_FORMAT (100% = 10_000). */
|
|
170
170
|
slippage?: number;
|
|
171
171
|
/**
|
|
@@ -189,7 +189,7 @@ type PoolInput = PoolOpportunityKey;
|
|
|
189
189
|
* `sdk.opportunities.list()` satisfies this, as does a bare key.
|
|
190
190
|
**/
|
|
191
191
|
type StrategyInput = StrategyOpportunityKey;
|
|
192
|
-
interface DepositStrategyParams extends
|
|
192
|
+
interface DepositStrategyParams extends PrepareOptions {
|
|
193
193
|
/**
|
|
194
194
|
* Collateral to add: the market underlying, or its unwrapped asset on an RWA
|
|
195
195
|
* market (USDC rather than dcUSDC).
|
|
@@ -209,11 +209,11 @@ interface DepositStrategyParams extends SimulateOptions {
|
|
|
209
209
|
**/
|
|
210
210
|
targetLeverage?: bigint;
|
|
211
211
|
}
|
|
212
|
-
interface WithdrawStrategyParams extends
|
|
212
|
+
interface WithdrawStrategyParams extends PrepareOptions {
|
|
213
213
|
/**
|
|
214
214
|
* Amount the wallet receives, denominated in `tokenOut`. `MAX_UINT256`, or
|
|
215
215
|
* anything at or above the account's net value, turns the flow into an exit,
|
|
216
|
-
* see {@link
|
|
216
|
+
* see {@link OpportunitiesPrepare.withdrawStrategy}.
|
|
217
217
|
**/
|
|
218
218
|
amount: bigint;
|
|
219
219
|
/** Wallet receiving the payout. */
|
|
@@ -229,7 +229,7 @@ interface WithdrawStrategyParams extends SimulateOptions {
|
|
|
229
229
|
**/
|
|
230
230
|
sourceToken?: Address;
|
|
231
231
|
}
|
|
232
|
-
interface RepayStrategyParams extends
|
|
232
|
+
interface RepayStrategyParams extends PrepareOptions {
|
|
233
233
|
/**
|
|
234
234
|
* Funding token: the market underlying, which needs no conversion and is
|
|
235
235
|
* repaid where it lands, or — on an RWA market — the unwrapped asset behind
|
|
@@ -240,14 +240,14 @@ interface RepayStrategyParams extends SimulateOptions {
|
|
|
240
240
|
* Amount taken from the wallet. Anything above the outstanding debt settles
|
|
241
241
|
* it in full and stays on the account as collateral, so a caller clearing the
|
|
242
242
|
* account can add a buffer for the interest that accrues before the
|
|
243
|
-
* transaction lands, see {@link
|
|
243
|
+
* transaction lands, see {@link OpportunitiesPrepare.maxRepay}.
|
|
244
244
|
* `MAX_UINT256` settles the debt and sizes that buffer itself.
|
|
245
245
|
**/
|
|
246
246
|
amount: bigint;
|
|
247
247
|
/** Native value to attach when paying a wrapped-native market in the coin. */
|
|
248
248
|
value?: bigint;
|
|
249
249
|
}
|
|
250
|
-
interface AdjustLeverageParams extends
|
|
250
|
+
interface AdjustLeverageParams extends PrepareOptions {
|
|
251
251
|
/**
|
|
252
252
|
* Target total leverage scaled by `LEVERAGE_DECIMALS` (300n = 3x); 100n means
|
|
253
253
|
* no debt.
|
|
@@ -259,21 +259,21 @@ interface AdjustLeverageParams extends SimulateOptions {
|
|
|
259
259
|
**/
|
|
260
260
|
token?: Address;
|
|
261
261
|
}
|
|
262
|
-
interface AddCollateralParams extends
|
|
262
|
+
interface AddCollateralParams extends PrepareOptions {
|
|
263
263
|
/** Position token to deposit; nothing else is accepted. */
|
|
264
264
|
token: Address;
|
|
265
265
|
amount: bigint;
|
|
266
266
|
/** Native value to attach when paying a wrapped-native market in the coin. */
|
|
267
267
|
value?: bigint;
|
|
268
268
|
}
|
|
269
|
-
interface WithdrawCollateralParams extends
|
|
269
|
+
interface WithdrawCollateralParams extends PrepareOptions {
|
|
270
270
|
/** Token to move out; must already sit on the account. */
|
|
271
271
|
token: Address;
|
|
272
272
|
amount: bigint;
|
|
273
273
|
/** Wallet receiving the tokens. */
|
|
274
274
|
to: Address;
|
|
275
275
|
}
|
|
276
|
-
interface OpenStrategyParams extends
|
|
276
|
+
interface OpenStrategyParams extends PrepareOptions {
|
|
277
277
|
/** Collateral coming from the wallet, in their own tokens. */
|
|
278
278
|
collateral: Asset[];
|
|
279
279
|
/**
|
|
@@ -312,7 +312,7 @@ interface LpParams {
|
|
|
312
312
|
tokenOut?: Address;
|
|
313
313
|
}
|
|
314
314
|
/**
|
|
315
|
-
* Same shape as {@link LpParams}, but {@link
|
|
315
|
+
* Same shape as {@link LpParams}, but {@link OpportunitiesPrepare.redeem}
|
|
316
316
|
* treats `amount` as the pool shares to burn rather than the underlying to
|
|
317
317
|
* receive.
|
|
318
318
|
**/
|
|
@@ -326,7 +326,7 @@ interface LpRedeemParams {
|
|
|
326
326
|
tokenIn?: Address;
|
|
327
327
|
tokenOut?: Address;
|
|
328
328
|
}
|
|
329
|
-
interface
|
|
329
|
+
interface FinalizeParams extends PrepareOptions {
|
|
330
330
|
/**
|
|
331
331
|
* The matured withdrawal to claim, from
|
|
332
332
|
* `sdk.onchain.chain(chainId).withdrawalCompressor.getCurrentWithdrawals()`.
|
|
@@ -339,44 +339,6 @@ interface FinishDelayedParams extends SimulateOptions {
|
|
|
339
339
|
**/
|
|
340
340
|
intent?: ResumableIntent;
|
|
341
341
|
}
|
|
342
|
-
/**
|
|
343
|
-
* The delayed route of the two operations that can take it: a source that only
|
|
344
|
-
* redeems through its issuer — a Securitize dsToken, a Mellow share — instead of
|
|
345
|
-
* through the router.
|
|
346
|
-
*
|
|
347
|
-
* Two transactions rather than one: the request, then the tail once the
|
|
348
|
-
* redemption matures, which is days later. In between, nothing has to be kept on
|
|
349
|
-
* the client — the request writes the operation into the withdrawal's
|
|
350
|
-
* `extraData`, and reading the claimable decodes it back.
|
|
351
|
-
**/
|
|
352
|
-
interface DelayedSimulate {
|
|
353
|
-
/**
|
|
354
|
-
* The delayed counterpart of {@link OpportunitiesSimulate.withdrawStrategy},
|
|
355
|
-
* on its own: that flow already quotes this route alongside the instant one,
|
|
356
|
-
* so reach for this when the delayed route is the only one of interest.
|
|
357
|
-
*
|
|
358
|
-
* Reports `noDelayedRoute` when the account has no redemption venue for the
|
|
359
|
-
* source at all.
|
|
360
|
-
**/
|
|
361
|
-
withdrawStrategy(position: PositionInput, params: WithdrawStrategyParams): Promise<DataResponse<DelayedStrategySimulate>>;
|
|
362
|
-
/**
|
|
363
|
-
* The delayed counterpart of {@link OpportunitiesSimulate.adjustLeverage} on
|
|
364
|
-
* its own, which only deleveraging reaches: raising leverage buys the position
|
|
365
|
-
* token and never redeems it. That flow already quotes this route alongside
|
|
366
|
-
* the instant one, so reach for this when it is the only one of interest.
|
|
367
|
-
**/
|
|
368
|
-
adjustLeverage(position: PositionInput, params: AdjustLeverageParams): Promise<DataResponse<DelayedStrategySimulate>>;
|
|
369
|
-
/**
|
|
370
|
-
* The tail: claim the matured withdrawal, then whatever the recorded
|
|
371
|
-
* operation still owes — repaying debt and paying the wallet out for a
|
|
372
|
-
* withdrawal, repaying alone for a deleveraging, nothing beyond the claim for
|
|
373
|
-
* the rest.
|
|
374
|
-
*
|
|
375
|
-
* Answers like the instant flows, so both halves are consumed the same way.
|
|
376
|
-
* Reports `noRecordedIntent` when the claim names no operation to resume.
|
|
377
|
-
**/
|
|
378
|
-
finish(position: PositionInput, params: FinishDelayedParams): Promise<DataResponse<StrategySimulate>>;
|
|
379
|
-
}
|
|
380
342
|
/**
|
|
381
343
|
* Simulations of everything a wallet can do to a pool or a credit account.
|
|
382
344
|
*
|
|
@@ -387,7 +349,7 @@ interface DelayedSimulate {
|
|
|
387
349
|
* Not to be confused with `src/preview/simulate`, which goes the other way: it
|
|
388
350
|
* takes calldata that already exists and reports what it would do.
|
|
389
351
|
**/
|
|
390
|
-
interface
|
|
352
|
+
interface OpportunitiesPrepare {
|
|
391
353
|
/**
|
|
392
354
|
* Depositing into a pool: underlying in, shares out.
|
|
393
355
|
*
|
|
@@ -499,10 +461,22 @@ interface OpportunitiesSimulate {
|
|
|
499
461
|
**/
|
|
500
462
|
withdrawCollateral(position: PositionInput, params: WithdrawCollateralParams): Promise<DataResponse<StrategySimulate>>;
|
|
501
463
|
/**
|
|
502
|
-
* The
|
|
503
|
-
*
|
|
464
|
+
* The tail of a delayed route: claim the matured withdrawal, then whatever the
|
|
465
|
+
* operation that requested it still owes — repaying debt and paying the wallet
|
|
466
|
+
* out for a withdrawal, repaying alone for a deleveraging, nothing beyond the
|
|
467
|
+
* claim for the rest.
|
|
468
|
+
*
|
|
469
|
+
* The route is requested by {@link withdrawStrategy} or
|
|
470
|
+
* {@link adjustLeverage}, whose `delayed` branch is the transaction that
|
|
471
|
+
* starts it; days later the redemption matures and this finishes it. Nothing
|
|
472
|
+
* has to be kept on the client in between: the request writes the operation
|
|
473
|
+
* into the withdrawal's `extraData`, and reading the claimable decodes it
|
|
474
|
+
* back.
|
|
475
|
+
*
|
|
476
|
+
* Answers like the instant flows, so both halves are consumed the same way.
|
|
477
|
+
* Reports `noRecordedIntent` when the claim names no operation to resume.
|
|
504
478
|
**/
|
|
505
|
-
|
|
479
|
+
finalize(position: PositionInput, params: FinalizeParams): Promise<DataResponse<StrategySimulate>>;
|
|
506
480
|
}
|
|
507
481
|
//#endregion
|
|
508
|
-
export { AddCollateralParams, AdjustLeverageParams,
|
|
482
|
+
export { AddCollateralParams, AdjustLeverageParams, DelayedStrategySimulate, DepositStrategyParams, FinalizeParams, LpParams, LpRedeemParams, LpSimulate, OpenStrategyParams, OpenStrategySimulate, OpportunitiesPrepare, PoolInput, PositionInput, PrepareOptions, RepayStrategyParams, StrategyInput, StrategyRoutesSimulate, StrategySimulate, WithdrawCollateralParams, WithdrawStrategyParams };
|
|
@@ -105,7 +105,7 @@ interface BuildMockSdkArgs {
|
|
|
105
105
|
delayed?: Record<Address, MockDelayedVenue[]>;
|
|
106
106
|
/**
|
|
107
107
|
* Accounts `accounts.getCreditAccountData` knows, keyed by address. What the
|
|
108
|
-
*
|
|
108
|
+
* prepare layer reads on its own instead of taking a slice from the caller;
|
|
109
109
|
* `accountDebt` lands as the principal with no interest or fees accrued.
|
|
110
110
|
*/
|
|
111
111
|
creditAccounts?: CreditAccountSlice[];
|
|
@@ -40,7 +40,7 @@ interface OperationState extends PositionMetrics {
|
|
|
40
40
|
*
|
|
41
41
|
* Every member is thrown by the engine as an {@link IntentPreviewError}, with
|
|
42
42
|
* the exception of `unsupportedTokenPair` and `noRecordedIntent`, which the
|
|
43
|
-
*
|
|
43
|
+
* prepare namespace reports for a request it can refuse before planning: a
|
|
44
44
|
* route the market does not offer, a claim naming no operation.
|
|
45
45
|
*/
|
|
46
46
|
type PreviewErrorReason = "debtOutOfRange" | "leverageOutOfRange" | "insufficientSourceBalance" |
|
|
@@ -98,8 +98,8 @@ type IntentPreviewResult = {
|
|
|
98
98
|
interface DelayedStart {
|
|
99
99
|
/**
|
|
100
100
|
* The intent written into the request, and decoded back from the claimable
|
|
101
|
-
* withdrawal at claim time.
|
|
102
|
-
* `CreditAccountOperationsService.finishIntent
|
|
101
|
+
* withdrawal at claim time. `prepare.finalize` picks it up from there, and
|
|
102
|
+
* `CreditAccountOperationsService.finishIntent` is what it feeds.
|
|
103
103
|
*/
|
|
104
104
|
record: DelayedIntent;
|
|
105
105
|
/** Unix seconds after which the delayed outputs can be claimed. */
|
|
@@ -172,16 +172,16 @@ type IntentRoutesResult = {
|
|
|
172
172
|
* The intents the engine previews.
|
|
173
173
|
*
|
|
174
174
|
* Naming avoids the `withdrawCollateral` collision that exists elsewhere in the
|
|
175
|
-
* repo. Mapping to the public
|
|
175
|
+
* repo. Mapping to the public prepare API:
|
|
176
176
|
*
|
|
177
|
-
* | Intent type | Public name
|
|
178
|
-
* | ------------------ |
|
|
179
|
-
* | `ADD_COLLATERAL` | `
|
|
180
|
-
* | `WITHDRAW_ASSET` | `
|
|
181
|
-
* | `ADJUST_LEVERAGE` | `
|
|
182
|
-
* | `DEPOSIT` | `
|
|
183
|
-
* | `WITHDRAW` | `
|
|
184
|
-
* | `REPAY` | `
|
|
177
|
+
* | Intent type | Public name | Debt |
|
|
178
|
+
* | ------------------ | ---------------------------- | ------- |
|
|
179
|
+
* | `ADD_COLLATERAL` | `prepare.addCollateral` | fixed |
|
|
180
|
+
* | `WITHDRAW_ASSET` | `prepare.withdrawCollateral` | fixed |
|
|
181
|
+
* | `ADJUST_LEVERAGE` | `prepare.adjustLeverage` | changes |
|
|
182
|
+
* | `DEPOSIT` | `prepare.depositStrategy` | grows |
|
|
183
|
+
* | `WITHDRAW` | `prepare.withdrawStrategy` | shrinks |
|
|
184
|
+
* | `REPAY` | `prepare.repayStrategy` | shrinks |
|
|
185
185
|
*/
|
|
186
186
|
/** Shared inputs for every start intent. */
|
|
187
187
|
type StartIntentProps = {
|
package/package.json
CHANGED