@gearbox-protocol/sdk 14.11.0-next.9 → 14.11.0
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 +0 -2
- package/dist/cjs/dev/index.js +1 -3
- package/dist/cjs/dev/isOutOfSyncError.js +3 -1
- package/dist/cjs/history/assembleOperations.js +6 -6
- package/dist/cjs/history/classifyMulticallOperations.js +25 -31
- package/dist/cjs/{preview/trace → history}/errors.js +26 -0
- package/dist/cjs/history/extractProtocolCalls.js +53 -0
- package/dist/cjs/{preview/trace → history}/extractTransfers.js +23 -11
- package/dist/cjs/{preview/trace → history}/findFacadeCalls.js +3 -3
- package/dist/cjs/history/index.js +2 -0
- package/dist/cjs/{preview/parse/types-facades.js → history/inner-operations.js} +2 -2
- package/dist/cjs/{preview/parse/types-adapters.js → history/internal-types.js} +2 -2
- package/dist/cjs/history/parseCreditAccountTransaction.js +6 -5
- package/dist/cjs/history/toLegacyOperation.js +2 -6
- package/dist/cjs/{common-utils/utils/trace.js → history/trace-utils.js} +5 -62
- package/dist/cjs/permissionless/bindings/pricefeeds/curve-twap.js +2 -2
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +37 -25
- package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +0 -9
- package/dist/esm/common-utils/utils/index.js +0 -1
- package/dist/esm/dev/index.js +0 -1
- package/dist/esm/dev/isOutOfSyncError.js +3 -1
- package/dist/esm/history/assembleOperations.js +6 -8
- package/dist/esm/history/classifyMulticallOperations.js +23 -29
- package/dist/esm/{preview/trace → history}/errors.js +24 -0
- package/dist/esm/history/extractProtocolCalls.js +32 -0
- package/dist/esm/{preview/trace → history}/extractTransfers.js +23 -11
- package/dist/esm/{preview/trace → history}/findFacadeCalls.js +2 -4
- package/dist/esm/history/index.js +1 -0
- package/dist/esm/history/parseCreditAccountTransaction.js +4 -3
- package/dist/esm/history/toLegacyOperation.js +2 -6
- package/dist/esm/history/trace-utils.js +36 -0
- package/dist/esm/permissionless/bindings/pricefeeds/curve-twap.js +2 -2
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +38 -28
- package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +0 -9
- package/dist/types/common-utils/utils/index.d.ts +0 -1
- package/dist/types/dev/index.d.ts +0 -1
- package/dist/types/history/assembleOperations.d.ts +6 -11
- package/dist/types/history/classifyMulticallOperations.d.ts +9 -21
- package/dist/types/{preview/trace → history}/errors.d.ts +10 -0
- package/dist/types/history/extractProtocolCalls.d.ts +8 -0
- package/dist/types/{preview/trace → history}/extractTransfers.d.ts +7 -15
- package/dist/types/{preview/trace → history}/findFacadeCalls.d.ts +2 -3
- package/dist/types/history/index.d.ts +1 -0
- package/dist/types/history/inner-operations.d.ts +57 -0
- package/dist/types/history/internal-types.d.ts +47 -0
- package/dist/types/history/mapOperations.d.ts +9 -7
- package/dist/types/history/trace-utils.d.ts +12 -0
- package/dist/types/history/types.d.ts +71 -22
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +17 -16
- package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +1 -10
- 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/types.d.ts +46 -8
- package/package.json +1 -6
- package/dist/cjs/dev/verifyTestnet.js +0 -124
- package/dist/cjs/plugins/adapters/transfers.js +0 -16
- package/dist/cjs/preview/index.js +0 -28
- package/dist/cjs/preview/package.json +0 -1
- package/dist/cjs/preview/parse/classifyInnerOperations.js +0 -92
- package/dist/cjs/preview/parse/errors.js +0 -47
- package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +0 -48
- package/dist/cjs/preview/parse/index.js +0 -34
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +0 -115
- package/dist/cjs/preview/parse/parseOperationCalldata.js +0 -46
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +0 -77
- package/dist/cjs/preview/parse/types-pools.js +0 -16
- package/dist/cjs/preview/parse/types.js +0 -37
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +0 -78
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +0 -77
- package/dist/cjs/preview/prerequisites/Prerequisite.js +0 -85
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +0 -187
- package/dist/cjs/preview/prerequisites/index.js +0 -34
- package/dist/cjs/preview/prerequisites/prepareAction.js +0 -48
- package/dist/cjs/preview/prerequisites/runPrerequisites.js +0 -71
- package/dist/cjs/preview/prerequisites/types.js +0 -16
- package/dist/cjs/preview/simulate/constants.js +0 -28
- package/dist/cjs/preview/simulate/errors.js +0 -98
- package/dist/cjs/preview/simulate/extractERC20Transfers.js +0 -47
- package/dist/cjs/preview/simulate/holders.js +0 -45
- package/dist/cjs/preview/simulate/index.js +0 -40
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +0 -30
- package/dist/cjs/preview/simulate/simulateOperation.js +0 -37
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +0 -155
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +0 -106
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +0 -62
- package/dist/cjs/preview/simulate/types.js +0 -16
- package/dist/cjs/preview/trace/extractAdapterCallTraces.js +0 -58
- package/dist/cjs/preview/trace/index.js +0 -30
- package/dist/cjs/preview/trace/types.js +0 -16
- package/dist/esm/common-utils/utils/trace.js +0 -93
- package/dist/esm/dev/verifyTestnet.js +0 -98
- package/dist/esm/preview/index.js +0 -4
- package/dist/esm/preview/package.json +0 -1
- package/dist/esm/preview/parse/classifyInnerOperations.js +0 -68
- package/dist/esm/preview/parse/errors.js +0 -22
- package/dist/esm/preview/parse/extractExpectedBalanceChanges.js +0 -24
- package/dist/esm/preview/parse/index.js +0 -7
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +0 -91
- package/dist/esm/preview/parse/parseOperationCalldata.js +0 -25
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +0 -53
- 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 +0 -9
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +0 -57
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +0 -56
- package/dist/esm/preview/prerequisites/Prerequisite.js +0 -63
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +0 -163
- package/dist/esm/preview/prerequisites/index.js +0 -7
- package/dist/esm/preview/prerequisites/prepareAction.js +0 -23
- package/dist/esm/preview/prerequisites/runPrerequisites.js +0 -47
- package/dist/esm/preview/prerequisites/types.js +0 -0
- package/dist/esm/preview/simulate/constants.js +0 -4
- package/dist/esm/preview/simulate/errors.js +0 -75
- package/dist/esm/preview/simulate/extractERC20Transfers.js +0 -23
- package/dist/esm/preview/simulate/holders.js +0 -21
- package/dist/esm/preview/simulate/index.js +0 -12
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +0 -6
- package/dist/esm/preview/simulate/simulateOperation.js +0 -13
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +0 -130
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +0 -82
- package/dist/esm/preview/simulate/simulatePoolOperation.js +0 -41
- package/dist/esm/preview/simulate/types.js +0 -0
- package/dist/esm/preview/trace/extractAdapterCallTraces.js +0 -40
- package/dist/esm/preview/trace/index.js +0 -5
- package/dist/esm/preview/trace/types.js +0 -0
- package/dist/types/common-utils/utils/trace.d.ts +0 -73
- package/dist/types/dev/verifyTestnet.d.ts +0 -82
- package/dist/types/plugins/adapters/transfers.d.ts +0 -17
- package/dist/types/preview/index.d.ts +0 -4
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +0 -21
- package/dist/types/preview/parse/errors.d.ts +0 -17
- package/dist/types/preview/parse/extractExpectedBalanceChanges.d.ts +0 -22
- package/dist/types/preview/parse/index.d.ts +0 -7
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +0 -19
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +0 -23
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +0 -17
- package/dist/types/preview/parse/types-adapters.d.ts +0 -69
- package/dist/types/preview/parse/types-facades.d.ts +0 -157
- package/dist/types/preview/parse/types-pools.d.ts +0 -55
- package/dist/types/preview/parse/types.d.ts +0 -44
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +0 -24
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +0 -23
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +0 -60
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +0 -16
- package/dist/types/preview/prerequisites/index.d.ts +0 -7
- package/dist/types/preview/prerequisites/prepareAction.d.ts +0 -52
- package/dist/types/preview/prerequisites/runPrerequisites.d.ts +0 -12
- package/dist/types/preview/prerequisites/types.d.ts +0 -78
- package/dist/types/preview/simulate/constants.d.ts +0 -6
- package/dist/types/preview/simulate/errors.d.ts +0 -51
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +0 -11
- package/dist/types/preview/simulate/holders.d.ts +0 -7
- package/dist/types/preview/simulate/index.d.ts +0 -9
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +0 -25
- package/dist/types/preview/simulate/simulateOperation.d.ts +0 -20
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +0 -28
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +0 -14
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +0 -8
- package/dist/types/preview/simulate/types.d.ts +0 -79
- package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +0 -23
- package/dist/types/preview/trace/index.d.ts +0 -5
- package/dist/types/preview/trace/types.d.ts +0 -21
- /package/dist/esm/{plugins/adapters/transfers.js → history/inner-operations.js} +0 -0
- /package/dist/esm/{preview/parse/types-adapters.js → history/internal-types.js} +0 -0
|
@@ -22,7 +22,6 @@ __reExport(utils_exports, require("./constants.js"), module.exports);
|
|
|
22
22
|
__reExport(utils_exports, require("./creditAccount/index.js"), module.exports);
|
|
23
23
|
__reExport(utils_exports, require("./price-math.js"), module.exports);
|
|
24
24
|
__reExport(utils_exports, require("./strategies/index.js"), module.exports);
|
|
25
|
-
__reExport(utils_exports, require("./trace.js"), module.exports);
|
|
26
25
|
__reExport(utils_exports, require("./validation/index.js"), module.exports);
|
|
27
26
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
27
|
0 && (module.exports = {
|
|
@@ -33,6 +32,5 @@ __reExport(utils_exports, require("./validation/index.js"), module.exports);
|
|
|
33
32
|
...require("./creditAccount/index.js"),
|
|
34
33
|
...require("./price-math.js"),
|
|
35
34
|
...require("./strategies/index.js"),
|
|
36
|
-
...require("./trace.js"),
|
|
37
35
|
...require("./validation/index.js")
|
|
38
36
|
});
|
package/dist/cjs/dev/index.js
CHANGED
|
@@ -44,7 +44,6 @@ __reExport(dev_exports, require("./replaceStorage.js"), module.exports);
|
|
|
44
44
|
__reExport(dev_exports, require("./resilientTransport.js"), module.exports);
|
|
45
45
|
__reExport(dev_exports, require("./transports.js"), module.exports);
|
|
46
46
|
__reExport(dev_exports, require("./types.js"), module.exports);
|
|
47
|
-
__reExport(dev_exports, require("./verifyTestnet.js"), module.exports);
|
|
48
47
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
48
|
0 && (module.exports = {
|
|
50
49
|
isRangeError,
|
|
@@ -68,6 +67,5 @@ __reExport(dev_exports, require("./verifyTestnet.js"), module.exports);
|
|
|
68
67
|
...require("./replaceStorage.js"),
|
|
69
68
|
...require("./resilientTransport.js"),
|
|
70
69
|
...require("./transports.js"),
|
|
71
|
-
...require("./types.js")
|
|
72
|
-
...require("./verifyTestnet.js")
|
|
70
|
+
...require("./types.js")
|
|
73
71
|
});
|
|
@@ -38,7 +38,9 @@ const OUT_OF_SYNC_PATTERNS = [
|
|
|
38
38
|
// Optimism proxyd (code -32019) for future/non-existent blocks
|
|
39
39
|
/block is out of range/i,
|
|
40
40
|
// EIP-1474 standard (code -32001) when block/state is not available
|
|
41
|
-
/resource not found/i
|
|
41
|
+
/resource not found/i,
|
|
42
|
+
// DRPC when a requested block is ahead of the node's latest block
|
|
43
|
+
/greater than latest block/i
|
|
42
44
|
];
|
|
43
45
|
function isOutOfSyncError(e) {
|
|
44
46
|
if (e instanceof import_viem.BaseError) {
|
|
@@ -22,12 +22,12 @@ __export(assembleOperations_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(assembleOperations_exports);
|
|
24
24
|
var import_adapters = require("../plugins/adapters/index.js");
|
|
25
|
-
var import_trace = require("../preview/trace/index.js");
|
|
26
25
|
var import_classifyMulticallOperations = require("./classifyMulticallOperations.js");
|
|
26
|
+
var import_extractProtocolCalls = require("./extractProtocolCalls.js");
|
|
27
27
|
function assembleOperations(input) {
|
|
28
28
|
const {
|
|
29
29
|
facadeCalls,
|
|
30
|
-
|
|
30
|
+
executeResults,
|
|
31
31
|
register,
|
|
32
32
|
underlying,
|
|
33
33
|
liquidationRemainingFunds,
|
|
@@ -42,7 +42,7 @@ function assembleOperations(input) {
|
|
|
42
42
|
return assemblePartialLiquidation(fc);
|
|
43
43
|
}
|
|
44
44
|
const count = countAdapterCalls(fc.innerCalls, register);
|
|
45
|
-
const sliced =
|
|
45
|
+
const sliced = executeResults.slice(executeOffset, executeOffset + count);
|
|
46
46
|
executeOffset += count;
|
|
47
47
|
const withdrawCount = countWithdrawCollateralCalls(fc.innerCalls);
|
|
48
48
|
const slicedWithdrawEvents = withdrawCollateralEvents.slice(
|
|
@@ -50,11 +50,11 @@ function assembleOperations(input) {
|
|
|
50
50
|
withdrawOffset + withdrawCount
|
|
51
51
|
);
|
|
52
52
|
withdrawOffset += withdrawCount;
|
|
53
|
-
const
|
|
53
|
+
const protocolCalldatas = (0, import_extractProtocolCalls.extractProtocolCalls)(fc.trace, sliced);
|
|
54
54
|
const multicall = (0, import_classifyMulticallOperations.classifyMulticallOperations)({
|
|
55
55
|
innerCalls: fc.innerCalls,
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
executeResults: sliced,
|
|
57
|
+
protocolCalldatas,
|
|
58
58
|
register,
|
|
59
59
|
creditAccount: fc.creditAccount,
|
|
60
60
|
underlying,
|
|
@@ -23,12 +23,12 @@ __export(classifyMulticallOperations_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(classifyMulticallOperations_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
var import_adapters = require("../plugins/adapters/index.js");
|
|
26
|
-
var
|
|
26
|
+
var import_errors = require("./errors.js");
|
|
27
27
|
function classifyMulticallOperations(input) {
|
|
28
28
|
const {
|
|
29
29
|
innerCalls,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
executeResults,
|
|
31
|
+
protocolCalldatas,
|
|
32
32
|
register,
|
|
33
33
|
creditAccount,
|
|
34
34
|
underlying,
|
|
@@ -43,27 +43,20 @@ function classifyMulticallOperations(input) {
|
|
|
43
43
|
const contract = register.getContract(call.target);
|
|
44
44
|
if (contract instanceof import_adapters.AbstractAdapterContract) {
|
|
45
45
|
const idx = transferIdx++;
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
throw new
|
|
46
|
+
const executeResult = executeResults[idx];
|
|
47
|
+
if (!executeResult) {
|
|
48
|
+
throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
|
|
49
49
|
}
|
|
50
|
-
const
|
|
51
|
-
const
|
|
50
|
+
const { transfers: transfers2, targetContract: targetContract2 } = executeResult;
|
|
51
|
+
const protocolCalldata = protocolCalldatas[idx];
|
|
52
|
+
const partial = contract.parseAdapterOperation(
|
|
52
53
|
call,
|
|
53
|
-
|
|
54
|
+
transfers2,
|
|
55
|
+
creditAccount,
|
|
56
|
+
protocolCalldata,
|
|
57
|
+
strict
|
|
54
58
|
);
|
|
55
|
-
result.push({
|
|
56
|
-
operation: "Execute",
|
|
57
|
-
adapter: call.target,
|
|
58
|
-
adapterType: call.contractType,
|
|
59
|
-
version: call.version,
|
|
60
|
-
label: call.label,
|
|
61
|
-
adapterFunctionName: call.functionName,
|
|
62
|
-
adapterArgs: call.rawArgs,
|
|
63
|
-
protocol,
|
|
64
|
-
transfers: transfers2,
|
|
65
|
-
legacy
|
|
66
|
-
});
|
|
59
|
+
if (partial) result.push({ ...partial, protocol: targetContract2 });
|
|
67
60
|
continue;
|
|
68
61
|
}
|
|
69
62
|
if (contract !== void 0) {
|
|
@@ -79,25 +72,26 @@ function classifyMulticallOperations(input) {
|
|
|
79
72
|
continue;
|
|
80
73
|
}
|
|
81
74
|
if (strict) {
|
|
82
|
-
throw new
|
|
75
|
+
throw new import_errors.UnknownAdapterError(call.target);
|
|
83
76
|
}
|
|
84
77
|
const unknownIdx = transferIdx++;
|
|
85
|
-
const
|
|
86
|
-
if (!
|
|
87
|
-
throw new
|
|
78
|
+
const unknownResult = executeResults[unknownIdx];
|
|
79
|
+
if (!unknownResult) {
|
|
80
|
+
throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
|
|
88
81
|
}
|
|
82
|
+
const { transfers, targetContract } = unknownResult;
|
|
89
83
|
const netTransfers = (0, import_adapters.toNetTransfers)(transfers, creditAccount);
|
|
90
84
|
result.push({
|
|
91
85
|
operation: "Execute",
|
|
92
86
|
adapter: call.target,
|
|
87
|
+
protocol: targetContract,
|
|
93
88
|
adapterType: call.contractType,
|
|
94
89
|
version: call.version,
|
|
95
90
|
label: call.label,
|
|
96
91
|
adapterFunctionName: call.functionName,
|
|
97
92
|
adapterArgs: call.rawArgs,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
protocol: void 0,
|
|
93
|
+
protocolFunctionName: call.functionName,
|
|
94
|
+
protocolArgs: call.rawArgs,
|
|
101
95
|
transfers,
|
|
102
96
|
legacy: {
|
|
103
97
|
operation: "Swap",
|
|
@@ -105,11 +99,11 @@ function classifyMulticallOperations(input) {
|
|
|
105
99
|
}
|
|
106
100
|
});
|
|
107
101
|
}
|
|
108
|
-
if (transferIdx !==
|
|
109
|
-
throw new
|
|
102
|
+
if (transferIdx !== executeResults.length) {
|
|
103
|
+
throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
|
|
110
104
|
}
|
|
111
105
|
if (withdrawCollateralEvents && withdrawCollateralEvents.length > 0 && withdrawIdx !== withdrawCollateralEvents.length) {
|
|
112
|
-
throw new
|
|
106
|
+
throw new import_errors.WithdrawCollateralAlignmentError(
|
|
113
107
|
withdrawCollateralEvents.length,
|
|
114
108
|
withdrawIdx
|
|
115
109
|
);
|
|
@@ -18,6 +18,8 @@ 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,
|
|
21
23
|
TransferAlignmentError: () => TransferAlignmentError,
|
|
22
24
|
UnexpectedFacadeEventOrderError: () => UnexpectedFacadeEventOrderError,
|
|
23
25
|
UnknownAdapterError: () => UnknownAdapterError,
|
|
@@ -49,6 +51,28 @@ class WithdrawCollateralAlignmentError extends Error {
|
|
|
49
51
|
this.name = "WithdrawCollateralAlignmentError";
|
|
50
52
|
}
|
|
51
53
|
}
|
|
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
|
+
}
|
|
52
76
|
class UnexpectedFacadeEventOrderError extends Error {
|
|
53
77
|
constructor(e) {
|
|
54
78
|
super(
|
|
@@ -69,6 +93,8 @@ class UnknownFacadeCallError extends Error {
|
|
|
69
93
|
}
|
|
70
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
71
95
|
0 && (module.exports = {
|
|
96
|
+
AdapterTraceAlignmentError,
|
|
97
|
+
ProtocolCallNotFoundError,
|
|
72
98
|
TransferAlignmentError,
|
|
73
99
|
UnexpectedFacadeEventOrderError,
|
|
74
100
|
UnknownAdapterError,
|
|
@@ -0,0 +1,53 @@
|
|
|
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 extractProtocolCalls_exports = {};
|
|
20
|
+
__export(extractProtocolCalls_exports, {
|
|
21
|
+
extractProtocolCalls: () => extractProtocolCalls
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(extractProtocolCalls_exports);
|
|
24
|
+
var import_errors = require("./errors.js");
|
|
25
|
+
var import_trace_utils = require("./trace-utils.js");
|
|
26
|
+
function extractProtocolCalls(facadeTrace, executeResults) {
|
|
27
|
+
if (executeResults.length === 0) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const subtraces = facadeTrace.calls ?? [];
|
|
31
|
+
const result = [];
|
|
32
|
+
let subtraceIdx = 0;
|
|
33
|
+
for (let i = 0; i < executeResults.length; i++) {
|
|
34
|
+
const { targetContract } = executeResults[i];
|
|
35
|
+
let found;
|
|
36
|
+
while (subtraceIdx < subtraces.length && !found) {
|
|
37
|
+
found = (0, import_trace_utils.findCallTo)(subtraces[subtraceIdx], targetContract);
|
|
38
|
+
subtraceIdx++;
|
|
39
|
+
}
|
|
40
|
+
if (!found) {
|
|
41
|
+
throw new import_errors.ProtocolCallNotFoundError(targetContract, i);
|
|
42
|
+
}
|
|
43
|
+
result.push(found.input);
|
|
44
|
+
}
|
|
45
|
+
if (result.length !== executeResults.length) {
|
|
46
|
+
throw new import_errors.AdapterTraceAlignmentError(executeResults.length, result.length);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
extractProtocolCalls
|
|
53
|
+
});
|
|
@@ -22,14 +22,18 @@ __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
|
+
const hasLiquidation = logs.some((l) => {
|
|
32
|
+
const e = tryDecodeFacadeEvent(l, creditFacade);
|
|
33
|
+
return !!e && (e.eventName === "LiquidateCreditAccount" || e.eventName === "PartiallyLiquidateCreditAccount") && (0, import_viem.isAddressEqual)(e.args.creditAccount, creditAccount);
|
|
34
|
+
});
|
|
31
35
|
let currentEntries = [];
|
|
32
|
-
const
|
|
36
|
+
const executeResults = [];
|
|
33
37
|
const directTransfers = [];
|
|
34
38
|
const phantomTokens = new import_sdk.AddressMap();
|
|
35
39
|
const withdrawCollateralEvents = [];
|
|
@@ -38,17 +42,20 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
38
42
|
const facadeEvent = tryDecodeFacadeEvent(log, creditFacade);
|
|
39
43
|
if (facadeEvent) {
|
|
40
44
|
if (isExecute(facadeEvent, creditAccount)) {
|
|
41
|
-
|
|
45
|
+
executeResults.push({
|
|
46
|
+
transfers: currentEntries,
|
|
47
|
+
targetContract: facadeEvent.args.targetContract
|
|
48
|
+
});
|
|
42
49
|
} else if (isLiquidation(facadeEvent, creditAccount)) {
|
|
43
50
|
liquidationRemainingFunds = facadeEvent.args.remainingFunds;
|
|
44
51
|
} else if (isWithdrawPhantomToken(facadeEvent, creditAccount)) {
|
|
45
|
-
const
|
|
46
|
-
if (!
|
|
52
|
+
const phantomExec = executeResults.pop();
|
|
53
|
+
if (!phantomExec) {
|
|
47
54
|
throw new Error(
|
|
48
55
|
`WithdrawPhantomToken without preceding Execute at logIndex ${facadeEvent.logIndex}`
|
|
49
56
|
);
|
|
50
57
|
}
|
|
51
|
-
const rawDeposit =
|
|
58
|
+
const rawDeposit = phantomExec.transfers.find(
|
|
52
59
|
(t) => (0, import_viem.isAddressEqual)(t.to, creditAccount)
|
|
53
60
|
);
|
|
54
61
|
if (!rawDeposit) {
|
|
@@ -82,12 +89,17 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
82
89
|
if ((0, import_viem.isAddressEqual)(from, creditAccount) || (0, import_viem.isAddressEqual)(to, creditAccount)) {
|
|
83
90
|
currentEntries.push({ token, amount: value, from, to });
|
|
84
91
|
}
|
|
85
|
-
if ((0, import_viem.isAddressEqual)(
|
|
86
|
-
directTransfers.push({
|
|
92
|
+
if (!hasLiquidation && !isInRange(log.logIndex, ranges) && ((0, import_viem.isAddressEqual)(from, creditAccount) || (0, import_viem.isAddressEqual)(to, creditAccount))) {
|
|
93
|
+
directTransfers.push({
|
|
94
|
+
token,
|
|
95
|
+
from,
|
|
96
|
+
to,
|
|
97
|
+
amount: value
|
|
98
|
+
});
|
|
87
99
|
}
|
|
88
100
|
}
|
|
89
101
|
return {
|
|
90
|
-
|
|
102
|
+
executeResults,
|
|
91
103
|
directTransfers,
|
|
92
104
|
liquidationRemainingFunds,
|
|
93
105
|
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("
|
|
26
|
-
var import_trace = require("../../common-utils/utils/trace.js");
|
|
25
|
+
var import_generated = require("../abi/310/generated.js");
|
|
27
26
|
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_utils.collectTraces)(trace, creditFacade);
|
|
52
52
|
const results = [];
|
|
53
53
|
for (const trace2 of facadeTraces) {
|
|
54
54
|
const parsed = register.parseFunctionDataV2(
|
|
@@ -22,6 +22,7 @@ __export(history_exports, {
|
|
|
22
22
|
parseCreditAccountTransaction: () => import_parseCreditAccountTransaction.parseCreditAccountTransaction
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(history_exports);
|
|
25
|
+
__reExport(history_exports, require("./inner-operations.js"), module.exports);
|
|
25
26
|
__reExport(history_exports, require("./mapOperations.js"), module.exports);
|
|
26
27
|
var import_parseCreditAccountTransaction = require("./parseCreditAccountTransaction.js");
|
|
27
28
|
__reExport(history_exports, require("./populateContractsRegister.js"), module.exports);
|
|
@@ -30,6 +31,7 @@ __reExport(history_exports, require("./types.js"), module.exports);
|
|
|
30
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
32
|
0 && (module.exports = {
|
|
32
33
|
parseCreditAccountTransaction,
|
|
34
|
+
...require("./inner-operations.js"),
|
|
33
35
|
...require("./mapOperations.js"),
|
|
34
36
|
...require("./populateContractsRegister.js"),
|
|
35
37
|
...require("./toLegacyOperation.js"),
|
|
@@ -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 inner_operations_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(inner_operations_exports);
|
|
@@ -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 internal_types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(internal_types_exports);
|
|
@@ -21,8 +21,9 @@ __export(parseCreditAccountTransaction_exports, {
|
|
|
21
21
|
parseCreditAccountTransaction: () => parseCreditAccountTransaction
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(parseCreditAccountTransaction_exports);
|
|
24
|
-
var import_trace = require("../preview/trace/index.js");
|
|
25
24
|
var import_assembleOperations = require("./assembleOperations.js");
|
|
25
|
+
var import_extractTransfers = require("./extractTransfers.js");
|
|
26
|
+
var import_findFacadeCalls = require("./findFacadeCalls.js");
|
|
26
27
|
function parseCreditAccountTransaction(input) {
|
|
27
28
|
const {
|
|
28
29
|
trace,
|
|
@@ -39,7 +40,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
39
40
|
const txHash = receipt.transactionHash;
|
|
40
41
|
const blockNumber = Number(receipt.blockNumber);
|
|
41
42
|
const timestamp = Number(receipt.blockTimestamp ?? 0);
|
|
42
|
-
const facadeCalls = (0,
|
|
43
|
+
const facadeCalls = (0, import_findFacadeCalls.findFacadeCalls)(
|
|
43
44
|
trace,
|
|
44
45
|
creditFacade,
|
|
45
46
|
creditAccount,
|
|
@@ -47,12 +48,12 @@ function parseCreditAccountTransaction(input) {
|
|
|
47
48
|
strict
|
|
48
49
|
);
|
|
49
50
|
const {
|
|
50
|
-
|
|
51
|
+
executeResults,
|
|
51
52
|
directTransfers,
|
|
52
53
|
liquidationRemainingFunds,
|
|
53
54
|
phantomTokens,
|
|
54
55
|
withdrawCollateralEvents
|
|
55
|
-
} = (0,
|
|
56
|
+
} = (0, import_extractTransfers.extractTransfers)(logs, creditAccount, pool, creditFacade);
|
|
56
57
|
const meta = {
|
|
57
58
|
creditManager,
|
|
58
59
|
creditFacade,
|
|
@@ -62,7 +63,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
62
63
|
};
|
|
63
64
|
const facadeOps = (0, import_assembleOperations.assembleOperations)({
|
|
64
65
|
facadeCalls,
|
|
65
|
-
|
|
66
|
+
executeResults,
|
|
66
67
|
register,
|
|
67
68
|
underlying,
|
|
68
69
|
liquidationRemainingFunds,
|
|
@@ -48,11 +48,7 @@ function createLegacyVisitor(params) {
|
|
|
48
48
|
blockNum: ctx.blockNumber,
|
|
49
49
|
timestamp: ctx.timestamp,
|
|
50
50
|
sessionId: params.sessionId,
|
|
51
|
-
|
|
52
|
-
// non-strict mode, or undecodable calldata). The deprecated charts
|
|
53
|
-
// output still needs an address, so fall back to the on-chain adapter
|
|
54
|
-
// address, which is the closest meaningful value.
|
|
55
|
-
protocol: op.protocol?.contract ?? op.adapter
|
|
51
|
+
protocol: op.protocol
|
|
56
52
|
};
|
|
57
53
|
},
|
|
58
54
|
IncreaseBorrowedAmount(op, ctx) {
|
|
@@ -108,7 +104,7 @@ function createLegacyVisitor(params) {
|
|
|
108
104
|
token: op.token,
|
|
109
105
|
amount: op.amount.toString(),
|
|
110
106
|
from: op.from,
|
|
111
|
-
to: op.
|
|
107
|
+
to: op.to
|
|
112
108
|
};
|
|
113
109
|
},
|
|
114
110
|
MultiCall(op, multicall) {
|
|
@@ -16,66 +16,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var
|
|
20
|
-
__export(
|
|
21
|
-
EXECUTE_BYTES_SELECTOR: () => EXECUTE_BYTES_SELECTOR,
|
|
19
|
+
var trace_utils_exports = {};
|
|
20
|
+
__export(trace_utils_exports, {
|
|
22
21
|
collectTraces: () => collectTraces,
|
|
23
|
-
findCallTo: () => findCallTo
|
|
24
|
-
findCallWithInput: () => findCallWithInput,
|
|
25
|
-
findExecuteBytes: () => findExecuteBytes,
|
|
26
|
-
resolveProtocolCall: () => resolveProtocolCall
|
|
22
|
+
findCallTo: () => findCallTo
|
|
27
23
|
});
|
|
28
|
-
module.exports = __toCommonJS(
|
|
24
|
+
module.exports = __toCommonJS(trace_utils_exports);
|
|
29
25
|
var import_viem = require("viem");
|
|
30
|
-
const EXECUTE_BYTES_SELECTOR = "0x09c5eabe";
|
|
31
|
-
function findExecuteBytes(node) {
|
|
32
|
-
const queue = [node];
|
|
33
|
-
while (queue.length > 0) {
|
|
34
|
-
const current = queue.shift();
|
|
35
|
-
if (current.error) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (current.input.slice(0, 10).toLowerCase() === EXECUTE_BYTES_SELECTOR) {
|
|
39
|
-
return current;
|
|
40
|
-
}
|
|
41
|
-
if (current.calls) {
|
|
42
|
-
queue.push(...current.calls);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
function findCallWithInput(node, input) {
|
|
48
|
-
if (node.error) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
if (node.type === "CALL" && node.input.toLowerCase() === input.toLowerCase()) {
|
|
52
|
-
return node;
|
|
53
|
-
}
|
|
54
|
-
if (node.calls) {
|
|
55
|
-
for (const child of node.calls) {
|
|
56
|
-
const found = findCallWithInput(child, input);
|
|
57
|
-
if (found) {
|
|
58
|
-
return found;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return void 0;
|
|
63
|
-
}
|
|
64
|
-
function resolveProtocolCall(node) {
|
|
65
|
-
const executeNode = findExecuteBytes(node);
|
|
66
|
-
if (!executeNode) {
|
|
67
|
-
return void 0;
|
|
68
|
-
}
|
|
69
|
-
const [calldata] = (0, import_viem.decodeAbiParameters)(
|
|
70
|
-
[{ type: "bytes" }],
|
|
71
|
-
`0x${executeNode.input.slice(10)}`
|
|
72
|
-
);
|
|
73
|
-
const targetCall = findCallWithInput(executeNode, calldata);
|
|
74
|
-
if (!targetCall) {
|
|
75
|
-
return void 0;
|
|
76
|
-
}
|
|
77
|
-
return { contract: (0, import_viem.getAddress)(targetCall.to), calldata };
|
|
78
|
-
}
|
|
79
26
|
function findCallTo(node, target) {
|
|
80
27
|
if (node.error) {
|
|
81
28
|
return void 0;
|
|
@@ -109,10 +56,6 @@ function collectTraces(node, target) {
|
|
|
109
56
|
}
|
|
110
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
111
58
|
0 && (module.exports = {
|
|
112
|
-
EXECUTE_BYTES_SELECTOR,
|
|
113
59
|
collectTraces,
|
|
114
|
-
findCallTo
|
|
115
|
-
findCallWithInput,
|
|
116
|
-
findExecuteBytes,
|
|
117
|
-
resolveProtocolCall
|
|
60
|
+
findCallTo
|
|
118
61
|
});
|
|
@@ -27,12 +27,12 @@ const curveTwapPriceFeed = {
|
|
|
27
27
|
constructorParams: [
|
|
28
28
|
{
|
|
29
29
|
label: "lowerBound ($)",
|
|
30
|
-
type: { type: "int256", decimals:
|
|
30
|
+
type: { type: "int256", decimals: 18 },
|
|
31
31
|
defaultValue: "0"
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
label: "upperBound ($)",
|
|
35
|
-
type: { type: "int256", decimals:
|
|
35
|
+
type: { type: "int256", decimals: 18 },
|
|
36
36
|
defaultValue: "1"
|
|
37
37
|
},
|
|
38
38
|
{
|