@gearbox-protocol/sdk 14.11.0-next.3 → 14.11.0-next.5

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.
Files changed (105) hide show
  1. package/dist/cjs/common-utils/utils/index.js +2 -0
  2. package/dist/cjs/{history/trace-utils.js → common-utils/utils/trace.js} +62 -5
  3. package/dist/cjs/history/assembleOperations.js +6 -6
  4. package/dist/cjs/history/classifyMulticallOperations.js +31 -25
  5. package/dist/cjs/history/index.js +0 -2
  6. package/dist/cjs/history/parseCreditAccountTransaction.js +5 -6
  7. package/dist/cjs/history/toLegacyOperation.js +5 -1
  8. package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +25 -37
  9. package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
  10. package/dist/cjs/{history/internal-types.js → plugins/adapters/transfers.js} +2 -2
  11. package/dist/cjs/preview/index.js +3 -1
  12. package/dist/cjs/preview/parse/classifyInnerOperations.js +5 -43
  13. package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +1 -4
  14. package/dist/cjs/{history/inner-operations.js → preview/parse/types-adapters.js} +2 -2
  15. package/dist/cjs/preview/parse/types-facades.js +16 -0
  16. package/dist/cjs/preview/parse/types-pools.js +16 -0
  17. package/dist/cjs/preview/parse/types.js +8 -1
  18. package/dist/cjs/preview/prerequisites/index.js +2 -0
  19. package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
  20. package/dist/cjs/{history → preview/trace}/errors.js +0 -26
  21. package/dist/cjs/preview/trace/extractAdapterCallTraces.js +58 -0
  22. package/dist/cjs/{history → preview/trace}/extractTransfers.js +10 -13
  23. package/dist/cjs/{history → preview/trace}/findFacadeCalls.js +3 -3
  24. package/dist/cjs/preview/trace/index.js +30 -0
  25. package/dist/cjs/preview/trace/types.js +16 -0
  26. package/dist/esm/common-utils/utils/index.js +1 -0
  27. package/dist/esm/common-utils/utils/trace.js +93 -0
  28. package/dist/esm/history/assembleOperations.js +8 -6
  29. package/dist/esm/history/classifyMulticallOperations.js +29 -23
  30. package/dist/esm/history/index.js +0 -1
  31. package/dist/esm/history/parseCreditAccountTransaction.js +3 -4
  32. package/dist/esm/history/toLegacyOperation.js +5 -1
  33. package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +28 -38
  34. package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
  35. package/dist/esm/preview/index.js +1 -0
  36. package/dist/esm/preview/parse/classifyInnerOperations.js +6 -46
  37. package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +2 -9
  38. package/dist/esm/preview/parse/types-facades.js +0 -0
  39. package/dist/esm/preview/parse/types-pools.js +0 -0
  40. package/dist/esm/preview/parse/types.js +3 -0
  41. package/dist/esm/preview/prerequisites/index.js +1 -0
  42. package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
  43. package/dist/esm/{history → preview/trace}/errors.js +0 -24
  44. package/dist/esm/preview/trace/extractAdapterCallTraces.js +40 -0
  45. package/dist/esm/{history → preview/trace}/extractTransfers.js +10 -13
  46. package/dist/esm/{history → preview/trace}/findFacadeCalls.js +4 -2
  47. package/dist/esm/preview/trace/index.js +5 -0
  48. package/dist/esm/preview/trace/types.js +0 -0
  49. package/dist/types/common-utils/utils/index.d.ts +1 -0
  50. package/dist/types/common-utils/utils/trace.d.ts +73 -0
  51. package/dist/types/history/assembleOperations.d.ts +11 -6
  52. package/dist/types/history/classifyMulticallOperations.d.ts +21 -9
  53. package/dist/types/history/index.d.ts +0 -1
  54. package/dist/types/history/mapOperations.d.ts +7 -9
  55. package/dist/types/history/types.d.ts +22 -65
  56. package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +16 -17
  57. package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +10 -1
  58. package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +1 -1
  59. package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +1 -1
  60. package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +1 -1
  61. package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +1 -1
  62. package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +1 -1
  63. package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +1 -1
  64. package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +1 -1
  65. package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +1 -1
  66. package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +1 -1
  67. package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +1 -1
  68. package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +1 -1
  69. package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +1 -1
  70. package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +1 -1
  71. package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +1 -1
  72. package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +1 -1
  73. package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +1 -1
  74. package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +1 -1
  75. package/dist/types/plugins/adapters/transferHelpers.d.ts +1 -1
  76. package/dist/types/plugins/adapters/transfers.d.ts +17 -0
  77. package/dist/types/plugins/adapters/types.d.ts +8 -46
  78. package/dist/types/preview/index.d.ts +1 -0
  79. package/dist/types/preview/parse/classifyInnerOperations.d.ts +8 -8
  80. package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +4 -3
  81. package/dist/types/preview/parse/types-adapters.d.ts +69 -0
  82. package/dist/types/preview/parse/types-facades.d.ts +124 -0
  83. package/dist/types/preview/parse/types-pools.d.ts +42 -0
  84. package/dist/types/preview/parse/types.d.ts +12 -46
  85. package/dist/types/preview/prerequisites/index.d.ts +1 -0
  86. package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -0
  87. package/dist/types/preview/simulate/extractERC20Transfers.d.ts +1 -1
  88. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +1 -1
  89. package/dist/types/preview/simulate/types.d.ts +1 -1
  90. package/dist/types/{history → preview/trace}/errors.d.ts +0 -10
  91. package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +23 -0
  92. package/dist/types/{history → preview/trace}/extractTransfers.d.ts +14 -5
  93. package/dist/types/{history → preview/trace}/findFacadeCalls.d.ts +3 -2
  94. package/dist/types/preview/trace/index.d.ts +5 -0
  95. package/dist/types/preview/trace/types.d.ts +21 -0
  96. package/package.json +1 -1
  97. package/dist/cjs/history/extractProtocolCalls.js +0 -53
  98. package/dist/esm/history/extractProtocolCalls.js +0 -32
  99. package/dist/esm/history/trace-utils.js +0 -36
  100. package/dist/types/history/extractProtocolCalls.d.ts +0 -8
  101. package/dist/types/history/inner-operations.d.ts +0 -57
  102. package/dist/types/history/internal-types.d.ts +0 -47
  103. package/dist/types/history/trace-utils.d.ts +0 -12
  104. /package/dist/esm/{history/inner-operations.js → plugins/adapters/transfers.js} +0 -0
  105. /package/dist/esm/{history/internal-types.js → preview/parse/types-adapters.js} +0 -0
