@gearbox-protocol/sdk 16.0.0-next.43 → 16.0.0-next.45
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/onchain/accounts/index.js +0 -2
- 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 -4
- package/dist/cjs/onchain/market/adapters/contracts/BalancerV3RouterAdapterContract.js +33 -1
- 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 -18
- package/dist/cjs/onchain/market/zapper/index.js +1 -2
- package/dist/cjs/onchain/validation/checks.js +1 -1
- package/dist/cjs/preview/index.js +1 -10
- package/dist/cjs/preview/parse/errors.js +0 -35
- 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 -17
- package/dist/cjs/preview/preview/index.js +1 -2
- package/dist/cjs/preview/preview/previewOperation.js +30 -42
- package/dist/cjs/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/cjs/preview/simulate/errors.js +13 -23
- 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/esm/onchain/accounts/index.js +1 -2
- package/dist/esm/onchain/accounts/withdrawal-compressor/RedemptionLoggerV310Contract.js +13 -7
- 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/index.js +1 -3
- package/dist/esm/onchain/market/adapters/contracts/BalancerV3RouterAdapterContract.js +33 -1
- package/dist/esm/onchain/market/index.js +1 -2
- package/dist/esm/onchain/market/zapper/ZapperContract.js +15 -8
- package/dist/esm/onchain/market/zapper/errors.js +1 -18
- package/dist/esm/onchain/market/zapper/index.js +2 -2
- package/dist/esm/onchain/validation/checks.js +1 -1
- package/dist/esm/preview/index.js +2 -6
- package/dist/esm/preview/parse/errors.js +1 -33
- 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 -17
- package/dist/esm/preview/preview/index.js +2 -2
- package/dist/esm/preview/preview/previewOperation.js +31 -43
- package/dist/esm/preview/preview/previewPoolPositionOperation.js +7 -3
- package/dist/esm/preview/simulate/errors.js +14 -23
- 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 +6 -3
- package/dist/types/model/errors.d.ts +1 -1
- 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 +2 -11
- 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 +2 -2
- 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 +1 -10
- 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/preview/index.d.ts +4 -4
- package/dist/types/preview/parse/errors.d.ts +3 -21
- 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 +1 -10
- package/dist/types/preview/preview/index.d.ts +2 -2
- package/dist/types/preview/preview/previewOperation.d.ts +10 -10
- package/dist/types/preview/preview/previewPoolPositionOperation.d.ts +3 -1
- package/dist/types/preview/simulate/errors.d.ts +2 -11
- 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/prepare/errors.d.ts +1 -1
- package/dist/types/sdk/preview/PreviewNamespace.d.ts +2 -2
- package/dist/types/sdk/preview/types.d.ts +3 -3
- package/dist/types/sdk/types.d.ts +1 -3
- package/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { iZapperAbi } from "../../../abi/iZapper.js";
|
|
2
2
|
import { BaseContract } from "../../base/BaseContract.js";
|
|
3
3
|
import "../../base/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { sdkErr, sdkOk } from "../../../model/result.js";
|
|
5
|
+
import "../../../model/index.js";
|
|
5
6
|
//#region src/onchain/market/zapper/ZapperContract.ts
|
|
6
7
|
/**
|
|
7
8
|
* Base contract for every Gearbox zapper. Specialized zappers (e.g.
|
|
@@ -32,8 +33,9 @@ var ZapperContract = class extends BaseContract {
|
|
|
32
33
|
this.tokenOut = data.tokenOut;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
|
-
* Decodes zapper calldata into {@link ParsedZapperOperation}
|
|
36
|
-
*
|
|
36
|
+
* Decodes zapper calldata into {@link ParsedZapperOperation} behind `ok`,
|
|
37
|
+
* or refuses with {@link UnsupportedZapperFunctionError} for unknown
|
|
38
|
+
* selectors.
|
|
37
39
|
*/
|
|
38
40
|
parseOperation(calldata, value) {
|
|
39
41
|
const parsed = this.parseFunctionDataV2(calldata);
|
|
@@ -42,7 +44,7 @@ var ZapperContract = class extends BaseContract {
|
|
|
42
44
|
const zapper = this.address;
|
|
43
45
|
const underlying = this.sdk.marketRegister.findByPool(pool).underlying;
|
|
44
46
|
const receiver = rawArgs.receiver;
|
|
45
|
-
if (parsed.functionName.startsWith("deposit")) return {
|
|
47
|
+
if (parsed.functionName.startsWith("deposit")) return sdkOk({
|
|
46
48
|
operation: "Deposit",
|
|
47
49
|
pool,
|
|
48
50
|
zapper,
|
|
@@ -50,16 +52,21 @@ var ZapperContract = class extends BaseContract {
|
|
|
50
52
|
assets: rawArgs.tokenInAmount ?? value ?? 0n,
|
|
51
53
|
underlying,
|
|
52
54
|
referralCode: rawArgs.referralCode
|
|
53
|
-
};
|
|
54
|
-
if (parsed.functionName.startsWith("redeem")) return {
|
|
55
|
+
});
|
|
56
|
+
if (parsed.functionName.startsWith("redeem")) return sdkOk({
|
|
55
57
|
operation: "Redeem",
|
|
56
58
|
pool,
|
|
57
59
|
zapper,
|
|
58
60
|
receiver,
|
|
59
61
|
shares: rawArgs.tokenOutAmount,
|
|
60
62
|
underlying
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
+
});
|
|
64
|
+
return sdkErr({
|
|
65
|
+
code: "unsupportedZapperFunction",
|
|
66
|
+
message: `unsupported zapper function "${parsed.functionName}" on ${zapper}`,
|
|
67
|
+
zapper,
|
|
68
|
+
functionName: parsed.functionName
|
|
69
|
+
});
|
|
63
70
|
}
|
|
64
71
|
/**
|
|
65
72
|
* Redeems pool shares (diesel tokens) for the underlying asset via this zapper.
|
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function unsupportedZapperFunction(zapper, functionName) {
|
|
3
|
-
return {
|
|
4
|
-
code: "unsupportedZapperFunction",
|
|
5
|
-
message: `unsupported zapper function "${functionName}" on ${zapper}`,
|
|
6
|
-
zapper,
|
|
7
|
-
functionName
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(unsupportedZapperFunction, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedZapperFunction" });
|
|
11
|
-
/**
|
|
12
|
-
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
13
|
-
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
14
|
-
* the answer is never an `Error`.
|
|
15
|
-
*/
|
|
16
|
-
const UnsupportedZapperFunctionError = unsupportedZapperFunction;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { UnsupportedZapperFunctionError };
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UnsupportedZapperFunctionError } from "./errors.js";
|
|
2
1
|
import { ZapperContract } from "./ZapperContract.js";
|
|
3
2
|
import { IERC20ZapperContract } from "./IERC20ZapperContract.js";
|
|
4
3
|
import { IETHZapperContract } from "./IETHZapperContract.js";
|
|
5
4
|
import { createZapper } from "./createZapper.js";
|
|
5
|
+
import "./errors.js";
|
|
6
6
|
import "./types.js";
|
|
7
|
-
export { IERC20ZapperContract, IETHZapperContract,
|
|
7
|
+
export { IERC20ZapperContract, IETHZapperContract, ZapperContract, createZapper };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
//#region src/onchain/validation/checks.ts
|
|
2
2
|
/**
|
|
3
|
-
* Every
|
|
3
|
+
* Every refusal the protocol can pass on an operation, as values.
|
|
4
4
|
*
|
|
5
5
|
* Each check is handed the numbers it compares — never a suite, a market or an
|
|
6
6
|
* SDK — so the engine, `checkOperation` and the strategy lists share one
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { UnsupportedZapperFunctionError } from "../onchain/market/zapper/errors.js";
|
|
2
1
|
import { raise, refuse } from "../onchain/validation/refusal.js";
|
|
3
|
-
import { InvalidDelayedIntentError } from "../onchain/accounts/withdrawal-compressor/errors.js";
|
|
4
2
|
import { TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, WithdrawCollateralAlignmentError } from "./trace/errors.js";
|
|
5
3
|
import { extractAdapterCallTraces } from "./trace/extractAdapterCallTraces.js";
|
|
6
4
|
import { extractTransfers } from "./trace/extractTransfers.js";
|
|
7
5
|
import { findFacadeCalls } from "./trace/findFacadeCalls.js";
|
|
8
6
|
import "./trace/index.js";
|
|
9
7
|
import { classifyInnerOperations } from "./parse/classifyInnerOperations.js";
|
|
10
|
-
import { UnsupportedPoolFunctionError, UnsupportedTargetError } from "./parse/errors.js";
|
|
11
8
|
import { parseFacadeOperationCalldata } from "./parse/parseFacadeOperationCalldata.js";
|
|
12
9
|
import { parsePoolOperationCalldata } from "./parse/parsePoolOperationCalldata.js";
|
|
13
10
|
import { parseRWAFactoryOperationCalldata } from "./parse/parseRWAFactoryOperationCalldata.js";
|
|
@@ -25,17 +22,16 @@ import { CreditAccountState } from "./preview/CreditAccountState.js";
|
|
|
25
22
|
import { classifyCloseOrRepay, isCloseOrRepay } from "./preview/detectCloseOrRepay.js";
|
|
26
23
|
import { detectDelayedClaim, resolveDelayedClaimIntent } from "./preview/detectDelayedClaim.js";
|
|
27
24
|
import { detectDelayedOperation } from "./preview/detectDelayedOperation.js";
|
|
28
|
-
import { UnsupportedOperationError } from "./preview/errors.js";
|
|
29
25
|
import { estimateClaimableAt } from "./preview/estimateClaimableAt.js";
|
|
30
26
|
import { makeReplayState, replayInnerOperations } from "./preview/replayInnerOperations.js";
|
|
31
27
|
import { replayMulticall } from "./preview/replayMulticall.js";
|
|
32
28
|
import { previewAdjustStrategyPosition } from "./preview/previewAdjustStrategyPosition.js";
|
|
33
29
|
import { previewExitOrRepayStrategyPosition } from "./preview/previewExitOrRepayStrategyPosition.js";
|
|
34
|
-
import {
|
|
30
|
+
import { asPreviewSimulationError } from "./simulate/errors.js";
|
|
35
31
|
import { previewOperation } from "./preview/previewOperation.js";
|
|
36
32
|
import "./preview/index.js";
|
|
37
33
|
import "./types.js";
|
|
38
34
|
import { checkOperation, collateralIssue, marketIssues, quotaCountIssue } from "./validate/checkOperation.js";
|
|
39
35
|
import { checkSimulation } from "./validate/checkSimulation.js";
|
|
40
36
|
import "./validate/index.js";
|
|
41
|
-
export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState,
|
|
37
|
+
export { AllowancePrerequisite, BalancePrerequisite, CreditAccountState, Prerequisite, RWAOpenRequirementsPrerequisite, TransferAlignmentError, UnexpectedFacadeEventOrderError, UnknownAdapterError, UnknownFacadeCallError, WithdrawCollateralAlignmentError, asPreviewSimulationError, buildDelayedStrategyPositionOperationPreview, checkOperation, checkPrerequisites, checkSimulation, classifyCloseOrRepay, classifyInnerOperations, collateralIssue, detectDelayedClaim, detectDelayedOperation, estimateClaimableAt, extractAdapterCallTraces, extractTransfers, findFacadeCalls, isCloseOrRepay, isPoolOperation, isRWAOperation, makeReplayState, marketIssues, parseFacadeOperationCalldata, parseOperationCalldata, parsePoolOperationCalldata, parseRWAFactoryOperationCalldata, previewAdjustStrategyPosition, previewExitOrRepayStrategyPosition, previewOperation, quotaCountIssue, raise, refuse, replayInnerOperations, replayMulticall, resolveDelayedClaimIntent };
|
|
@@ -1,33 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/preview/parse/errors.ts
|
|
3
|
-
function unsupportedTarget(target) {
|
|
4
|
-
return {
|
|
5
|
-
code: "unsupportedTarget",
|
|
6
|
-
message: `unsupported transaction target: ${target}`,
|
|
7
|
-
target
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
Object.defineProperty(unsupportedTarget, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedTarget" });
|
|
11
|
-
/**
|
|
12
|
-
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
13
|
-
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
14
|
-
* the answer is never an `Error`.
|
|
15
|
-
*/
|
|
16
|
-
const UnsupportedTargetError = unsupportedTarget;
|
|
17
|
-
function unsupportedPoolFunction(pool, functionName) {
|
|
18
|
-
return {
|
|
19
|
-
code: "unsupportedPoolFunction",
|
|
20
|
-
message: `unsupported pool function "${functionName}" on ${pool}`,
|
|
21
|
-
pool,
|
|
22
|
-
functionName
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
Object.defineProperty(unsupportedPoolFunction, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedPoolFunction" });
|
|
26
|
-
/**
|
|
27
|
-
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
28
|
-
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
29
|
-
* the answer is never an `Error`.
|
|
30
|
-
*/
|
|
31
|
-
const UnsupportedPoolFunctionError = unsupportedPoolFunction;
|
|
32
|
-
//#endregion
|
|
33
|
-
export { UnsupportedPoolFunctionError, UnsupportedTargetError, UnsupportedZapperFunctionError };
|
|
1
|
+
export {};
|
|
@@ -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,17 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function unsupportedOperation(operation) {
|
|
3
|
-
return {
|
|
4
|
-
code: "unsupportedOperation",
|
|
5
|
-
message: `operation "${operation}" is not supported by previewOperation`,
|
|
6
|
-
operation
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(unsupportedOperation, Symbol.hasInstance, { value: (value) => typeof value === "object" && value !== null && value.code === "unsupportedOperation" });
|
|
10
|
-
/**
|
|
11
|
-
* Builds the verdict. Callable with or without `new`, so pre-declassing raise
|
|
12
|
-
* sites keep compiling; `instanceof` matches on the `code` discriminant, and
|
|
13
|
-
* the answer is never an `Error`.
|
|
14
|
-
*/
|
|
15
|
-
const UnsupportedOperationError = unsupportedOperation;
|
|
16
|
-
//#endregion
|
|
17
|
-
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,9 +1,5 @@
|
|
|
1
|
-
import { sdkErr, sdkOk } from "../../model/result.js";
|
|
1
|
+
import { isSDKError, sdkErr, sdkOk } from "../../model/result.js";
|
|
2
2
|
import "../../model/index.js";
|
|
3
|
-
import { UnsupportedZapperFunctionError } from "../../onchain/market/zapper/errors.js";
|
|
4
|
-
import { InvalidDelayedIntentError } from "../../onchain/accounts/withdrawal-compressor/errors.js";
|
|
5
|
-
import "../../onchain/index.js";
|
|
6
|
-
import { UnsupportedPoolFunctionError, UnsupportedTargetError } from "../parse/errors.js";
|
|
7
3
|
import { parseOperationCalldata } from "../parse/parseOperationCalldata.js";
|
|
8
4
|
import { isPoolOperation } from "../parse/types.js";
|
|
9
5
|
import "../parse/index.js";
|
|
@@ -11,55 +7,43 @@ import { buildDelayedStrategyPositionOperationPreview } from "./buildDelayedStra
|
|
|
11
7
|
import { isCloseOrRepay } from "./detectCloseOrRepay.js";
|
|
12
8
|
import { resolveDelayedClaimIntent } from "./detectDelayedClaim.js";
|
|
13
9
|
import { detectDelayedOperation } from "./detectDelayedOperation.js";
|
|
14
|
-
import { UnsupportedOperationError } from "./errors.js";
|
|
15
10
|
import { estimateClaimableAt } from "./estimateClaimableAt.js";
|
|
16
11
|
import { replayMulticall } from "./replayMulticall.js";
|
|
17
12
|
import { previewAdjustStrategyPosition } from "./previewAdjustStrategyPosition.js";
|
|
18
13
|
import { previewExitOrRepayStrategyPosition } from "./previewExitOrRepayStrategyPosition.js";
|
|
19
|
-
import { PreviewSimulationError } from "../simulate/errors.js";
|
|
20
14
|
import { previewOpenStrategyPosition } from "./previewOpenStrategyPosition.js";
|
|
21
15
|
import { previewPoolPositionOperation } from "./previewPoolPositionOperation.js";
|
|
22
16
|
//#region src/preview/preview/previewOperation.ts
|
|
23
17
|
/**
|
|
24
|
-
* Narrows a raised value to the verdict vocabulary: a plain non-`Error`
|
|
25
|
-
* object whose `code` is one of the preview verdicts. Genuine exceptions —
|
|
26
|
-
* bugs, outages, calldata the parser cannot read at all — fail the check and
|
|
27
|
-
* keep propagating as throws.
|
|
28
|
-
*/
|
|
29
|
-
function isPreviewVerdict(raised) {
|
|
30
|
-
if (typeof raised !== "object" || raised === null || raised instanceof Error) return false;
|
|
31
|
-
return raised instanceof UnsupportedTargetError || raised instanceof UnsupportedPoolFunctionError || raised instanceof UnsupportedZapperFunctionError || raised instanceof UnsupportedOperationError || raised instanceof InvalidDelayedIntentError || raised instanceof PreviewSimulationError;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
18
|
* Previews a raw operation calldata: decodes it into a typed operation and
|
|
35
19
|
* assembles an operation-specific, human-displayable preview.
|
|
36
20
|
*
|
|
37
21
|
* Answers an {@link SDKReturn} envelope: the preview behind `ok: true`, or —
|
|
38
22
|
* when the transaction is one the previewer refuses to read — a
|
|
39
|
-
* {@link
|
|
40
|
-
* means the SDK could not do its job (a read failed, the targeted
|
|
41
|
-
* account could not be resolved), not 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.
|
|
42
26
|
*/
|
|
43
27
|
async function previewOperation(input, options) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return sdkOk(await previewMulticallOperation(input, operation, resolved));
|
|
57
|
-
}
|
|
58
|
-
return sdkErr(UnsupportedOperationError(operation.operation));
|
|
59
|
-
} catch (raised) {
|
|
60
|
-
if (isPreviewVerdict(raised)) return sdkErr(raised);
|
|
61
|
-
throw raised;
|
|
28
|
+
const parsed = parseOperationCalldata(input);
|
|
29
|
+
if (isSDKError(parsed)) return parsed;
|
|
30
|
+
const operation = parsed.data;
|
|
31
|
+
if (isPoolOperation(operation)) return previewPoolPositionOperation(input, operation, options);
|
|
32
|
+
if (operation.operation === "OpenCreditAccount" || operation.operation === "RWAOpenCreditAccount") return sdkOk(await previewOpenStrategyPosition(input, operation));
|
|
33
|
+
if (operation.operation === "CloseCreditAccount") {
|
|
34
|
+
const resolved = await resolveCreditAccount(input, operation, options);
|
|
35
|
+
const preview = previewExitOrRepayStrategyPosition(input, operation, true, resolved);
|
|
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);
|
|
62
40
|
}
|
|
41
|
+
if (operation.operation === "MultiCall" || operation.operation === "BotMulticall" || operation.operation === "RWAMulticall") return previewMulticallOperation(input, operation, await resolveCreditAccount(input, operation, options));
|
|
42
|
+
return sdkErr({
|
|
43
|
+
code: "unsupportedOperation",
|
|
44
|
+
message: `operation "${operation.operation}" is not supported by previewOperation`,
|
|
45
|
+
operation: operation.operation
|
|
46
|
+
});
|
|
63
47
|
}
|
|
64
48
|
/**
|
|
65
49
|
* Resolves the pre-state of the credit account an operation targets: uses the
|
|
@@ -85,10 +69,14 @@ async function resolveCreditAccount(input, operation, options) {
|
|
|
85
69
|
async function previewMulticallOperation(input, operation, options) {
|
|
86
70
|
const { sdk } = input;
|
|
87
71
|
const instantPreview = isCloseOrRepay(operation.multicall) ? previewExitOrRepayStrategyPosition(input, operation, false, options) : previewAdjustStrategyPosition(input, operation, options);
|
|
88
|
-
const
|
|
72
|
+
const detected = detectDelayedOperation(sdk, operation.multicall);
|
|
73
|
+
if (isSDKError(detected)) return detected;
|
|
74
|
+
const delayed = detected.data;
|
|
89
75
|
if (!delayed) {
|
|
90
|
-
|
|
91
|
-
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);
|
|
92
80
|
}
|
|
93
81
|
const { before, after } = replayMulticall(sdk, operation, options);
|
|
94
82
|
const market = sdk.marketRegister.findByCreditManager(operation.creditManager);
|
|
@@ -96,7 +84,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
96
84
|
const meta = sdk.tokensMeta.get(market.underlying);
|
|
97
85
|
const receivedToken = meta && sdk.tokensMeta.isRWAUnderlying(meta) ? meta.asset : market.underlying;
|
|
98
86
|
const suite = sdk.marketRegister.findCreditManager(operation.creditManager);
|
|
99
|
-
return {
|
|
87
|
+
return sdkOk({
|
|
100
88
|
operation: "DelayedCreditAccountOperation",
|
|
101
89
|
creditAccount: operation.creditAccount,
|
|
102
90
|
...suite.creditOperationMarket(),
|
|
@@ -106,7 +94,7 @@ async function previewMulticallOperation(input, operation, options) {
|
|
|
106
94
|
estClaimableAt: estimateClaimableAt(sdk, delayed.request.phantomToken),
|
|
107
95
|
instantPreview,
|
|
108
96
|
delayedPreview: buildDelayedStrategyPositionOperationPreview(after.account, before, delayed, convert, receivedToken, sdk)
|
|
109
|
-
};
|
|
97
|
+
});
|
|
110
98
|
}
|
|
111
99
|
//#endregion
|
|
112
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 };
|