@gearbox-protocol/sdk 14.11.0-next.4 → 14.11.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common-utils/utils/index.js +2 -0
- package/dist/cjs/{history/trace-utils.js → common-utils/utils/trace.js} +62 -5
- package/dist/cjs/history/assembleOperations.js +6 -6
- package/dist/cjs/history/classifyMulticallOperations.js +31 -25
- package/dist/cjs/history/index.js +0 -2
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -6
- package/dist/cjs/history/toLegacyOperation.js +5 -1
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +25 -37
- package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/cjs/{history/internal-types.js → plugins/adapters/transfers.js} +2 -2
- package/dist/cjs/preview/index.js +3 -1
- package/dist/cjs/preview/parse/classifyInnerOperations.js +5 -43
- package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +48 -0
- package/dist/cjs/preview/parse/index.js +2 -0
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +13 -9
- package/dist/cjs/{history/inner-operations.js → preview/parse/types-adapters.js} +2 -2
- package/dist/cjs/preview/parse/types-facades.js +16 -0
- package/dist/cjs/preview/parse/types-pools.js +16 -0
- package/dist/cjs/preview/parse/types.js +8 -1
- package/dist/cjs/{history → preview/trace}/errors.js +0 -26
- package/dist/cjs/preview/trace/extractAdapterCallTraces.js +58 -0
- package/dist/cjs/{history → preview/trace}/extractTransfers.js +10 -13
- package/dist/cjs/{history → preview/trace}/findFacadeCalls.js +3 -3
- package/dist/cjs/preview/trace/index.js +30 -0
- package/dist/cjs/preview/trace/types.js +16 -0
- package/dist/esm/common-utils/utils/index.js +1 -0
- package/dist/esm/common-utils/utils/trace.js +93 -0
- package/dist/esm/history/assembleOperations.js +8 -6
- package/dist/esm/history/classifyMulticallOperations.js +29 -23
- package/dist/esm/history/index.js +0 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -4
- package/dist/esm/history/toLegacyOperation.js +5 -1
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +28 -38
- package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/esm/preview/index.js +1 -0
- package/dist/esm/preview/parse/classifyInnerOperations.js +6 -46
- package/dist/esm/preview/parse/extractExpectedBalanceChanges.js +24 -0
- package/dist/esm/preview/parse/index.js +1 -0
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +14 -14
- package/dist/esm/preview/parse/types-facades.js +0 -0
- package/dist/esm/preview/parse/types-pools.js +0 -0
- package/dist/esm/preview/parse/types.js +3 -0
- package/dist/esm/{history → preview/trace}/errors.js +0 -24
- package/dist/esm/preview/trace/extractAdapterCallTraces.js +40 -0
- package/dist/esm/{history → preview/trace}/extractTransfers.js +10 -13
- package/dist/esm/{history → preview/trace}/findFacadeCalls.js +4 -2
- package/dist/esm/preview/trace/index.js +5 -0
- package/dist/esm/preview/trace/types.js +0 -0
- package/dist/types/common-utils/utils/index.d.ts +1 -0
- package/dist/types/common-utils/utils/trace.d.ts +73 -0
- package/dist/types/history/assembleOperations.d.ts +11 -6
- package/dist/types/history/classifyMulticallOperations.d.ts +21 -9
- package/dist/types/history/index.d.ts +0 -1
- package/dist/types/history/mapOperations.d.ts +7 -9
- package/dist/types/history/types.d.ts +22 -65
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +16 -17
- package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +10 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/transferHelpers.d.ts +1 -1
- package/dist/types/plugins/adapters/transfers.d.ts +17 -0
- package/dist/types/plugins/adapters/types.d.ts +8 -46
- package/dist/types/preview/index.d.ts +1 -0
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +8 -8
- package/dist/types/preview/parse/extractExpectedBalanceChanges.d.ts +22 -0
- package/dist/types/preview/parse/index.d.ts +1 -0
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +4 -3
- package/dist/types/preview/parse/types-adapters.d.ts +69 -0
- package/dist/types/preview/parse/types-facades.d.ts +157 -0
- package/dist/types/preview/parse/types-pools.d.ts +42 -0
- package/dist/types/preview/parse/types.d.ts +12 -46
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +1 -1
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +1 -1
- package/dist/types/preview/simulate/types.d.ts +1 -1
- package/dist/types/{history → preview/trace}/errors.d.ts +0 -10
- package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +23 -0
- package/dist/types/{history → preview/trace}/extractTransfers.d.ts +14 -5
- package/dist/types/{history → preview/trace}/findFacadeCalls.d.ts +3 -2
- package/dist/types/preview/trace/index.d.ts +5 -0
- package/dist/types/preview/trace/types.d.ts +21 -0
- package/package.json +1 -1
- package/dist/cjs/history/extractProtocolCalls.js +0 -53
- package/dist/esm/history/extractProtocolCalls.js +0 -32
- package/dist/esm/history/trace-utils.js +0 -36
- package/dist/types/history/extractProtocolCalls.d.ts +0 -8
- package/dist/types/history/inner-operations.d.ts +0 -57
- package/dist/types/history/internal-types.d.ts +0 -47
- package/dist/types/history/trace-utils.d.ts +0 -12
- /package/dist/esm/{history/inner-operations.js → plugins/adapters/transfers.js} +0 -0
- /package/dist/esm/{history/internal-types.js → preview/parse/types-adapters.js} +0 -0
|
@@ -23,6 +23,7 @@ __export(parseFacadeOperationCalldata_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(parseFacadeOperationCalldata_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
var import_classifyInnerOperations = require("./classifyInnerOperations.js");
|
|
26
|
+
var import_extractExpectedBalanceChanges = require("./extractExpectedBalanceChanges.js");
|
|
26
27
|
function parseFacadeOperationCalldata(props) {
|
|
27
28
|
const { sdk, facade, calldata } = props;
|
|
28
29
|
const parsed = sdk.parseFunctionDataV2(facade.address, calldata);
|
|
@@ -36,30 +37,30 @@ function parseFacadeOperationCalldata(props) {
|
|
|
36
37
|
}
|
|
37
38
|
const metadata = {
|
|
38
39
|
creditManager: suite.creditManager.address,
|
|
39
|
-
creditFacade: facade.address
|
|
40
|
-
blockNumber: Number(sdk.currentBlock),
|
|
41
|
-
txHash: import_viem.zeroHash,
|
|
42
|
-
timestamp: 0
|
|
40
|
+
creditFacade: facade.address
|
|
43
41
|
};
|
|
44
42
|
const innerCalls = rawArgs.calls ?? [];
|
|
45
43
|
const multicall = (0, import_classifyInnerOperations.classifyInnerOperations)(innerCalls, {
|
|
46
44
|
sdk,
|
|
47
45
|
underlying: suite.underlying
|
|
48
46
|
});
|
|
47
|
+
const expectedBalanceChanges = (0, import_extractExpectedBalanceChanges.extractExpectedBalanceChanges)(innerCalls);
|
|
49
48
|
switch (functionName) {
|
|
50
49
|
case "multicall":
|
|
51
50
|
return {
|
|
52
51
|
...metadata,
|
|
53
52
|
operation: "MultiCall",
|
|
54
53
|
creditAccount: rawArgs.creditAccount,
|
|
55
|
-
multicall
|
|
54
|
+
multicall,
|
|
55
|
+
expectedBalanceChanges
|
|
56
56
|
};
|
|
57
57
|
case "botMulticall":
|
|
58
58
|
return {
|
|
59
59
|
...metadata,
|
|
60
60
|
operation: "BotMulticall",
|
|
61
61
|
creditAccount: rawArgs.creditAccount,
|
|
62
|
-
multicall
|
|
62
|
+
multicall,
|
|
63
|
+
expectedBalanceChanges
|
|
63
64
|
};
|
|
64
65
|
case "openCreditAccount":
|
|
65
66
|
return {
|
|
@@ -68,14 +69,16 @@ function parseFacadeOperationCalldata(props) {
|
|
|
68
69
|
creditAccount: import_viem.zeroAddress,
|
|
69
70
|
onBehalfOf: rawArgs.onBehalfOf,
|
|
70
71
|
referralCode: rawArgs.referralCode,
|
|
71
|
-
multicall
|
|
72
|
+
multicall,
|
|
73
|
+
expectedBalanceChanges
|
|
72
74
|
};
|
|
73
75
|
case "closeCreditAccount":
|
|
74
76
|
return {
|
|
75
77
|
...metadata,
|
|
76
78
|
operation: "CloseCreditAccount",
|
|
77
79
|
creditAccount: rawArgs.creditAccount,
|
|
78
|
-
multicall
|
|
80
|
+
multicall,
|
|
81
|
+
expectedBalanceChanges
|
|
79
82
|
};
|
|
80
83
|
case "liquidateCreditAccount":
|
|
81
84
|
return {
|
|
@@ -87,7 +90,8 @@ function parseFacadeOperationCalldata(props) {
|
|
|
87
90
|
// liquidation, so they are not recoverable from raw calldata.
|
|
88
91
|
token: import_viem.zeroAddress,
|
|
89
92
|
remainingFunds: 0n,
|
|
90
|
-
multicall
|
|
93
|
+
multicall,
|
|
94
|
+
expectedBalanceChanges
|
|
91
95
|
};
|
|
92
96
|
case "partiallyLiquidateCreditAccount":
|
|
93
97
|
return {
|
|
@@ -12,5 +12,5 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
return to;
|
|
13
13
|
};
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
15
|
+
var types_adapters_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_adapters_exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_facades_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_facades_exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_pools_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_pools_exports);
|
|
@@ -15,16 +15,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
}
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
20
|
var types_exports = {};
|
|
20
21
|
__export(types_exports, {
|
|
21
22
|
isPoolOperation: () => isPoolOperation
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(types_exports);
|
|
25
|
+
__reExport(types_exports, require("./types-adapters.js"), module.exports);
|
|
26
|
+
__reExport(types_exports, require("./types-facades.js"), module.exports);
|
|
27
|
+
__reExport(types_exports, require("./types-pools.js"), module.exports);
|
|
24
28
|
function isPoolOperation(tx) {
|
|
25
29
|
return tx.operation === "Deposit" || tx.operation === "Redeem";
|
|
26
30
|
}
|
|
27
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
32
|
0 && (module.exports = {
|
|
29
|
-
isPoolOperation
|
|
33
|
+
isPoolOperation,
|
|
34
|
+
...require("./types-adapters.js"),
|
|
35
|
+
...require("./types-facades.js"),
|
|
36
|
+
...require("./types-pools.js")
|
|
30
37
|
});
|
|
@@ -18,8 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var errors_exports = {};
|
|
20
20
|
__export(errors_exports, {
|
|
21
|
-
AdapterTraceAlignmentError: () => AdapterTraceAlignmentError,
|
|
22
|
-
ProtocolCallNotFoundError: () => ProtocolCallNotFoundError,
|
|
23
21
|
TransferAlignmentError: () => TransferAlignmentError,
|
|
24
22
|
UnexpectedFacadeEventOrderError: () => UnexpectedFacadeEventOrderError,
|
|
25
23
|
UnknownAdapterError: () => UnknownAdapterError,
|
|
@@ -51,28 +49,6 @@ class WithdrawCollateralAlignmentError extends Error {
|
|
|
51
49
|
this.name = "WithdrawCollateralAlignmentError";
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
class ProtocolCallNotFoundError extends Error {
|
|
55
|
-
targetContract;
|
|
56
|
-
executeIndex;
|
|
57
|
-
constructor(targetContract, executeIndex) {
|
|
58
|
-
super(
|
|
59
|
-
`protocol call to ${targetContract} not found in trace for Execute #${executeIndex}`
|
|
60
|
-
);
|
|
61
|
-
this.name = "ProtocolCallNotFoundError";
|
|
62
|
-
this.targetContract = targetContract;
|
|
63
|
-
this.executeIndex = executeIndex;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
class AdapterTraceAlignmentError extends Error {
|
|
67
|
-
constructor(expected, actual) {
|
|
68
|
-
super(`found ${actual} adapter traces for ${expected} execute events`);
|
|
69
|
-
this.expected = expected;
|
|
70
|
-
this.actual = actual;
|
|
71
|
-
this.name = "AdapterTracesAlignmentError";
|
|
72
|
-
}
|
|
73
|
-
expected;
|
|
74
|
-
actual;
|
|
75
|
-
}
|
|
76
52
|
class UnexpectedFacadeEventOrderError extends Error {
|
|
77
53
|
constructor(e) {
|
|
78
54
|
super(
|
|
@@ -93,8 +69,6 @@ class UnknownFacadeCallError extends Error {
|
|
|
93
69
|
}
|
|
94
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
95
71
|
0 && (module.exports = {
|
|
96
|
-
AdapterTraceAlignmentError,
|
|
97
|
-
ProtocolCallNotFoundError,
|
|
98
72
|
TransferAlignmentError,
|
|
99
73
|
UnexpectedFacadeEventOrderError,
|
|
100
74
|
UnknownAdapterError,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var extractAdapterCallTraces_exports = {};
|
|
20
|
+
__export(extractAdapterCallTraces_exports, {
|
|
21
|
+
extractAdapterCallTraces: () => extractAdapterCallTraces
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extractAdapterCallTraces_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
var import_trace = require("../../common-utils/utils/trace.js");
|
|
26
|
+
const WITHDRAW_PHANTOM_TOKEN_SELECTOR = (0, import_viem.toFunctionSelector)(
|
|
27
|
+
"withdrawPhantomToken(address,uint256)"
|
|
28
|
+
);
|
|
29
|
+
const GET_PHANTOM_TOKEN_INFO_SELECTOR = (0, import_viem.toFunctionSelector)(
|
|
30
|
+
"getPhantomTokenInfo()"
|
|
31
|
+
);
|
|
32
|
+
function isSynthesizedPhantomWithdrawal(siblings, index) {
|
|
33
|
+
const node = siblings[index];
|
|
34
|
+
if (node.type !== "CALL" || node.input.slice(0, 10).toLowerCase() !== WITHDRAW_PHANTOM_TOKEN_SELECTOR) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const [token] = (0, import_viem.decodeAbiParameters)(
|
|
38
|
+
[{ type: "address" }, { type: "uint256" }],
|
|
39
|
+
`0x${node.input.slice(10)}`
|
|
40
|
+
);
|
|
41
|
+
for (let i = 0; i < index; i++) {
|
|
42
|
+
const sib = siblings[i];
|
|
43
|
+
if (sib.type === "STATICCALL" && sib.input.slice(0, 10).toLowerCase() === GET_PHANTOM_TOKEN_INFO_SELECTOR && (0, import_viem.isAddressEqual)(sib.to, token)) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function extractAdapterCallTraces(facadeTrace) {
|
|
50
|
+
const subtraces = facadeTrace.calls ?? [];
|
|
51
|
+
return subtraces.filter(
|
|
52
|
+
(sub, index) => (0, import_trace.resolveProtocolCall)(sub) !== void 0 && !isSynthesizedPhantomWithdrawal(subtraces, index)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
extractAdapterCallTraces
|
|
58
|
+
});
|
|
@@ -22,14 +22,14 @@ __export(extractTransfers_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(extractTransfers_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
-
var import_generated = require("
|
|
26
|
-
var import_iERC20 = require("
|
|
27
|
-
var import_sdk = require("
|
|
25
|
+
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
+
var import_iERC20 = require("../../abi/iERC20.js");
|
|
27
|
+
var import_sdk = require("../../sdk/index.js");
|
|
28
28
|
var import_errors = require("./errors.js");
|
|
29
29
|
function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
30
30
|
const ranges = buildOperationRanges(logs, creditFacade, creditAccount);
|
|
31
31
|
let currentEntries = [];
|
|
32
|
-
const
|
|
32
|
+
const executeTransfers = [];
|
|
33
33
|
const directTransfers = [];
|
|
34
34
|
const phantomTokens = new import_sdk.AddressMap();
|
|
35
35
|
const withdrawCollateralEvents = [];
|
|
@@ -38,20 +38,17 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
38
38
|
const facadeEvent = tryDecodeFacadeEvent(log, creditFacade);
|
|
39
39
|
if (facadeEvent) {
|
|
40
40
|
if (isExecute(facadeEvent, creditAccount)) {
|
|
41
|
-
|
|
42
|
-
transfers: currentEntries,
|
|
43
|
-
targetContract: facadeEvent.args.targetContract
|
|
44
|
-
});
|
|
41
|
+
executeTransfers.push(currentEntries);
|
|
45
42
|
} else if (isLiquidation(facadeEvent, creditAccount)) {
|
|
46
43
|
liquidationRemainingFunds = facadeEvent.args.remainingFunds;
|
|
47
44
|
} else if (isWithdrawPhantomToken(facadeEvent, creditAccount)) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
45
|
+
const phantomTransfers = executeTransfers.pop();
|
|
46
|
+
if (!phantomTransfers) {
|
|
50
47
|
throw new Error(
|
|
51
48
|
`WithdrawPhantomToken without preceding Execute at logIndex ${facadeEvent.logIndex}`
|
|
52
49
|
);
|
|
53
50
|
}
|
|
54
|
-
const rawDeposit =
|
|
51
|
+
const rawDeposit = phantomTransfers.find(
|
|
55
52
|
(t) => (0, import_viem.isAddressEqual)(t.to, creditAccount)
|
|
56
53
|
);
|
|
57
54
|
if (!rawDeposit) {
|
|
@@ -86,11 +83,11 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
86
83
|
currentEntries.push({ token, amount: value, from, to });
|
|
87
84
|
}
|
|
88
85
|
if ((0, import_viem.isAddressEqual)(to, creditAccount) && !isInRange(log.logIndex, ranges)) {
|
|
89
|
-
directTransfers.push({ token,
|
|
86
|
+
directTransfers.push({ token, amount: value, from, to });
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
89
|
return {
|
|
93
|
-
|
|
90
|
+
executeTransfers,
|
|
94
91
|
directTransfers,
|
|
95
92
|
liquidationRemainingFunds,
|
|
96
93
|
phantomTokens,
|
|
@@ -22,9 +22,9 @@ __export(findFacadeCalls_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(findFacadeCalls_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
-
var import_generated = require("
|
|
25
|
+
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
+
var import_trace = require("../../common-utils/utils/trace.js");
|
|
26
27
|
var import_errors = require("./errors.js");
|
|
27
|
-
var import_trace_utils = require("./trace-utils.js");
|
|
28
28
|
const FACADE_CALL_TYPES = {
|
|
29
29
|
multicall: "MultiCall",
|
|
30
30
|
botMulticall: "BotMulticall",
|
|
@@ -48,7 +48,7 @@ function extractCreditAccount(operation, rawArgs, traceOutput) {
|
|
|
48
48
|
return ca;
|
|
49
49
|
}
|
|
50
50
|
function findFacadeCalls(trace, creditFacade, creditAccount, register, strict) {
|
|
51
|
-
const facadeTraces = (0,
|
|
51
|
+
const facadeTraces = (0, import_trace.collectTraces)(trace, creditFacade);
|
|
52
52
|
const results = [];
|
|
53
53
|
for (const trace2 of facadeTraces) {
|
|
54
54
|
const parsed = register.parseFunctionDataV2(
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var trace_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(trace_exports);
|
|
18
|
+
__reExport(trace_exports, require("./errors.js"), module.exports);
|
|
19
|
+
__reExport(trace_exports, require("./extractAdapterCallTraces.js"), module.exports);
|
|
20
|
+
__reExport(trace_exports, require("./extractTransfers.js"), module.exports);
|
|
21
|
+
__reExport(trace_exports, require("./findFacadeCalls.js"), module.exports);
|
|
22
|
+
__reExport(trace_exports, require("./types.js"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./errors.js"),
|
|
26
|
+
...require("./extractAdapterCallTraces.js"),
|
|
27
|
+
...require("./extractTransfers.js"),
|
|
28
|
+
...require("./findFacadeCalls.js"),
|
|
29
|
+
...require("./types.js")
|
|
30
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAbiParameters,
|
|
3
|
+
getAddress,
|
|
4
|
+
isAddressEqual
|
|
5
|
+
} from "viem";
|
|
6
|
+
const EXECUTE_BYTES_SELECTOR = "0x09c5eabe";
|
|
7
|
+
function findExecuteBytes(node) {
|
|
8
|
+
const queue = [node];
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
const current = queue.shift();
|
|
11
|
+
if (current.error) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (current.input.slice(0, 10).toLowerCase() === EXECUTE_BYTES_SELECTOR) {
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
if (current.calls) {
|
|
18
|
+
queue.push(...current.calls);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
function findCallWithInput(node, input) {
|
|
24
|
+
if (node.error) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
if (node.type === "CALL" && node.input.toLowerCase() === input.toLowerCase()) {
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
if (node.calls) {
|
|
31
|
+
for (const child of node.calls) {
|
|
32
|
+
const found = findCallWithInput(child, input);
|
|
33
|
+
if (found) {
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
function resolveProtocolCall(node) {
|
|
41
|
+
const executeNode = findExecuteBytes(node);
|
|
42
|
+
if (!executeNode) {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
const [calldata] = decodeAbiParameters(
|
|
46
|
+
[{ type: "bytes" }],
|
|
47
|
+
`0x${executeNode.input.slice(10)}`
|
|
48
|
+
);
|
|
49
|
+
const targetCall = findCallWithInput(executeNode, calldata);
|
|
50
|
+
if (!targetCall) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
return { contract: getAddress(targetCall.to), calldata };
|
|
54
|
+
}
|
|
55
|
+
function findCallTo(node, target) {
|
|
56
|
+
if (node.error) {
|
|
57
|
+
return void 0;
|
|
58
|
+
}
|
|
59
|
+
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
60
|
+
return node;
|
|
61
|
+
}
|
|
62
|
+
if (node.calls) {
|
|
63
|
+
for (const child of node.calls) {
|
|
64
|
+
const found = findCallTo(child, target);
|
|
65
|
+
if (found) {
|
|
66
|
+
return found;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
function collectTraces(node, target) {
|
|
73
|
+
const results = [];
|
|
74
|
+
if (node.error) {
|
|
75
|
+
return results;
|
|
76
|
+
}
|
|
77
|
+
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
78
|
+
results.push(node);
|
|
79
|
+
} else if (node.calls) {
|
|
80
|
+
for (const child of node.calls) {
|
|
81
|
+
results.push(...collectTraces(child, target));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
EXECUTE_BYTES_SELECTOR,
|
|
88
|
+
collectTraces,
|
|
89
|
+
findCallTo,
|
|
90
|
+
findCallWithInput,
|
|
91
|
+
findExecuteBytes,
|
|
92
|
+
resolveProtocolCall
|
|
93
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AbstractAdapterContract } from "../plugins/adapters/index.js";
|
|
2
|
+
import {
|
|
3
|
+
extractAdapterCallTraces
|
|
4
|
+
} from "../preview/trace/index.js";
|
|
2
5
|
import { classifyMulticallOperations } from "./classifyMulticallOperations.js";
|
|
3
|
-
import { extractProtocolCalls } from "./extractProtocolCalls.js";
|
|
4
6
|
function assembleOperations(input) {
|
|
5
7
|
const {
|
|
6
8
|
facadeCalls,
|
|
7
|
-
|
|
9
|
+
executeTransfers,
|
|
8
10
|
register,
|
|
9
11
|
underlying,
|
|
10
12
|
liquidationRemainingFunds,
|
|
@@ -19,7 +21,7 @@ function assembleOperations(input) {
|
|
|
19
21
|
return assemblePartialLiquidation(fc);
|
|
20
22
|
}
|
|
21
23
|
const count = countAdapterCalls(fc.innerCalls, register);
|
|
22
|
-
const sliced =
|
|
24
|
+
const sliced = executeTransfers.slice(executeOffset, executeOffset + count);
|
|
23
25
|
executeOffset += count;
|
|
24
26
|
const withdrawCount = countWithdrawCollateralCalls(fc.innerCalls);
|
|
25
27
|
const slicedWithdrawEvents = withdrawCollateralEvents.slice(
|
|
@@ -27,11 +29,11 @@ function assembleOperations(input) {
|
|
|
27
29
|
withdrawOffset + withdrawCount
|
|
28
30
|
);
|
|
29
31
|
withdrawOffset += withdrawCount;
|
|
30
|
-
const
|
|
32
|
+
const adapterTraces = extractAdapterCallTraces(fc.trace);
|
|
31
33
|
const multicall = classifyMulticallOperations({
|
|
32
34
|
innerCalls: fc.innerCalls,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
executeTransfers: sliced,
|
|
36
|
+
adapterTraces,
|
|
35
37
|
register,
|
|
36
38
|
creditAccount: fc.creditAccount,
|
|
37
39
|
underlying,
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
TransferAlignmentError,
|
|
9
9
|
UnknownAdapterError,
|
|
10
10
|
WithdrawCollateralAlignmentError
|
|
11
|
-
} from "
|
|
11
|
+
} from "../preview/trace/index.js";
|
|
12
12
|
function classifyMulticallOperations(input) {
|
|
13
13
|
const {
|
|
14
14
|
innerCalls,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
executeTransfers,
|
|
16
|
+
adapterTraces,
|
|
17
17
|
register,
|
|
18
18
|
creditAccount,
|
|
19
19
|
underlying,
|
|
@@ -28,20 +28,27 @@ function classifyMulticallOperations(input) {
|
|
|
28
28
|
const contract = register.getContract(call.target);
|
|
29
29
|
if (contract instanceof AbstractAdapterContract) {
|
|
30
30
|
const idx = transferIdx++;
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
throw new TransferAlignmentError(
|
|
31
|
+
const transfers2 = executeTransfers[idx];
|
|
32
|
+
if (!transfers2) {
|
|
33
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const partial = contract.parseAdapterOperation(
|
|
35
|
+
const protocol = contract.parseProtocolCall(adapterTraces[idx], strict);
|
|
36
|
+
const legacy = contract.classifyLegacyOperation(
|
|
38
37
|
call,
|
|
39
|
-
transfers2,
|
|
40
|
-
creditAccount,
|
|
41
|
-
protocolCalldata,
|
|
42
|
-
strict
|
|
38
|
+
toNetTransfers(transfers2, creditAccount)
|
|
43
39
|
);
|
|
44
|
-
|
|
40
|
+
result.push({
|
|
41
|
+
operation: "Execute",
|
|
42
|
+
adapter: call.target,
|
|
43
|
+
adapterType: call.contractType,
|
|
44
|
+
version: call.version,
|
|
45
|
+
label: call.label,
|
|
46
|
+
adapterFunctionName: call.functionName,
|
|
47
|
+
adapterArgs: call.rawArgs,
|
|
48
|
+
protocol,
|
|
49
|
+
transfers: transfers2,
|
|
50
|
+
legacy
|
|
51
|
+
});
|
|
45
52
|
continue;
|
|
46
53
|
}
|
|
47
54
|
if (contract !== void 0) {
|
|
@@ -60,23 +67,22 @@ function classifyMulticallOperations(input) {
|
|
|
60
67
|
throw new UnknownAdapterError(call.target);
|
|
61
68
|
}
|
|
62
69
|
const unknownIdx = transferIdx++;
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
65
|
-
throw new TransferAlignmentError(
|
|
70
|
+
const transfers = executeTransfers[unknownIdx];
|
|
71
|
+
if (!transfers) {
|
|
72
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
66
73
|
}
|
|
67
|
-
const { transfers, targetContract } = unknownResult;
|
|
68
74
|
const netTransfers = toNetTransfers(transfers, creditAccount);
|
|
69
75
|
result.push({
|
|
70
76
|
operation: "Execute",
|
|
71
77
|
adapter: call.target,
|
|
72
|
-
protocol: targetContract,
|
|
73
78
|
adapterType: call.contractType,
|
|
74
79
|
version: call.version,
|
|
75
80
|
label: call.label,
|
|
76
81
|
adapterFunctionName: call.functionName,
|
|
77
82
|
adapterArgs: call.rawArgs,
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
// Unknown adapter (non-strict): we have no ABI to decode the protocol
|
|
84
|
+
// call, so `protocol` is left absent rather than filled with placeholders.
|
|
85
|
+
protocol: void 0,
|
|
80
86
|
transfers,
|
|
81
87
|
legacy: {
|
|
82
88
|
operation: "Swap",
|
|
@@ -84,8 +90,8 @@ function classifyMulticallOperations(input) {
|
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
92
|
}
|
|
87
|
-
if (transferIdx !==
|
|
88
|
-
throw new TransferAlignmentError(
|
|
93
|
+
if (transferIdx !== executeTransfers.length) {
|
|
94
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
89
95
|
}
|
|
90
96
|
if (withdrawCollateralEvents && withdrawCollateralEvents.length > 0 && withdrawIdx !== withdrawCollateralEvents.length) {
|
|
91
97
|
throw new WithdrawCollateralAlignmentError(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { extractTransfers, findFacadeCalls } from "../preview/trace/index.js";
|
|
1
2
|
import { assembleOperations } from "./assembleOperations.js";
|
|
2
|
-
import { extractTransfers } from "./extractTransfers.js";
|
|
3
|
-
import { findFacadeCalls } from "./findFacadeCalls.js";
|
|
4
3
|
function parseCreditAccountTransaction(input) {
|
|
5
4
|
const {
|
|
6
5
|
trace,
|
|
@@ -25,7 +24,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
25
24
|
strict
|
|
26
25
|
);
|
|
27
26
|
const {
|
|
28
|
-
|
|
27
|
+
executeTransfers,
|
|
29
28
|
directTransfers,
|
|
30
29
|
liquidationRemainingFunds,
|
|
31
30
|
phantomTokens,
|
|
@@ -40,7 +39,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
40
39
|
};
|
|
41
40
|
const facadeOps = assembleOperations({
|
|
42
41
|
facadeCalls,
|
|
43
|
-
|
|
42
|
+
executeTransfers,
|
|
44
43
|
register,
|
|
45
44
|
underlying,
|
|
46
45
|
liquidationRemainingFunds,
|
|
@@ -24,7 +24,11 @@ function createLegacyVisitor(params) {
|
|
|
24
24
|
blockNum: ctx.blockNumber,
|
|
25
25
|
timestamp: ctx.timestamp,
|
|
26
26
|
sessionId: params.sessionId,
|
|
27
|
-
protocol
|
|
27
|
+
// `protocol` may be absent (migrator adapter, unknown adapter in
|
|
28
|
+
// non-strict mode, or undecodable calldata). The deprecated charts
|
|
29
|
+
// output still needs an address, so fall back to the on-chain adapter
|
|
30
|
+
// address, which is the closest meaningful value.
|
|
31
|
+
protocol: op.protocol?.contract ?? op.adapter
|
|
28
32
|
};
|
|
29
33
|
},
|
|
30
34
|
IncreaseBorrowedAmount(op, ctx) {
|