@gearbox-protocol/sdk 16.0.0-next.42 → 16.0.0-next.44
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/index.js +4 -0
- package/dist/cjs/model/result.js +27 -0
- package/dist/cjs/onchain/accounts/index.js +0 -2
- package/dist/cjs/onchain/accounts/intents/tail.js +1 -1
- package/dist/cjs/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +13 -7
- package/dist/cjs/onchain/accounts/withdrawal-compressor/errors.js +0 -19
- package/dist/cjs/onchain/accounts/withdrawal-compressor/index.js +1 -2
- package/dist/cjs/onchain/index.js +0 -5
- package/dist/cjs/onchain/market/index.js +0 -2
- package/dist/cjs/onchain/market/zapper/ZapperContract.js +15 -8
- package/dist/cjs/onchain/market/zapper/errors.js +0 -17
- package/dist/cjs/onchain/market/zapper/index.js +1 -2
- package/dist/cjs/onchain/validation/checks.js +1 -1
- package/dist/cjs/onchain/validation/index.js +0 -1
- package/dist/cjs/preview/index.js +2 -8
- package/dist/cjs/preview/parse/errors.js +0 -32
- package/dist/cjs/preview/parse/index.js +1 -5
- package/dist/cjs/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/cjs/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/cjs/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/cjs/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/cjs/preview/preview/errors.js +0 -16
- package/dist/cjs/preview/preview/index.js +1 -2
- package/dist/cjs/preview/preview/previewOperation.js +30 -11
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/cjs/preview/simulate/errors.js +15 -24
- package/dist/cjs/preview/simulate/index.js +1 -1
- package/dist/cjs/preview/simulate/simulateOperation.js +6 -4
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +6 -3
- package/dist/cjs/sdk/execute/ExecuteApi.js +1 -1
- package/dist/cjs/sdk/index.js +1 -1
- package/dist/cjs/sdk/prepare/PrepareApi.js +198 -278
- package/dist/cjs/sdk/prepare/errors.js +5 -2
- package/dist/cjs/sdk/prepare/index.js +1 -1
- package/dist/esm/dev/AccountOpener.js +1 -1
- package/dist/esm/dev/withdrawalUtils.js +1 -1
- package/dist/esm/model/index.js +2 -1
- package/dist/esm/model/result.js +24 -0
- package/dist/esm/onchain/accounts/CreditAccountsServiceV310.js +2 -2
- package/dist/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/intents/tail.js +1 -1
- package/dist/esm/onchain/accounts/liquidations/LiquidationsService.js +1 -1
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +14 -8
- 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/accounts/withdrawal-compressor/errors.js +1 -19
- package/dist/esm/onchain/accounts/withdrawal-compressor/index.js +2 -2
- package/dist/esm/onchain/base/TokensMeta.js +3 -3
- package/dist/esm/onchain/core/createAddressProvider.js +1 -1
- package/dist/esm/onchain/index.js +2 -4
- 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/index.js +1 -2
- 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 +16 -9
- package/dist/esm/onchain/market/zapper/errors.js +1 -17
- package/dist/esm/onchain/market/zapper/index.js +2 -2
- package/dist/esm/onchain/utils/viem/simulateWithPriceUpdates.js +1 -1
- package/dist/esm/onchain/validation/checks.js +1 -1
- package/dist/esm/onchain/validation/index.js +2 -2
- package/dist/esm/preview/index.js +3 -5
- package/dist/esm/preview/parse/errors.js +1 -30
- package/dist/esm/preview/parse/index.js +2 -3
- package/dist/esm/preview/parse/parseOperationCalldata.js +28 -17
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +17 -11
- package/dist/esm/preview/prerequisites/checkPrerequisites.js +5 -2
- package/dist/esm/preview/preview/detectDelayedClaim.js +9 -7
- package/dist/esm/preview/preview/detectDelayedOperation.js +11 -4
- package/dist/esm/preview/preview/errors.js +1 -16
- package/dist/esm/preview/preview/index.js +2 -2
- package/dist/esm/preview/preview/previewOperation.js +30 -11
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/esm/preview/simulate/errors.js +16 -24
- package/dist/esm/preview/simulate/index.js +2 -2
- package/dist/esm/preview/simulate/simulateOperation.js +6 -4
- package/dist/esm/preview/simulate/simulatePoolOperation.js +7 -4
- package/dist/esm/preview/trace/extractTransfers.js +1 -1
- package/dist/esm/sdk/execute/ExecuteApi.js +1 -1
- package/dist/esm/sdk/index.js +2 -2
- package/dist/esm/sdk/prepare/PrepareApi.js +199 -279
- package/dist/esm/sdk/prepare/errors.js +5 -2
- package/dist/esm/sdk/prepare/index.js +2 -2
- package/dist/types/model/errors.d.ts +4 -32
- package/dist/types/model/index.d.ts +3 -2
- package/dist/types/model/result.d.ts +48 -0
- package/dist/types/onchain/accounts/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.d.ts +6 -4
- package/dist/types/onchain/accounts/withdrawal-compressor/errors.d.ts +9 -5
- package/dist/types/onchain/accounts/withdrawal-compressor/index.d.ts +1 -1
- package/dist/types/onchain/accounts/withdrawal-compressor/types.d.ts +6 -4
- package/dist/types/onchain/index.d.ts +4 -4
- package/dist/types/onchain/market/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/ZapperContract.d.ts +7 -3
- package/dist/types/onchain/market/zapper/errors.d.ts +11 -6
- package/dist/types/onchain/market/zapper/index.d.ts +1 -1
- package/dist/types/onchain/market/zapper/types.d.ts +4 -1
- package/dist/types/onchain/validation/checks.d.ts +1 -1
- package/dist/types/onchain/validation/index.d.ts +2 -2
- package/dist/types/preview/index.d.ts +5 -3
- package/dist/types/preview/parse/errors.d.ts +19 -12
- package/dist/types/preview/parse/index.d.ts +1 -1
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +5 -1
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +5 -2
- package/dist/types/preview/prerequisites/checkPrerequisites.d.ts +6 -1
- package/dist/types/preview/preview/detectDelayedClaim.d.ts +7 -6
- package/dist/types/preview/preview/detectDelayedOperation.d.ts +3 -1
- package/dist/types/preview/preview/errors.d.ts +8 -5
- package/dist/types/preview/preview/index.d.ts +2 -2
- package/dist/types/preview/preview/previewOperation.d.ts +21 -2
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +3 -1
- package/dist/types/preview/simulate/errors.d.ts +12 -8
- package/dist/types/preview/simulate/index.d.ts +2 -2
- package/dist/types/preview/simulate/simulateOperation.d.ts +4 -1
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +4 -1
- package/dist/types/sdk/execute/types.d.ts +6 -11
- package/dist/types/sdk/index.d.ts +3 -3
- package/dist/types/sdk/prepare/PrepareApi.d.ts +29 -26
- package/dist/types/sdk/prepare/errors.d.ts +57 -20
- package/dist/types/sdk/prepare/index.d.ts +3 -3
- package/dist/types/sdk/prepare/types.d.ts +73 -74
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +4 -1
- package/dist/types/sdk/preview/types.d.ts +7 -3
- package/dist/types/sdk/types.d.ts +1 -3
- package/package.json +11 -2
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { UnsupportedZapperFunctionError } from "../../onchain/market/zapper/errors.js";
|
|
2
1
|
import { classifyInnerOperations } from "./classifyInnerOperations.js";
|
|
3
|
-
import
|
|
2
|
+
import "./errors.js";
|
|
4
3
|
import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
|
|
5
4
|
import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
|
|
6
5
|
import { parseRWAFactoryOperationCalldata } from "./parseRWAFactoryOperationCalldata.js";
|
|
7
6
|
import { parseOperationCalldata } from "./parseOperationCalldata.js";
|
|
8
7
|
import { isPoolOperation, isRWAOperation } from "./types.js";
|
|
9
|
-
export {
|
|
8
|
+
export { classifyInnerOperations, isPoolOperation, isRWAOperation, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CreditFacadeV310Contract } from "../../onchain/market/credit/CreditFacadeV310Contract.js";
|
|
2
|
+
import { isSDKError, sdkErr, sdkOk } from "../../model/result.js";
|
|
3
|
+
import "../../model/index.js";
|
|
2
4
|
import { PoolV310Contract } from "../../onchain/market/pool/PoolV310Contract.js";
|
|
3
5
|
import { ZapperContract } from "../../onchain/market/zapper/ZapperContract.js";
|
|
4
6
|
import { isRWAFactory } from "../../onchain/market/rwa/types.js";
|
|
5
7
|
import "../../onchain/index.js";
|
|
6
|
-
import { UnsupportedTargetError } from "./errors.js";
|
|
7
8
|
import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
|
|
8
9
|
import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
|
|
9
10
|
import { parseRWAFactoryOperationCalldata } from "./parseRWAFactoryOperationCalldata.js";
|
|
@@ -19,19 +20,24 @@ function parseOperationCalldata(input) {
|
|
|
19
20
|
const contract = sdk.getContract(to);
|
|
20
21
|
if (contract instanceof PoolV310Contract) return parsePoolOperationCalldata(sdk, contract, calldata);
|
|
21
22
|
if (contract instanceof ZapperContract) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const answer = contract.parseOperation(calldata, value);
|
|
24
|
+
if (isSDKError(answer)) return answer;
|
|
25
|
+
const parsed = answer.data;
|
|
26
|
+
if (parsed.operation === "Deposit") {
|
|
27
|
+
const op = {
|
|
28
|
+
operation: "Deposit",
|
|
29
|
+
pool: parsed.pool,
|
|
30
|
+
receiver: parsed.receiver,
|
|
31
|
+
assets: parsed.assets,
|
|
32
|
+
underlying: parsed.underlying,
|
|
33
|
+
tokenIn: contract.tokenIn.addr,
|
|
34
|
+
tokenOut: contract.tokenOut.addr,
|
|
35
|
+
zapper: parsed.zapper,
|
|
36
|
+
referralCode: parsed.referralCode
|
|
37
|
+
};
|
|
38
|
+
return sdkOk(op);
|
|
39
|
+
}
|
|
40
|
+
const op = {
|
|
35
41
|
operation: "Redeem",
|
|
36
42
|
pool: parsed.pool,
|
|
37
43
|
receiver: parsed.receiver,
|
|
@@ -42,10 +48,15 @@ function parseOperationCalldata(input) {
|
|
|
42
48
|
tokenOut: contract.tokenIn.addr,
|
|
43
49
|
zapper: parsed.zapper
|
|
44
50
|
};
|
|
51
|
+
return sdkOk(op);
|
|
45
52
|
}
|
|
46
|
-
if (contract instanceof CreditFacadeV310Contract) return parseFacadeOperationCalldata(sdk, contract, calldata);
|
|
47
|
-
if (contract && isRWAFactory(contract)) return parseRWAFactoryOperationCalldata(sdk, contract, calldata);
|
|
48
|
-
|
|
53
|
+
if (contract instanceof CreditFacadeV310Contract) return sdkOk(parseFacadeOperationCalldata(sdk, contract, calldata));
|
|
54
|
+
if (contract && isRWAFactory(contract)) return sdkOk(parseRWAFactoryOperationCalldata(sdk, contract, calldata));
|
|
55
|
+
return sdkErr({
|
|
56
|
+
code: "unsupportedTarget",
|
|
57
|
+
message: `unsupported transaction target: ${to}`,
|
|
58
|
+
target: to
|
|
59
|
+
});
|
|
49
60
|
}
|
|
50
61
|
//#endregion
|
|
51
62
|
export { parseOperationCalldata };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { sdkErr, sdkOk } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
2
3
|
//#region src/preview/parse/parsePoolOperationCalldata.ts
|
|
3
4
|
/**
|
|
4
5
|
* Decodes pool calldata into a {@link PoolOperation}.
|
|
@@ -6,7 +7,7 @@ import { UnsupportedPoolFunctionError } from "./errors.js";
|
|
|
6
7
|
* @param sdk - The SDK instance.
|
|
7
8
|
* @param pool - The pool contract.
|
|
8
9
|
* @param calldata - The calldata to parse.
|
|
9
|
-
* @returns The parsed operation.
|
|
10
|
+
* @returns The parsed operation behind `ok`, or the refusal.
|
|
10
11
|
*/
|
|
11
12
|
function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
12
13
|
const parsed = sdk.parseFunctionDataV2(pool.address, calldata);
|
|
@@ -15,7 +16,7 @@ function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
|
15
16
|
const underlying = pool.underlying;
|
|
16
17
|
switch (functionName) {
|
|
17
18
|
case "deposit":
|
|
18
|
-
case "depositWithReferral": return {
|
|
19
|
+
case "depositWithReferral": return sdkOk({
|
|
19
20
|
operation: "Deposit",
|
|
20
21
|
pool: pool.address,
|
|
21
22
|
receiver: rawArgs.receiver,
|
|
@@ -25,9 +26,9 @@ function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
|
25
26
|
tokenOut: pool.address,
|
|
26
27
|
zapper: void 0,
|
|
27
28
|
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
28
|
-
};
|
|
29
|
+
});
|
|
29
30
|
case "mint":
|
|
30
|
-
case "mintWithReferral": return {
|
|
31
|
+
case "mintWithReferral": return sdkOk({
|
|
31
32
|
operation: "Mint",
|
|
32
33
|
pool: pool.address,
|
|
33
34
|
receiver: rawArgs.receiver,
|
|
@@ -37,8 +38,8 @@ function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
|
37
38
|
tokenOut: pool.address,
|
|
38
39
|
zapper: void 0,
|
|
39
40
|
referralCode: functionName === "mintWithReferral" ? rawArgs.referralCode : void 0
|
|
40
|
-
};
|
|
41
|
-
case "withdraw": return {
|
|
41
|
+
});
|
|
42
|
+
case "withdraw": return sdkOk({
|
|
42
43
|
operation: "Withdraw",
|
|
43
44
|
pool: pool.address,
|
|
44
45
|
receiver: rawArgs.receiver,
|
|
@@ -48,8 +49,8 @@ function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
|
48
49
|
tokenIn: pool.address,
|
|
49
50
|
tokenOut: underlying,
|
|
50
51
|
zapper: void 0
|
|
51
|
-
};
|
|
52
|
-
case "redeem": return {
|
|
52
|
+
});
|
|
53
|
+
case "redeem": return sdkOk({
|
|
53
54
|
operation: "Redeem",
|
|
54
55
|
pool: pool.address,
|
|
55
56
|
receiver: rawArgs.receiver,
|
|
@@ -59,8 +60,13 @@ function parsePoolOperationCalldata(sdk, pool, calldata) {
|
|
|
59
60
|
tokenIn: pool.address,
|
|
60
61
|
tokenOut: underlying,
|
|
61
62
|
zapper: void 0
|
|
62
|
-
};
|
|
63
|
-
default:
|
|
63
|
+
});
|
|
64
|
+
default: return sdkErr({
|
|
65
|
+
code: "unsupportedPoolFunction",
|
|
66
|
+
message: `unsupported pool function "${parsed.functionName}" on ${pool.address}`,
|
|
67
|
+
pool: pool.address,
|
|
68
|
+
functionName: parsed.functionName
|
|
69
|
+
});
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
72
|
//#endregion
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSDKError, sdkOk } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { parseOperationCalldata } from "../parse/parseOperationCalldata.js";
|
|
2
4
|
import "../parse/index.js";
|
|
3
5
|
import { buildCollateralPrerequisites } from "./buildCollateralPrerequisites.js";
|
|
@@ -23,14 +25,15 @@ import { buildRWAPrerequisites } from "./buildRWAPrerequisites.js";
|
|
|
23
25
|
async function checkPrerequisites(input, options) {
|
|
24
26
|
const { sdk, sender: wallet } = input;
|
|
25
27
|
const tx = parseOperationCalldata(input);
|
|
28
|
+
if (isSDKError(tx)) return tx;
|
|
26
29
|
const ctx = {
|
|
27
30
|
sdk,
|
|
28
31
|
wallet,
|
|
29
32
|
blockNumber: options?.blockNumber,
|
|
30
33
|
value: input.value ?? 0n
|
|
31
34
|
};
|
|
32
|
-
const prereqs = await buildPrerequisites(tx, ctx);
|
|
33
|
-
return Promise.all(prereqs.map((p) => p.verify(ctx)));
|
|
35
|
+
const prereqs = await buildPrerequisites(tx.data, ctx);
|
|
36
|
+
return sdkOk(await Promise.all(prereqs.map((p) => p.verify(ctx))));
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
36
39
|
* Dispatches a parsed operation to the per-operation-family prerequisite
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { AbstractAdapterContract } from "../../onchain/market/adapters/contracts/AbstractAdapter.js";
|
|
2
|
+
import { sdkOk } from "../../model/result.js";
|
|
3
|
+
import "../../model/index.js";
|
|
2
4
|
import "../../onchain/index.js";
|
|
3
5
|
//#region src/preview/preview/detectDelayedClaim.ts
|
|
4
6
|
/**
|
|
@@ -29,16 +31,16 @@ function detectDelayedClaim(sdk, multicall) {
|
|
|
29
31
|
* @param sdk - Attached SDK.
|
|
30
32
|
* @param multicall - Parsed inner operations of the multicall.
|
|
31
33
|
* @param blockNumber - Optional block number to read the log at.
|
|
32
|
-
* @returns The decoded intent
|
|
33
|
-
* nothing, the redemption logger is not deployed, or the log carries
|
|
34
|
-
* intent
|
|
35
|
-
*
|
|
36
|
-
* but cannot be decoded as a `DelayedIntent`.
|
|
34
|
+
* @returns The decoded intent behind `ok` (`undefined` when the multicall
|
|
35
|
+
* claims nothing, the redemption logger is not deployed, or the log carries
|
|
36
|
+
* no intent), or the `invalidDelayedIntent` refusal when the logged
|
|
37
|
+
* `extraData` is non-empty but cannot be decoded as a `DelayedIntent`.
|
|
37
38
|
*/
|
|
38
39
|
async function resolveDelayedClaimIntent(sdk, multicall, blockNumber) {
|
|
39
40
|
const claim = detectDelayedClaim(sdk, multicall);
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const logger = sdk.redemptionLogger;
|
|
42
|
+
if (!claim || !logger) return sdkOk(void 0);
|
|
43
|
+
return logger.getDelayedIntent(claim.redeemer, blockNumber);
|
|
42
44
|
}
|
|
43
45
|
//#endregion
|
|
44
46
|
export { detectDelayedClaim, resolveDelayedClaimIntent };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AbstractAdapterContract } from "../../onchain/market/adapters/contracts/AbstractAdapter.js";
|
|
2
|
+
import { sdkErr, sdkOk } from "../../model/result.js";
|
|
3
|
+
import "../../model/index.js";
|
|
2
4
|
import { decodeDelayedIntent } from "../../onchain/accounts/withdrawal-compressor/intent-codec.js";
|
|
3
|
-
import { InvalidDelayedIntentError } from "../../onchain/accounts/withdrawal-compressor/errors.js";
|
|
4
5
|
import "../../onchain/index.js";
|
|
5
6
|
import { isAddressEqual } from "viem";
|
|
6
7
|
//#region src/preview/preview/detectDelayedOperation.ts
|
|
@@ -35,13 +36,19 @@ function detectDelayedOperation(sdk, multicall) {
|
|
|
35
36
|
if (request.extraData && request.extraData !== "0x") try {
|
|
36
37
|
intent = decodeDelayedIntent(request.extraData);
|
|
37
38
|
} catch (e) {
|
|
38
|
-
|
|
39
|
+
return sdkErr({
|
|
40
|
+
code: "invalidDelayedIntent",
|
|
41
|
+
message: `cannot decode delayed intent from extraData ${request.extraData}`,
|
|
42
|
+
extraData: request.extraData,
|
|
43
|
+
cause: e instanceof Error ? e : new Error(String(e))
|
|
44
|
+
});
|
|
39
45
|
}
|
|
40
|
-
return {
|
|
46
|
+
return sdkOk({
|
|
41
47
|
request,
|
|
42
48
|
intent
|
|
43
|
-
};
|
|
49
|
+
});
|
|
44
50
|
}
|
|
51
|
+
return sdkOk(void 0);
|
|
45
52
|
}
|
|
46
53
|
//#endregion
|
|
47
54
|
export { detectDelayedOperation };
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Thrown by `previewOperation` for parsed operations it cannot preview yet.
|
|
4
|
-
* Currently only pool operations and credit account opening are supported.
|
|
5
|
-
*/
|
|
6
|
-
var UnsupportedOperationError = class extends Error {
|
|
7
|
-
/** The parsed operation kind (the `operation` discriminant). */
|
|
8
|
-
operation;
|
|
9
|
-
constructor(operation) {
|
|
10
|
-
super(`operation "${operation}" is not supported by previewOperation`);
|
|
11
|
-
this.name = "UnsupportedOperationError";
|
|
12
|
-
this.operation = operation;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
//#endregion
|
|
16
|
-
export { UnsupportedOperationError };
|
|
1
|
+
export {};
|
|
@@ -3,11 +3,11 @@ import { CreditAccountState } from "./CreditAccountState.js";
|
|
|
3
3
|
import { classifyCloseOrRepay, isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
4
4
|
import { detectDelayedClaim, resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
5
5
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
6
|
-
import
|
|
6
|
+
import "./errors.js";
|
|
7
7
|
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
8
8
|
import { makeReplayState, replayInnerOperations } from "./replayInnerOperations.js";
|
|
9
9
|
import { replayMulticall } from "./replayMulticall.js";
|
|
10
10
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
11
11
|
import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
12
12
|
import { previewOperation } from "./previewOperation.js";
|
|
13
|
-
export { CreditAccountState,
|
|
13
|
+
export { CreditAccountState, buildDelayedStrategyPositionOperationPreview, classifyCloseOrRepay, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, isCloseOrRepay, makeReplayState, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSDKError, sdkErr, sdkOk } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { parseOperationCalldata } from "../parse/parseOperationCalldata.js";
|
|
2
4
|
import { isPoolOperation } from "../parse/types.js";
|
|
3
5
|
import "../parse/index.js";
|
|
@@ -5,7 +7,6 @@ import { buildDelayedStrategyPositionOperationPreview } from "./buildDelayedStra
|
|
|
5
7
|
import { isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
6
8
|
import { resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
7
9
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
8
|
-
import { UnsupportedOperationError } from "./errors.js";
|
|
9
10
|
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
10
11
|
import { replayMulticall } from "./replayMulticall.js";
|
|
11
12
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
@@ -16,19 +17,33 @@ import { previewPoolPositionOperation } from "./previewPoolPositionOperation.js"
|
|
|
16
17
|
/**
|
|
17
18
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
18
19
|
* assembles an operation-specific, human-displayable preview.
|
|
20
|
+
*
|
|
21
|
+
* Answers an {@link SDKReturn} envelope: the preview behind `ok: true`, or —
|
|
22
|
+
* when the transaction is one the previewer refuses to read — a
|
|
23
|
+
* {@link PreviewOperationError} behind `ok: false`. A thrown exception
|
|
24
|
+
* still means the SDK could not do its job (a read failed, the targeted
|
|
25
|
+
* credit account could not be resolved), not a refusal of the transaction.
|
|
19
26
|
*/
|
|
20
27
|
async function previewOperation(input, options) {
|
|
21
|
-
const
|
|
28
|
+
const parsed = parseOperationCalldata(input);
|
|
29
|
+
if (isSDKError(parsed)) return parsed;
|
|
30
|
+
const operation = parsed.data;
|
|
22
31
|
if (isPoolOperation(operation)) return previewPoolPositionOperation(input, operation, options);
|
|
23
|
-
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return previewOpenStrategyPosition(input, operation);
|
|
32
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return sdkOk(await previewOpenStrategyPosition(input, operation));
|
|
24
33
|
if (operation.operation === "CloseCreditAccount") {
|
|
25
34
|
const resolved = await resolveCreditAccount(input, operation, options);
|
|
26
35
|
const preview = previewExitOrRepayStrategyPosition(input, operation, true, resolved);
|
|
27
|
-
|
|
28
|
-
return
|
|
36
|
+
const intent = await resolveDelayedClaimIntent(input.sdk, operation.multicall, options?.blockNumber);
|
|
37
|
+
if (isSDKError(intent)) return intent;
|
|
38
|
+
preview.intent = intent.data;
|
|
39
|
+
return sdkOk(preview);
|
|
29
40
|
}
|
|
30
41
|
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") return previewMulticallOperation(input, operation, await resolveCreditAccount(input, operation, options));
|
|
31
|
-
|
|
42
|
+
return sdkErr({
|
|
43
|
+
code: "unsupportedOperation",
|
|
44
|
+
message: `operation "${operation.operation}" is not supported by previewOperation`,
|
|
45
|
+
operation: operation.operation
|
|
46
|
+
});
|
|
32
47
|
}
|
|
33
48
|
/**
|
|
34
49
|
* Resolves the pre-state of the credit account an operation targets: uses the
|
|
@@ -54,10 +69,14 @@ async function resolveCreditAccount(input, operation, options) {
|
|
|
54
69
|
async function previewMulticallOperation(input, operation, options) {
|
|
55
70
|
const { sdk } = input;
|
|
56
71
|
const instantPreview = isCloseOrRepay(operation.multicall) ? previewExitOrRepayStrategyPosition(input, operation, false, options) : previewAdjustStrategyPosition(input, operation, options);
|
|
57
|
-
const
|
|
72
|
+
const detected = detectDelayedOperation(sdk, operation.multicall);
|
|
73
|
+
if (isSDKError(detected)) return detected;
|
|
74
|
+
const delayed = detected.data;
|
|
58
75
|
if (!delayed) {
|
|
59
|
-
|
|
60
|
-
return
|
|
76
|
+
const intent = await resolveDelayedClaimIntent(sdk, operation.multicall, options?.blockNumber);
|
|
77
|
+
if (isSDKError(intent)) return intent;
|
|
78
|
+
instantPreview.intent = intent.data;
|
|
79
|
+
return sdkOk(instantPreview);
|
|
61
80
|
}
|
|
62
81
|
const { before, after } = replayMulticall(sdk, operation, options);
|
|
63
82
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
@@ -65,7 +84,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
65
84
|
const meta = sdk.tokensMeta.get(market.underlying);
|
|
66
85
|
const receivedToken = meta && sdk.tokensMeta.isRWAUnderlying(meta) ? meta.asset : market.underlying;
|
|
67
86
|
const suite = sdk.marketRegister.findCreditManager(operation.creditManager);
|
|
68
|
-
return {
|
|
87
|
+
return sdkOk({
|
|
69
88
|
operation: "DelayedCreditAccountOperation",
|
|
70
89
|
creditAccount: operation.creditAccount,
|
|
71
90
|
...suite.creditOperationMarket(),
|
|
@@ -75,7 +94,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
75
94
|
estClaimableAt: estimateClaimableAt(sdk, delayed.request.phantomToken),
|
|
76
95
|
instantPreview,
|
|
77
96
|
delayedPreview: buildDelayedStrategyPositionOperationPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
78
|
-
};
|
|
97
|
+
});
|
|
79
98
|
}
|
|
80
99
|
//#endregion
|
|
81
100
|
export { previewOperation };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isSDKError, sdkOk } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { simulatePoolOperation } from "../simulate/simulatePoolOperation.js";
|
|
2
4
|
import "../simulate/index.js";
|
|
3
5
|
//#region src/preview/preview/previewPoolPositionOperation.ts
|
|
@@ -5,13 +7,15 @@ async function previewPoolPositionOperation(input, operation, options) {
|
|
|
5
7
|
const { sdk, to, calldata } = input;
|
|
6
8
|
const { tokenIn, tokenOut } = operation;
|
|
7
9
|
const market = sdk.marketRegister.findByPool(operation.pool);
|
|
8
|
-
const
|
|
10
|
+
const answer = await simulatePoolOperation({
|
|
9
11
|
sdk,
|
|
10
12
|
operation,
|
|
11
13
|
to,
|
|
12
14
|
calldata
|
|
13
15
|
}, options);
|
|
14
|
-
return
|
|
16
|
+
if (isSDKError(answer)) return answer;
|
|
17
|
+
const sim = answer.data;
|
|
18
|
+
return sdkOk({
|
|
15
19
|
operation: operation.operation,
|
|
16
20
|
pool: operation.pool,
|
|
17
21
|
name: sdk.tokensMeta.mustGetToken(operation.pool).name,
|
|
@@ -19,7 +23,7 @@ async function previewPoolPositionOperation(input, operation, options) {
|
|
|
19
23
|
shareRate: market.pool.pool.dieselRate,
|
|
20
24
|
tokenIn: market.priceOracle.toTokenAmount(tokenIn, sim.amountIn),
|
|
21
25
|
tokenOut: market.priceOracle.toTokenAmount(tokenOut, sim.amountOut)
|
|
22
|
-
};
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
//#endregion
|
|
25
29
|
export { previewPoolPositionOperation };
|
|
@@ -1,34 +1,26 @@
|
|
|
1
1
|
import { errorAbis } from "../../abi/errors.js";
|
|
2
2
|
import { BaseError, ContractFunctionRevertedError, decodeErrorResult } from "viem";
|
|
3
3
|
//#region src/preview/simulate/errors.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
var PreviewSimulationError = class extends BaseError {
|
|
9
|
-
name = "PreviewSimulationError";
|
|
10
|
-
/** Per-flow decoded failures behind this error. */
|
|
11
|
-
failures;
|
|
12
|
-
constructor(failures) {
|
|
13
|
-
const shortMessage = failures.length <= 1 ? failures[0]?.detail.reason ?? "simulation failed" : "all simulation flows failed";
|
|
14
|
-
const cause = failures.find((f) => f.detail.cause instanceof Error)?.detail.cause;
|
|
15
|
-
super(shortMessage, {
|
|
16
|
-
metaMessages: failures.map((f) => `[${f.source}] ${f.detail.reason}`),
|
|
17
|
-
cause
|
|
18
|
-
});
|
|
19
|
-
this.failures = failures;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
4
|
+
function isPreviewSimulationError(value) {
|
|
5
|
+
return typeof value === "object" && value !== null && !(value instanceof Error) && value.code === "previewSimulationFailed";
|
|
6
|
+
}
|
|
22
7
|
/**
|
|
23
8
|
* Normalises an unknown rejection reason into a {@link PreviewSimulationError}.
|
|
24
9
|
* Pass-through when it already is one; otherwise decodes it under `source`.
|
|
25
10
|
*/
|
|
26
11
|
function asPreviewSimulationError(reason, source) {
|
|
27
|
-
if (reason
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
if (isPreviewSimulationError(reason)) return reason;
|
|
13
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
14
|
+
const detail = decodeSimulationError({ error });
|
|
15
|
+
return {
|
|
16
|
+
code: "previewSimulationFailed",
|
|
17
|
+
message: detail.reason,
|
|
18
|
+
failures: [{
|
|
19
|
+
source,
|
|
20
|
+
detail
|
|
21
|
+
}],
|
|
22
|
+
cause: error
|
|
23
|
+
};
|
|
32
24
|
}
|
|
33
25
|
/**
|
|
34
26
|
* Decodes a simulated call revert into a {@link SimulationError}.
|
|
@@ -76,4 +68,4 @@ function formatDecodedError(errorName, args) {
|
|
|
76
68
|
return `${errorName}(${args.map((arg) => String(arg)).join(", ")})`;
|
|
77
69
|
}
|
|
78
70
|
//#endregion
|
|
79
|
-
export {
|
|
71
|
+
export { asPreviewSimulationError, decodeSimulationError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { asPreviewSimulationError } from "./errors.js";
|
|
2
2
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
3
3
|
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
4
4
|
import { simulateRWAOperation } from "./simulateRWAOperation.js";
|
|
5
5
|
import { simulateOperation } from "./simulateOperation.js";
|
|
6
|
-
export {
|
|
6
|
+
export { asPreviewSimulationError, simulateFacadeOperation, simulateOperation, simulatePoolOperation, simulateRWAOperation };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { sdkOk } from "../../model/result.js";
|
|
2
|
+
import "../../model/index.js";
|
|
1
3
|
import { isPoolOperation, isRWAOperation } from "../parse/types.js";
|
|
2
4
|
import "../parse/index.js";
|
|
3
5
|
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
@@ -13,14 +15,14 @@ async function simulateOperation(input, options) {
|
|
|
13
15
|
...input,
|
|
14
16
|
operation
|
|
15
17
|
}, options);
|
|
16
|
-
if (isRWAOperation(operation)) return simulateRWAOperation({
|
|
18
|
+
if (isRWAOperation(operation)) return sdkOk(await simulateRWAOperation({
|
|
17
19
|
...input,
|
|
18
20
|
operation
|
|
19
|
-
}, options);
|
|
20
|
-
return simulateFacadeOperation({
|
|
21
|
+
}, options));
|
|
22
|
+
return sdkOk(await simulateFacadeOperation({
|
|
21
23
|
...input,
|
|
22
24
|
operation
|
|
23
|
-
}, options);
|
|
25
|
+
}, options));
|
|
24
26
|
}
|
|
25
27
|
//#endregion
|
|
26
28
|
export { simulateOperation };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
2
1
|
import { iPoolV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { sdkErr, sdkOk } from "../../model/result.js";
|
|
3
|
+
import "../../model/index.js";
|
|
4
|
+
import { iZapperAbi } from "../../abi/iZapper.js";
|
|
3
5
|
import { asPreviewSimulationError } from "./errors.js";
|
|
4
6
|
//#region src/preview/simulate/simulatePoolOperation.ts
|
|
5
7
|
function previewRead(operation) {
|
|
@@ -89,14 +91,15 @@ async function simulatePoolOperation(input, options = {}) {
|
|
|
89
91
|
const { sdk, operation } = input;
|
|
90
92
|
const { blockNumber, logger } = options;
|
|
91
93
|
try {
|
|
92
|
-
|
|
94
|
+
const previewAmount = await sdk.client.readContract({
|
|
93
95
|
blockNumber,
|
|
94
96
|
...previewContract(operation)
|
|
95
|
-
})
|
|
97
|
+
});
|
|
98
|
+
return sdkOk(amountsInOut(operation, previewAmount));
|
|
96
99
|
} catch (cause) {
|
|
97
100
|
const error = asPreviewSimulationError(cause, "multicall");
|
|
98
101
|
logger?.error(error, "pool operation simulation failed");
|
|
99
|
-
|
|
102
|
+
return sdkErr(error);
|
|
100
103
|
}
|
|
101
104
|
}
|
|
102
105
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
2
1
|
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
2
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
3
3
|
import { AddressMap } from "../../onchain/utils/AddressMap.js";
|
|
4
4
|
import "../../onchain/index.js";
|
|
5
5
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
@@ -11,7 +11,7 @@ var ExecuteApi = class {
|
|
|
11
11
|
* {@inheritDoc IOpportunitiesExecute.buildTx}
|
|
12
12
|
**/
|
|
13
13
|
async buildTx(request) {
|
|
14
|
-
if (!request.sim.
|
|
14
|
+
if (!request.sim.ok) throw new Error(`cannot build a transaction from a failed ${request.kind} preparation`);
|
|
15
15
|
const sdk = this.#chainOf(request.chainId);
|
|
16
16
|
switch (request.kind) {
|
|
17
17
|
case "pool": return poolTx(sdk, request);
|
package/dist/esm/sdk/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { LiquidationsNamespace } from "./liquidations/LiquidationsNamespace.js";
|
|
|
12
12
|
import "./liquidations/index.js";
|
|
13
13
|
import { ExecuteApi } from "./execute/ExecuteApi.js";
|
|
14
14
|
import "./execute/index.js";
|
|
15
|
-
import { creditAccountNotFound, noStrategyTargetCollateral,
|
|
15
|
+
import { creditAccountNotFound, noStrategyTargetCollateral, toRefusalError, unexpectedFailure } from "./prepare/errors.js";
|
|
16
16
|
import { PrepareApi } from "./prepare/PrepareApi.js";
|
|
17
17
|
import "./prepare/index.js";
|
|
18
18
|
import { filterResponse } from "./utils/filterResponse.js";
|
|
@@ -26,4 +26,4 @@ import { PreviewNamespace } from "./preview/PreviewNamespace.js";
|
|
|
26
26
|
import "./preview/index.js";
|
|
27
27
|
import { DEFAULT_MAX_STATE_AGE, GearboxSDK } from "./GearboxSDK.js";
|
|
28
28
|
import "./types.js";
|
|
29
|
-
export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, ExecuteApi, GearboxSDK, IntentPreviewError, LiquidationsNamespace, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, PrepareApi, PreviewNamespace, SourceChainMismatchError, SourceUnavailableError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse,
|
|
29
|
+
export { AbstractNamespace, AllSourcesFailedError, DEFAULT_MAX_OFFCHAIN_LAG, DEFAULT_MAX_STATE_AGE, ExecuteApi, GearboxSDK, IntentPreviewError, LiquidationsNamespace, MissingSourceError, NoSourceServedError, OpportunitiesNamespace, PositionsNamespace, PrepareApi, PreviewNamespace, SourceChainMismatchError, SourceUnavailableError, assertSameChains, creditAccountNotFound, everyChainFailed, filterResponse, mergeChainList, mergeChainOne, noStrategyTargetCollateral, raise, refuse, toRefusalError, unexpectedFailure };
|