@@ -22,6 +22,7 @@ __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);
25
26
  __reExport(utils_exports, require("./validation/index.js"), module.exports);
26
27
  // Annotate the CommonJS export names for ESM import in node:
27
28
  0 && (module.exports = {
@@ -32,5 +33,6 @@ __reExport(utils_exports, require("./validation/index.js"), module.exports);
32
33
  ...require("./creditAccount/index.js"),
33
34
  ...require("./price-math.js"),
34
35
  ...require("./strategies/index.js"),
36
+ ...require("./trace.js"),
35
37
  ...require("./validation/index.js")
36
38
  });
@@ -16,13 +16,66 @@ 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 trace_utils_exports = {};
20
- __export(trace_utils_exports, {
19
+ var trace_exports = {};
20
+ __export(trace_exports, {
21
+ EXECUTE_BYTES_SELECTOR: () => EXECUTE_BYTES_SELECTOR,
21
22
  collectTraces: () => collectTraces,
22
- findCallTo: () => findCallTo
23
+ findCallTo: () => findCallTo,
24
+ findCallWithInput: () => findCallWithInput,
25
+ findExecuteBytes: () => findExecuteBytes,
26
+ resolveProtocolCall: () => resolveProtocolCall
23
27
  });
24
- module.exports = __toCommonJS(trace_utils_exports);
28
+ module.exports = __toCommonJS(trace_exports);
25
29
  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
+ }
26
79
  function findCallTo(node, target) {
27
80
  if (node.error) {
28
81
  return void 0;
@@ -56,6 +109,10 @@ function collectTraces(node, target) {
56
109
  }
57
110
  // Annotate the CommonJS export names for ESM import in node:
58
111
  0 && (module.exports = {
112
+ EXECUTE_BYTES_SELECTOR,
59
113
  collectTraces,
60
- findCallTo
114
+ findCallTo,
115
+ findCallWithInput,
116
+ findExecuteBytes,
117
+ resolveProtocolCall
61
118
  });
@@ -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");
25
26
  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
- executeResults,
30
+ executeTransfers,
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 = executeResults.slice(executeOffset, executeOffset + count);
45
+ const sliced = executeTransfers.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 protocolCalldatas = (0, import_extractProtocolCalls.extractProtocolCalls)(fc.trace, sliced);
53
+ const adapterTraces = (0, import_trace.extractAdapterCallTraces)(fc.trace);
54
54
  const multicall = (0, import_classifyMulticallOperations.classifyMulticallOperations)({
55
55
  innerCalls: fc.innerCalls,
56
- executeResults: sliced,
57
- protocolCalldatas,
56
+ executeTransfers: sliced,
57
+ adapterTraces,
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 import_errors = require("./errors.js");
26
+ var import_trace = require("../preview/trace/index.js");
27
27
  function classifyMulticallOperations(input) {
28
28
  const {
29
29
  innerCalls,
30
- executeResults,
31
- protocolCalldatas,
30
+ executeTransfers,
31
+ adapterTraces,
32
32
  register,
33
33
  creditAccount,
34
34
  underlying,
@@ -43,20 +43,27 @@ 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 executeResult = executeResults[idx];
47
- if (!executeResult) {
48
- throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
46
+ const transfers2 = executeTransfers[idx];
47
+ if (!transfers2) {
48
+ throw new import_trace.TransferAlignmentError(executeTransfers.length, transferIdx);
49
49
  }
50
- const { transfers: transfers2, targetContract: targetContract2 } = executeResult;
51
- const protocolCalldata = protocolCalldatas[idx];
52
- const partial = contract.parseAdapterOperation(
50
+ const protocol = contract.parseProtocolCall(adapterTraces[idx], strict);
51
+ const legacy = contract.classifyLegacyOperation(
53
52
  call,
54
- transfers2,
55
- creditAccount,
56
- protocolCalldata,
57
- strict
53
+ (0, import_adapters.toNetTransfers)(transfers2, creditAccount)
58
54
  );
59
- if (partial) result.push({ ...partial, protocol: targetContract2 });
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
+ });
60
67
  continue;
61
68
  }
62
69
  if (contract !== void 0) {
@@ -72,26 +79,25 @@ function classifyMulticallOperations(input) {
72
79
  continue;
73
80
  }
74
81
  if (strict) {
75
- throw new import_errors.UnknownAdapterError(call.target);
82
+ throw new import_trace.UnknownAdapterError(call.target);
76
83
  }
77
84
  const unknownIdx = transferIdx++;
78
- const unknownResult = executeResults[unknownIdx];
79
- if (!unknownResult) {
80
- throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
85
+ const transfers = executeTransfers[unknownIdx];
86
+ if (!transfers) {
87
+ throw new import_trace.TransferAlignmentError(executeTransfers.length, transferIdx);
81
88
  }
82
- const { transfers, targetContract } = unknownResult;
83
89
  const netTransfers = (0, import_adapters.toNetTransfers)(transfers, creditAccount);
84
90
  result.push({
85
91
  operation: "Execute",
86
92
  adapter: call.target,
87
- protocol: targetContract,
88
93
  adapterType: call.contractType,
89
94
  version: call.version,
90
95
  label: call.label,
91
96
  adapterFunctionName: call.functionName,
92
97
  adapterArgs: call.rawArgs,
93
- protocolFunctionName: call.functionName,
94
- protocolArgs: call.rawArgs,
98
+ // Unknown adapter (non-strict): we have no ABI to decode the protocol
99
+ // call, so `protocol` is left absent rather than filled with placeholders.
100
+ protocol: void 0,
95
101
  transfers,
96
102
  legacy: {
97
103
  operation: "Swap",
@@ -99,11 +105,11 @@ function classifyMulticallOperations(input) {
99
105
  }
100
106
  });
101
107
  }
102
- if (transferIdx !== executeResults.length) {
103
- throw new import_errors.TransferAlignmentError(executeResults.length, transferIdx);
108
+ if (transferIdx !== executeTransfers.length) {
109
+ throw new import_trace.TransferAlignmentError(executeTransfers.length, transferIdx);
104
110
  }
105
111
  if (withdrawCollateralEvents && withdrawCollateralEvents.length > 0 && withdrawIdx !== withdrawCollateralEvents.length) {
106
- throw new import_errors.WithdrawCollateralAlignmentError(
112
+ throw new import_trace.WithdrawCollateralAlignmentError(
107
113
  withdrawCollateralEvents.length,
108
114
  withdrawIdx
109
115
  );
@@ -22,7 +22,6 @@ __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);
26
25
  __reExport(history_exports, require("./mapOperations.js"), module.exports);
27
26
  var import_parseCreditAccountTransaction = require("./parseCreditAccountTransaction.js");
28
27
  __reExport(history_exports, require("./populateContractsRegister.js"), module.exports);
@@ -31,7 +30,6 @@ __reExport(history_exports, require("./types.js"), module.exports);
31
30
  // Annotate the CommonJS export names for ESM import in node:
32
31
  0 && (module.exports = {
33
32
  parseCreditAccountTransaction,
34
- ...require("./inner-operations.js"),
35
33
  ...require("./mapOperations.js"),
36
34
  ...require("./populateContractsRegister.js"),
37
35
  ...require("./toLegacyOperation.js"),
@@ -21,9 +21,8 @@ __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");
24
25
  var import_assembleOperations = require("./assembleOperations.js");
25
- var import_extractTransfers = require("./extractTransfers.js");
26
- var import_findFacadeCalls = require("./findFacadeCalls.js");
27
26
  function parseCreditAccountTransaction(input) {
28
27
  const {
29
28
  trace,
@@ -40,7 +39,7 @@ function parseCreditAccountTransaction(input) {
40
39
  const txHash = receipt.transactionHash;
41
40
  const blockNumber = Number(receipt.blockNumber);
42
41
  const timestamp = Number(receipt.blockTimestamp ?? 0);
43
- const facadeCalls = (0, import_findFacadeCalls.findFacadeCalls)(
42
+ const facadeCalls = (0, import_trace.findFacadeCalls)(
44
43
  trace,
45
44
  creditFacade,
46
45
  creditAccount,
@@ -48,12 +47,12 @@ function parseCreditAccountTransaction(input) {
48
47
  strict
49
48
  );
50
49
  const {
51
- executeResults,
50
+ executeTransfers,
52
51
  directTransfers,
53
52
  liquidationRemainingFunds,
54
53
  phantomTokens,
55
54
  withdrawCollateralEvents
56
- } = (0, import_extractTransfers.extractTransfers)(logs, creditAccount, pool, creditFacade);
55
+ } = (0, import_trace.extractTransfers)(logs, creditAccount, pool, creditFacade);
57
56
  const meta = {
58
57
  creditManager,
59
58
  creditFacade,
@@ -63,7 +62,7 @@ function parseCreditAccountTransaction(input) {
63
62
  };
64
63
  const facadeOps = (0, import_assembleOperations.assembleOperations)({
65
64
  facadeCalls,
66
- executeResults,
65
+ executeTransfers,
67
66
  register,
68
67
  underlying,
69
68
  liquidationRemainingFunds,
@@ -48,7 +48,11 @@ function createLegacyVisitor(params) {
48
48
  blockNum: ctx.blockNumber,
49
49
  timestamp: ctx.timestamp,
50
50
  sessionId: params.sessionId,
51
- protocol: op.protocol
51
+ // `protocol` may be absent (migrator adapter, unknown adapter in
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
52
56
  };
53
57
  },
54
58
  IncreaseBorrowedAmount(op, ctx) {
@@ -22,6 +22,7 @@ __export(AbstractAdapter_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(AbstractAdapter_exports);
24
24
  var import_viem = require("viem");
25
+ var import_trace = require("../../../common-utils/utils/trace.js");
25
26
  var import_sdk = require("../../../sdk/index.js");
26
27
  var import_transferHelpers = require("../transferHelpers.js");
27
28
  class AbstractAdapterContract extends import_sdk.BaseContract {
@@ -64,45 +65,33 @@ class AbstractAdapterContract extends import_sdk.BaseContract {
64
65
  };
65
66
  }
66
67
  /**
67
- * Builds an {@link AdapterOperation} from a parsed call and ordered transfer entries.
68
+ * Decodes the protocol-level call (target contract + function name + args)
69
+ * performed by this adapter, recovered from its adapter-level call trace.
68
70
  *
69
- * Returns `PartialBy<AdapterOperation, "targetContract">` because the adapter
70
- * may not have `targetContract` (adapters created without SDK do not have serializedParams)
71
+ * Both the `targetContract` and the protocol calldata are taken from the
72
+ * execution trace.
71
73
  *
72
- * @param protocolCalldata Raw calldata of the actual CALL to targetContract, extracted from trace
73
- * @param strict When true, throws if protocol ABI is missing or decode fails
74
- */
75
- parseAdapterOperation(parsed, transfers, creditAccount, protocolCalldata, strict) {
76
- const netTransfers = (0, import_transferHelpers.toNetTransfers)(transfers, creditAccount);
77
- const protocol = this.parseProtocolCall(protocolCalldata, strict);
78
- return {
79
- operation: "Execute",
80
- adapter: this.address,
81
- protocol: this.#targetContract,
82
- adapterType: this.adapterType,
83
- version: this.version,
84
- label: parsed.label,
85
- adapterFunctionName: parsed.functionName,
86
- adapterArgs: parsed.rawArgs,
87
- ...protocol,
88
- transfers,
89
- legacy: this.classifyLegacyOperation(parsed, netTransfers)
90
- };
91
- }
92
- /**
93
- * Decodes protocol-level function name and args from the raw calldata
94
- * sent to targetContract.
74
+ * Returns `undefined` (in non-strict mode) when no external protocol call can
75
+ * be recovered, in strict mode throws instead.
76
+ *
77
+ * @param trace Adapter-level call trace (a direct child of the facade trace)
78
+ * @param strict When true, throws instead of returning `undefined`
95
79
  */
96
- parseProtocolCall(calldata, strict) {
80
+ parseProtocolCall(trace, strict) {
81
+ const resolved = (0, import_trace.resolveProtocolCall)(trace);
82
+ if (!resolved) {
83
+ if (strict) {
84
+ throw new Error("no external protocol call found in adapter trace");
85
+ }
86
+ return void 0;
87
+ }
88
+ const { contract, calldata } = resolved;
97
89
  const selector = calldata.slice(0, 10);
98
90
  if (this.protocolAbi.length === 0) {
99
91
  if (strict) {
100
92
  throw new Error(`Protocol ABI is missing for selector ${selector}`);
101
93
  }
102
- return {
103
- protocolFunctionName: `unknown function ${selector}`,
104
- protocolArgs: {}
105
- };
94
+ return void 0;
106
95
  }
107
96
  try {
108
97
  const decoded = (0, import_viem.decodeFunctionData)({
@@ -110,12 +99,12 @@ class AbstractAdapterContract extends import_sdk.BaseContract {
110
99
  data: calldata
111
100
  });
112
101
  const functionName = (0, import_sdk.getFunctionSignature)(this.protocolAbi, calldata);
113
- const protocolArgs = (0, import_sdk.functionArgsToRecord)(
102
+ const functionArgs = (0, import_sdk.functionArgsToRecord)(
114
103
  this.protocolAbi,
115
104
  decoded.functionName,
116
105
  decoded.args
117
106
  );
118
- return { protocolFunctionName: functionName, protocolArgs };
107
+ return { contract, functionName, functionArgs };
119
108
  } catch (e) {
120
109
  if (strict) {
121
110
  throw new Error(
@@ -123,10 +112,7 @@ class AbstractAdapterContract extends import_sdk.BaseContract {
123
112
  { cause: e }
124
113
  );
125
114
  }
126
- return {
127
- protocolFunctionName: `unknown function ${selector}`,
128
- protocolArgs: {}
129
- };
115
+ return void 0;
130
116
  }
131
117
  }
132
118
  /**
@@ -140,6 +126,8 @@ class AbstractAdapterContract extends import_sdk.BaseContract {
140
126
  * Override in protocol-specific subclasses for richer classification.
141
127
  *
142
128
  * @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/account_operation.go#L238-L264
129
+ *
130
+ * @deprecated Eventually will be gone, exists to produce output that legacy UI can display
143
131
  */
144
132
  classifyLegacyOperation(_parsed, transfers) {
145
133
  const swap = (0, import_transferHelpers.swapFromTransfers)(transfers);
@@ -35,6 +35,15 @@ class AccountMigratorAdapterContract extends import_AbstractAdapter.AbstractAdap
35
35
  `classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
36
36
  );
37
37
  }
38
+ /**
39
+ * The account-migrator adapter's `execute` targets the migrator bot, not an
40
+ * external protocol, so there is no protocol-level call to recover. Returning
41
+ * `undefined` keeps the `protocol` field aligned with its external-protocol
42
+ * semantics (see {@link TraceAdapterExt}).
43
+ */
44
+ parseProtocolCall(_trace, _strict) {
45
+ return void 0;
46
+ }
38
47
  }
39
48
  // Annotate the CommonJS export names for ESM import in node:
40
49
  0 && (module.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 internal_types_exports = {};
16
- module.exports = __toCommonJS(internal_types_exports);
15
+ var transfers_exports = {};
16
+ module.exports = __toCommonJS(transfers_exports);
@@ -18,9 +18,11 @@ module.exports = __toCommonJS(preview_exports);
18
18
  __reExport(preview_exports, require("./parse/index.js"), module.exports);
19
19
  __reExport(preview_exports, require("./prerequisites/index.js"), module.exports);
20
20
  __reExport(preview_exports, require("./simulate/index.js"), module.exports);
21
+ __reExport(preview_exports, require("./trace/index.js"), module.exports);
21
22
  // Annotate the CommonJS export names for ESM import in node:
22
23
  0 && (module.exports = {
23
24
  ...require("./parse/index.js"),
24
25
  ...require("./prerequisites/index.js"),
25
- ...require("./simulate/index.js")
26
+ ...require("./simulate/index.js"),
27
+ ...require("./trace/index.js")
26
28
  });
@@ -21,57 +21,28 @@ __export(classifyInnerOperations_exports, {
21
21
  classifyInnerOperations: () => classifyInnerOperations
22
22
  });
23
23
  module.exports = __toCommonJS(classifyInnerOperations_exports);
24
- var import_viem = require("viem");
25
24
  var import_adapters = require("../../plugins/adapters/index.js");
26
25
  function classifyInnerOperations(calls, props) {
27
26
  const { sdk, underlying } = props;
28
27
  const result = [];
29
28
  for (const call of calls) {
30
29
  const contract = sdk.getContract(call.target);
31
- if (contract instanceof import_adapters.AbstractAdapterContract) {
30
+ if (contract instanceof import_adapters.AbstractAdapterContract || contract === void 0) {
32
31
  result.push({
33
32
  operation: "Execute",
34
33
  adapter: call.target,
35
- protocol: contract.targetContract,
36
34
  adapterType: call.contractType,
37
35
  version: call.version,
38
36
  label: call.label,
39
37
  adapterFunctionName: call.functionName,
40
- adapterArgs: call.rawArgs,
41
- // TODO: mirror the adapter call into the protocol fields for now. The
42
- // real protocol-level call (adapter -> target contract) only exists in
43
- // the execution call trace, which is not available from raw calldata.
44
- // Recovering the actual protocol function/args requires a call trace.
45
- protocolFunctionName: call.functionName,
46
- protocolArgs: call.rawArgs,
47
- transfers: [],
48
- legacy: mockLegacyOperation()
38
+ adapterArgs: call.rawArgs
49
39
  });
50
40
  continue;
51
41
  }
52
- if (contract !== void 0) {
53
- const op = classifyFacadeInnerCall(call, underlying);
54
- if (op) result.push(op);
55
- continue;
42
+ const op = classifyFacadeInnerCall(call, underlying);
43
+ if (op) {
44
+ result.push(op);
56
45
  }
57
- result.push({
58
- operation: "Execute",
59
- adapter: call.target,
60
- protocol: call.target,
61
- adapterType: call.contractType,
62
- version: call.version,
63
- label: call.label,
64
- adapterFunctionName: call.functionName,
65
- adapterArgs: call.rawArgs,
66
- // TODO: mirror the adapter call into the protocol fields for now. The
67
- // real protocol-level call (adapter -> target contract) only exists in
68
- // the execution call trace, which is not available from raw calldata.
69
- // Recovering the actual protocol function/args requires a call trace.
70
- protocolFunctionName: call.functionName,
71
- protocolArgs: call.rawArgs,
72
- transfers: [],
73
- legacy: mockLegacyOperation()
74
- });
75
46
  }
76
47
  return result;
77
48
  }
@@ -115,15 +86,6 @@ function classifyFacadeInnerCall(call, underlying) {
115
86
  return null;
116
87
  }
117
88
  }
118
- function mockLegacyOperation() {
119
- return {
120
- operation: "Swap",
121
- from: import_viem.zeroAddress,
122
- fromAmount: "0",
123
- to: import_viem.zeroAddress,
124
- toAmount: "0"
125
- };
126
- }
127
89
  // Annotate the CommonJS export names for ESM import in node:
128
90
  0 && (module.exports = {
129
91
  classifyInnerOperations
@@ -36,10 +36,7 @@ function parseFacadeOperationCalldata(props) {
36
36
  }
37
37
  const metadata = {
38
38
  creditManager: suite.creditManager.address,
39
- creditFacade: facade.address,
40
- blockNumber: Number(sdk.currentBlock),
41
- txHash: import_viem.zeroHash,
42
- timestamp: 0
39
+ creditFacade: facade.address
43
40
  };
44
41
  const innerCalls = rawArgs.calls ?? [];
45
42
  const multicall = (0, import_classifyInnerOperations.classifyInnerOperations)(innerCalls, {
@@ -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 inner_operations_exports = {};
16
- module.exports = __toCommonJS(inner_operations_exports);
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
  });
@@ -19,6 +19,7 @@ __reExport(prerequisites_exports, require("./AllowancePrerequisite.js"), module.
19
19
  __reExport(prerequisites_exports, require("./BalancePrerequisite.js"), module.exports);
20
20
  __reExport(prerequisites_exports, require("./buildPrerequisites.js"), module.exports);
21
21
  __reExport(prerequisites_exports, require("./Prerequisite.js"), module.exports);
22
+ __reExport(prerequisites_exports, require("./prepareAction.js"), module.exports);
22
23
  __reExport(prerequisites_exports, require("./runPrerequisites.js"), module.exports);
23
24
  __reExport(prerequisites_exports, require("./types.js"), module.exports);
24
25
  // Annotate the CommonJS export names for ESM import in node:
@@ -27,6 +28,7 @@ __reExport(prerequisites_exports, require("./types.js"), module.exports);
27
28
  ...require("./BalancePrerequisite.js"),
28
29
  ...require("./buildPrerequisites.js"),
29
30
  ...require("./Prerequisite.js"),
31
+ ...require("./prepareAction.js"),
30
32
  ...require("./runPrerequisites.js"),
31
33
  ...require("./types.js")
32
34
  });