@gearbox-protocol/sdk 14.11.3 → 14.12.0-next.2

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 (214) hide show
  1. package/dist/cjs/abi/iZapper.js +62 -24
  2. package/dist/cjs/common-utils/utils/index.js +2 -0
  3. package/dist/cjs/{history/trace-utils.js → common-utils/utils/trace.js} +62 -5
  4. package/dist/cjs/dev/index.js +3 -1
  5. package/dist/cjs/dev/verifyTestnet.js +52 -0
  6. package/dist/cjs/history/assembleOperations.js +6 -6
  7. package/dist/cjs/history/classifyMulticallOperations.js +31 -25
  8. package/dist/cjs/history/index.js +0 -2
  9. package/dist/cjs/history/parseCreditAccountTransaction.js +5 -6
  10. package/dist/cjs/history/toLegacyOperation.js +5 -1
  11. package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +25 -37
  12. package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
  13. package/dist/cjs/{history/internal-types.js → plugins/adapters/transfers.js} +2 -2
  14. package/dist/cjs/preview/index.js +28 -0
  15. package/dist/cjs/preview/package.json +1 -0
  16. package/dist/cjs/preview/parse/classifyInnerOperations.js +92 -0
  17. package/dist/cjs/preview/parse/errors.js +50 -0
  18. package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +48 -0
  19. package/dist/cjs/preview/parse/index.js +34 -0
  20. package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +115 -0
  21. package/dist/cjs/preview/parse/parseOperationCalldata.js +75 -0
  22. package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +85 -0
  23. package/dist/cjs/{history/inner-operations.js → preview/parse/types-adapters.js} +2 -2
  24. package/dist/cjs/preview/parse/types-facades.js +16 -0
  25. package/dist/cjs/preview/parse/types-pools.js +16 -0
  26. package/dist/cjs/preview/parse/types.js +37 -0
  27. package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +78 -0
  28. package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +77 -0
  29. package/dist/cjs/preview/prerequisites/Prerequisite.js +85 -0
  30. package/dist/cjs/preview/prerequisites/buildPrerequisites.js +221 -0
  31. package/dist/cjs/preview/prerequisites/index.js +34 -0
  32. package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
  33. package/dist/cjs/preview/prerequisites/runPrerequisites.js +71 -0
  34. package/dist/cjs/preview/prerequisites/types.js +16 -0
  35. package/dist/cjs/preview/simulate/errors.js +91 -0
  36. package/dist/cjs/{sdk/market/zapper/Zapper.js → preview/simulate/holders.js} +21 -23
  37. package/dist/cjs/preview/simulate/index.js +37 -0
  38. package/dist/cjs/preview/simulate/simulateFacadeOperation.js +30 -0
  39. package/dist/cjs/preview/simulate/simulateOperation.js +37 -0
  40. package/dist/cjs/preview/simulate/simulatePoolOperation.js +187 -0
  41. package/dist/cjs/preview/simulate/types.js +16 -0
  42. package/dist/cjs/{history → preview/trace}/errors.js +0 -26
  43. package/dist/cjs/preview/trace/extractAdapterCallTraces.js +58 -0
  44. package/dist/cjs/{history → preview/trace}/extractTransfers.js +9 -12
  45. package/dist/cjs/{history → preview/trace}/findFacadeCalls.js +3 -3
  46. package/dist/cjs/preview/trace/index.js +30 -0
  47. package/dist/cjs/preview/trace/types.js +16 -0
  48. package/dist/cjs/sdk/MultichainSDK.js +1 -0
  49. package/dist/cjs/sdk/OnchainSDK.js +7 -3
  50. package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +154 -0
  51. package/dist/cjs/sdk/market/MarketRegister.js +10 -5
  52. package/dist/cjs/sdk/market/ZapperRegister.js +54 -0
  53. package/dist/cjs/sdk/market/zapper/IERC20ZapperContract.js +3 -38
  54. package/dist/cjs/sdk/market/zapper/IETHZapperContract.js +3 -38
  55. package/dist/cjs/sdk/market/zapper/ZapperContract.js +109 -0
  56. package/dist/cjs/sdk/market/zapper/createZapper.js +12 -4
  57. package/dist/cjs/sdk/market/zapper/errors.js +37 -0
  58. package/dist/cjs/sdk/market/zapper/index.js +6 -2
  59. package/dist/cjs/sdk/market/zapper/types.js +16 -0
  60. package/dist/cjs/sdk/options.js +41 -17
  61. package/dist/esm/abi/iZapper.js +62 -24
  62. package/dist/esm/common-utils/utils/index.js +1 -0
  63. package/dist/esm/common-utils/utils/trace.js +93 -0
  64. package/dist/esm/dev/index.js +1 -0
  65. package/dist/esm/dev/verifyTestnet.js +27 -0
  66. package/dist/esm/history/assembleOperations.js +8 -6
  67. package/dist/esm/history/classifyMulticallOperations.js +29 -23
  68. package/dist/esm/history/index.js +0 -1
  69. package/dist/esm/history/parseCreditAccountTransaction.js +3 -4
  70. package/dist/esm/history/toLegacyOperation.js +5 -1
  71. package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +28 -38
  72. package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
  73. package/dist/esm/preview/index.js +4 -0
  74. package/dist/esm/preview/package.json +1 -0
  75. package/dist/esm/preview/parse/classifyInnerOperations.js +68 -0
  76. package/dist/esm/preview/parse/errors.js +24 -0
  77. package/dist/esm/preview/parse/extractExpectedBalanceChanges.js +24 -0
  78. package/dist/esm/preview/parse/index.js +7 -0
  79. package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +91 -0
  80. package/dist/esm/preview/parse/parseOperationCalldata.js +55 -0
  81. package/dist/esm/preview/parse/parsePoolOperationCalldata.js +61 -0
  82. package/dist/esm/preview/parse/types-facades.js +0 -0
  83. package/dist/esm/preview/parse/types-pools.js +0 -0
  84. package/dist/esm/preview/parse/types.js +9 -0
  85. package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +57 -0
  86. package/dist/esm/preview/prerequisites/BalancePrerequisite.js +56 -0
  87. package/dist/esm/preview/prerequisites/Prerequisite.js +63 -0
  88. package/dist/esm/preview/prerequisites/buildPrerequisites.js +197 -0
  89. package/dist/esm/preview/prerequisites/index.js +7 -0
  90. package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
  91. package/dist/esm/preview/prerequisites/runPrerequisites.js +47 -0
  92. package/dist/esm/preview/prerequisites/types.js +0 -0
  93. package/dist/esm/preview/simulate/errors.js +69 -0
  94. package/dist/esm/preview/simulate/holders.js +21 -0
  95. package/dist/esm/preview/simulate/index.js +10 -0
  96. package/dist/esm/preview/simulate/simulateFacadeOperation.js +6 -0
  97. package/dist/esm/preview/simulate/simulateOperation.js +13 -0
  98. package/dist/esm/preview/simulate/simulatePoolOperation.js +166 -0
  99. package/dist/esm/preview/simulate/types.js +0 -0
  100. package/dist/esm/{history → preview/trace}/errors.js +0 -24
  101. package/dist/esm/preview/trace/extractAdapterCallTraces.js +40 -0
  102. package/dist/esm/{history → preview/trace}/extractTransfers.js +9 -12
  103. package/dist/esm/{history → preview/trace}/findFacadeCalls.js +4 -2
  104. package/dist/esm/preview/trace/index.js +5 -0
  105. package/dist/esm/preview/trace/types.js +0 -0
  106. package/dist/esm/sdk/MultichainSDK.js +1 -0
  107. package/dist/esm/sdk/OnchainSDK.js +7 -3
  108. package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +154 -0
  109. package/dist/esm/sdk/market/MarketRegister.js +10 -5
  110. package/dist/esm/sdk/market/ZapperRegister.js +54 -0
  111. package/dist/esm/sdk/market/zapper/IERC20ZapperContract.js +3 -38
  112. package/dist/esm/sdk/market/zapper/IETHZapperContract.js +3 -38
  113. package/dist/esm/sdk/market/zapper/ZapperContract.js +85 -0
  114. package/dist/esm/sdk/market/zapper/createZapper.js +12 -4
  115. package/dist/esm/sdk/market/zapper/errors.js +13 -0
  116. package/dist/esm/sdk/market/zapper/index.js +3 -1
  117. package/dist/esm/sdk/market/zapper/types.js +0 -0
  118. package/dist/esm/sdk/options.js +39 -15
  119. package/dist/types/abi/iERC20Zapper.d.ts +91 -23
  120. package/dist/types/abi/iETHZapper.d.ts +91 -23
  121. package/dist/types/abi/iZapper.d.ts +91 -23
  122. package/dist/types/common-utils/utils/index.d.ts +1 -0
  123. package/dist/types/common-utils/utils/trace.d.ts +73 -0
  124. package/dist/types/dev/index.d.ts +1 -0
  125. package/dist/types/dev/verifyTestnet.d.ts +24 -0
  126. package/dist/types/history/assembleOperations.d.ts +11 -6
  127. package/dist/types/history/classifyMulticallOperations.d.ts +21 -9
  128. package/dist/types/history/index.d.ts +0 -1
  129. package/dist/types/history/mapOperations.d.ts +7 -9
  130. package/dist/types/history/types.d.ts +22 -71
  131. package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +16 -17
  132. package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +10 -1
  133. package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +1 -1
  134. package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +1 -1
  135. package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +1 -1
  136. package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +1 -1
  137. package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +1 -1
  138. package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +1 -1
  139. package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +1 -1
  140. package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +1 -1
  141. package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +1 -1
  142. package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +1 -1
  143. package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +1 -1
  144. package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +1 -1
  145. package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +1 -1
  146. package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +1 -1
  147. package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +1 -1
  148. package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +1 -1
  149. package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +1 -1
  150. package/dist/types/plugins/adapters/transferHelpers.d.ts +1 -1
  151. package/dist/types/plugins/adapters/transfers.d.ts +17 -0
  152. package/dist/types/plugins/adapters/types.d.ts +8 -46
  153. package/dist/types/preview/index.d.ts +4 -0
  154. package/dist/types/preview/parse/classifyInnerOperations.d.ts +21 -0
  155. package/dist/types/preview/parse/errors.d.ts +18 -0
  156. package/dist/types/preview/parse/extractExpectedBalanceChanges.d.ts +22 -0
  157. package/dist/types/preview/parse/index.d.ts +7 -0
  158. package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +19 -0
  159. package/dist/types/preview/parse/parseOperationCalldata.d.ts +23 -0
  160. package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +17 -0
  161. package/dist/types/preview/parse/types-adapters.d.ts +69 -0
  162. package/dist/types/preview/parse/types-facades.d.ts +158 -0
  163. package/dist/types/preview/parse/types-pools.d.ts +115 -0
  164. package/dist/types/preview/parse/types.d.ts +44 -0
  165. package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +24 -0
  166. package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +23 -0
  167. package/dist/types/preview/prerequisites/Prerequisite.d.ts +60 -0
  168. package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +16 -0
  169. package/dist/types/preview/prerequisites/index.d.ts +7 -0
  170. package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -0
  171. package/dist/types/preview/prerequisites/runPrerequisites.d.ts +12 -0
  172. package/dist/types/preview/prerequisites/types.d.ts +78 -0
  173. package/dist/types/preview/simulate/errors.d.ts +45 -0
  174. package/dist/types/preview/simulate/holders.d.ts +7 -0
  175. package/dist/types/preview/simulate/index.d.ts +8 -0
  176. package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +25 -0
  177. package/dist/types/preview/simulate/simulateOperation.d.ts +20 -0
  178. package/dist/types/preview/simulate/simulatePoolOperation.d.ts +26 -0
  179. package/dist/types/preview/simulate/types.d.ts +66 -0
  180. package/dist/types/{history → preview/trace}/errors.d.ts +0 -10
  181. package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +23 -0
  182. package/dist/types/{history → preview/trace}/extractTransfers.d.ts +14 -5
  183. package/dist/types/{history → preview/trace}/findFacadeCalls.d.ts +3 -2
  184. package/dist/types/preview/trace/index.d.ts +5 -0
  185. package/dist/types/preview/trace/types.d.ts +21 -0
  186. package/dist/types/sdk/MultichainSDK.d.ts +5 -0
  187. package/dist/types/sdk/OnchainSDK.d.ts +4 -0
  188. package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +21 -1
  189. package/dist/types/sdk/accounts/types.d.ts +82 -0
  190. package/dist/types/sdk/market/MarketRegister.d.ts +15 -6
  191. package/dist/types/sdk/market/ZapperRegister.d.ts +25 -4
  192. package/dist/types/sdk/market/zapper/IERC20ZapperContract.d.ts +93 -39
  193. package/dist/types/sdk/market/zapper/IETHZapperContract.d.ts +93 -39
  194. package/dist/types/sdk/market/zapper/ZapperContract.d.ts +35 -0
  195. package/dist/types/sdk/market/zapper/createZapper.d.ts +2 -4
  196. package/dist/types/sdk/market/zapper/errors.d.ts +10 -0
  197. package/dist/types/sdk/market/zapper/index.d.ts +3 -1
  198. package/dist/types/sdk/market/zapper/types.d.ts +64 -0
  199. package/dist/types/sdk/options.d.ts +10 -5
  200. package/dist/types/sdk/pools/types.d.ts +3 -3
  201. package/dist/types/sdk/types/state-human.d.ts +9 -0
  202. package/dist/types/sdk/types/state.d.ts +7 -0
  203. package/package.json +8 -3
  204. package/dist/cjs/history/extractProtocolCalls.js +0 -53
  205. package/dist/esm/history/extractProtocolCalls.js +0 -32
  206. package/dist/esm/history/trace-utils.js +0 -36
  207. package/dist/esm/sdk/market/zapper/Zapper.js +0 -23
  208. package/dist/types/history/extractProtocolCalls.d.ts +0 -8
  209. package/dist/types/history/inner-operations.d.ts +0 -57
  210. package/dist/types/history/internal-types.d.ts +0 -47
  211. package/dist/types/history/trace-utils.d.ts +0 -12
  212. package/dist/types/sdk/market/zapper/Zapper.d.ts +0 -13
  213. /package/dist/esm/{history/inner-operations.js → plugins/adapters/transfers.js} +0 -0
  214. /package/dist/esm/{history/internal-types.js → preview/parse/types-adapters.js} +0 -0
@@ -18,19 +18,25 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var options_exports = {};
20
20
  __export(options_exports, {
21
- AttachOptionsSchema: () => AttachOptionsSchema,
22
- OnchainSDKOptionsSchema: () => OnchainSDKOptionsSchema
21
+ attachOptionsSchema: () => attachOptionsSchema,
22
+ onchainSDKOptionsSchema: () => onchainSDKOptionsSchema
23
23
  });
24
24
  module.exports = __toCommonJS(options_exports);
25
25
  var import_v4 = require("zod/v4");
26
26
  var import_updates = require("./market/pricefeeds/updates/index.js");
27
27
  var import_utils = require("./utils/index.js");
28
- const OnchainSDKOptionsSchema = import_v4.z.object({
29
- /** When `true`, throw on unrecognised contract types. */
28
+ const onchainSDKOptionsSchema = import_v4.z.object({
29
+ /**
30
+ * When `true`, throw on unrecognised contract types.
31
+ **/
30
32
  strictContractTypes: import_v4.z.boolean().optional(),
31
- /** Plugins that extend SDK functionality. */
33
+ /**
34
+ * Plugins that extend SDK functionality.
35
+ **/
32
36
  plugins: import_v4.z.record(import_v4.z.string(), import_v4.z.any()).optional(),
33
- /** Custom logger implementation. */
37
+ /**
38
+ * Custom logger implementation.
39
+ **/
34
40
  logger: import_v4.z.any(),
35
41
  /**
36
42
  * Explicit gas limit for read-only `eth_call` requests.
@@ -39,10 +45,14 @@ const OnchainSDKOptionsSchema = import_v4.z.object({
39
45
  **/
40
46
  gasLimit: import_v4.z.bigint().nonnegative().nullable().optional()
41
47
  });
42
- const AttachOptionsSchema = import_v4.z.object({
43
- /** Override address of the Gearbox AddressProvider contract. */
48
+ const attachOptionsSchema = import_v4.z.object({
49
+ /**
50
+ * Override address of the Gearbox AddressProvider contract.
51
+ **/
44
52
  addressProvider: (0, import_utils.ZodAddress)().optional(),
45
- /** Addresses of market configurator contracts to load. */
53
+ /**
54
+ * Addresses of market configurator contracts to load.
55
+ **/
46
56
  marketConfigurators: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
47
57
  /**
48
58
  * Addresses of RWA factory contracts to load.
@@ -50,19 +60,33 @@ const AttachOptionsSchema = import_v4.z.object({
50
60
  * (from {@link GearboxChain.rwaFactories})
51
61
  **/
52
62
  rwaFactories: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
53
- /** Pin SDK to a specific block number during attach. */
63
+ /**
64
+ * Pin SDK to a specific block number during attach.
65
+ **/
54
66
  blockNumber: import_v4.z.union([import_v4.z.bigint().nonnegative(), import_v4.z.number().int().nonnegative()]).optional(),
55
- /** Skip fetching updatable price feeds on attach and sync. */
67
+ /**
68
+ * Skip fetching updatable price feeds on attach and sync.
69
+ **/
56
70
  ignoreUpdateablePrices: import_v4.z.boolean().optional(),
57
- /** Pool addresses whose markets should be skipped. */
71
+ /**
72
+ * Pool addresses whose markets should be skipped.
73
+ **/
58
74
  ignoreMarkets: import_v4.z.array((0, import_utils.ZodAddress)()).optional(),
59
- /** Options for Redstone price-feed updates. */
75
+ /**
76
+ * Options for Redstone price-feed updates.
77
+ **/
60
78
  redstone: import_updates.RedstoneOptions.optional(),
61
- /** Options for Pyth price-feed updates. */
62
- pyth: import_updates.PythOptions.optional()
79
+ /**
80
+ * Options for Pyth price-feed updates.
81
+ **/
82
+ pyth: import_updates.PythOptions.optional(),
83
+ /**
84
+ * When `true`, automatically load zappers during attach.
85
+ **/
86
+ loadZappers: import_v4.z.boolean().optional()
63
87
  });
64
88
  // Annotate the CommonJS export names for ESM import in node:
65
89
  0 && (module.exports = {
66
- AttachOptionsSchema,
67
- OnchainSDKOptionsSchema
90
+ attachOptionsSchema,
91
+ onchainSDKOptionsSchema
68
92
  });
@@ -1,80 +1,118 @@
1
1
  const iZapperAbi = [
2
2
  {
3
3
  type: "function",
4
+ name: "contractType",
4
5
  inputs: [],
6
+ outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
7
+ stateMutability: "view"
8
+ },
9
+ {
10
+ type: "function",
5
11
  name: "pool",
6
- outputs: [{ name: "", internalType: "address", type: "address" }],
12
+ inputs: [],
13
+ outputs: [{ name: "", type: "address", internalType: "address" }],
7
14
  stateMutability: "view"
8
15
  },
9
16
  {
10
17
  type: "function",
18
+ name: "previewDeposit",
11
19
  inputs: [
12
- { name: "tokenInAmount", internalType: "uint256", type: "uint256" }
20
+ { name: "tokenInAmount", type: "uint256", internalType: "uint256" }
13
21
  ],
14
- name: "previewDeposit",
15
22
  outputs: [
16
- { name: "tokenOutAmount", internalType: "uint256", type: "uint256" }
23
+ { name: "tokenOutAmount", type: "uint256", internalType: "uint256" }
17
24
  ],
18
25
  stateMutability: "view"
19
26
  },
20
27
  {
21
28
  type: "function",
29
+ name: "previewRedeem",
22
30
  inputs: [
23
- { name: "tokenOutAmount", internalType: "uint256", type: "uint256" }
31
+ { name: "tokenOutAmount", type: "uint256", internalType: "uint256" }
24
32
  ],
25
- name: "previewRedeem",
26
33
  outputs: [
27
- { name: "tokenInAmount", internalType: "uint256", type: "uint256" }
34
+ { name: "tokenInAmount", type: "uint256", internalType: "uint256" }
28
35
  ],
29
36
  stateMutability: "view"
30
37
  },
31
38
  {
32
39
  type: "function",
40
+ name: "redeem",
33
41
  inputs: [
34
- { name: "tokenOutAmount", internalType: "uint256", type: "uint256" },
35
- { name: "receiver", internalType: "address", type: "address" }
42
+ { name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
43
+ { name: "receiver", type: "address", internalType: "address" }
36
44
  ],
37
- name: "redeem",
38
45
  outputs: [
39
- { name: "tokenInAmount", internalType: "uint256", type: "uint256" }
46
+ { name: "tokenInAmount", type: "uint256", internalType: "uint256" }
40
47
  ],
41
48
  stateMutability: "nonpayable"
42
49
  },
43
50
  {
44
51
  type: "function",
52
+ name: "redeemWithPermit",
45
53
  inputs: [
46
- { name: "tokenOutAmount", internalType: "uint256", type: "uint256" },
47
- { name: "receiver", internalType: "address", type: "address" },
48
- { name: "deadline", internalType: "uint256", type: "uint256" },
49
- { name: "v", internalType: "uint8", type: "uint8" },
50
- { name: "r", internalType: "bytes32", type: "bytes32" },
51
- { name: "s", internalType: "bytes32", type: "bytes32" }
54
+ { name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
55
+ { name: "receiver", type: "address", internalType: "address" },
56
+ { name: "deadline", type: "uint256", internalType: "uint256" },
57
+ { name: "v", type: "uint8", internalType: "uint8" },
58
+ { name: "r", type: "bytes32", internalType: "bytes32" },
59
+ { name: "s", type: "bytes32", internalType: "bytes32" }
52
60
  ],
53
- name: "redeemWithPermit",
54
61
  outputs: [
55
- { name: "tokenInAmount", internalType: "uint256", type: "uint256" }
62
+ { name: "tokenInAmount", type: "uint256", internalType: "uint256" }
56
63
  ],
57
64
  stateMutability: "nonpayable"
58
65
  },
59
66
  {
60
67
  type: "function",
68
+ name: "redeemWithPermitAllowed",
69
+ inputs: [
70
+ { name: "tokenOutAmount", type: "uint256", internalType: "uint256" },
71
+ { name: "receiver", type: "address", internalType: "address" },
72
+ { name: "nonce", type: "uint256", internalType: "uint256" },
73
+ { name: "expiry", type: "uint256", internalType: "uint256" },
74
+ { name: "v", type: "uint8", internalType: "uint8" },
75
+ { name: "r", type: "bytes32", internalType: "bytes32" },
76
+ { name: "s", type: "bytes32", internalType: "bytes32" }
77
+ ],
78
+ outputs: [
79
+ { name: "tokenInAmount", type: "uint256", internalType: "uint256" }
80
+ ],
81
+ stateMutability: "nonpayable"
82
+ },
83
+ {
84
+ type: "function",
85
+ name: "serialize",
61
86
  inputs: [],
62
- name: "tokenIn",
63
- outputs: [{ name: "", internalType: "address", type: "address" }],
87
+ outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
64
88
  stateMutability: "view"
65
89
  },
66
90
  {
67
91
  type: "function",
92
+ name: "tokenIn",
68
93
  inputs: [],
69
- name: "tokenOut",
70
- outputs: [{ name: "", internalType: "address", type: "address" }],
94
+ outputs: [{ name: "", type: "address", internalType: "address" }],
71
95
  stateMutability: "view"
72
96
  },
73
97
  {
74
98
  type: "function",
99
+ name: "tokenOut",
75
100
  inputs: [],
101
+ outputs: [{ name: "", type: "address", internalType: "address" }],
102
+ stateMutability: "view"
103
+ },
104
+ {
105
+ type: "function",
76
106
  name: "underlying",
77
- outputs: [{ name: "", internalType: "address", type: "address" }],
107
+ inputs: [],
108
+ outputs: [{ name: "", type: "address", internalType: "address" }],
109
+ stateMutability: "view"
110
+ },
111
+ {
112
+ type: "function",
113
+ name: "version",
114
+ inputs: [],
115
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
78
116
  stateMutability: "view"
79
117
  }
80
118
  ];
@@ -5,4 +5,5 @@ export * from "./constants.js";
5
5
  export * from "./creditAccount/index.js";
6
6
  export * from "./price-math.js";
7
7
  export * from "./strategies/index.js";
8
+ export * from "./trace.js";
8
9
  export * from "./validation/index.js";
@@ -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
+ };
@@ -23,6 +23,7 @@ export * from "./replaceStorage.js";
23
23
  export * from "./resilientTransport.js";
24
24
  export * from "./transports.js";
25
25
  export * from "./types.js";
26
+ export * from "./verifyTestnet.js";
26
27
  export {
27
28
  isRangeError,
28
29
  logSplitterTransport
@@ -0,0 +1,27 @@
1
+ import { iOnchainExecutionIdAbi } from "./abi.js";
2
+ const ONCHAIN_EXECUTION_ID_ADDRESS = "0x34131bc13eaa4ef5f98c2a423f93bc88d6ee01ba";
3
+ async function verifyTestnet(client, expected) {
4
+ try {
5
+ const { deployer, executionId, forkAlias } = await client.readContract({
6
+ abi: iOnchainExecutionIdAbi,
7
+ address: ONCHAIN_EXECUTION_ID_ADDRESS,
8
+ functionName: "info"
9
+ });
10
+ if (deployer !== "anvil-manager") {
11
+ return false;
12
+ }
13
+ if ("executionId" in expected && expected.executionId && expected.executionId !== executionId) {
14
+ return false;
15
+ }
16
+ if ("alias" in expected && expected.alias && expected.alias !== forkAlias) {
17
+ return false;
18
+ }
19
+ return true;
20
+ } catch {
21
+ return false;
22
+ }
23
+ }
24
+ export {
25
+ ONCHAIN_EXECUTION_ID_ADDRESS,
26
+ verifyTestnet
27
+ };
@@ -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
- executeResults,
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 = executeResults.slice(executeOffset, executeOffset + count);
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 protocolCalldatas = extractProtocolCalls(fc.trace, sliced);
32
+ const adapterTraces = extractAdapterCallTraces(fc.trace);
31
33
  const multicall = classifyMulticallOperations({
32
34
  innerCalls: fc.innerCalls,
33
- executeResults: sliced,
34
- protocolCalldatas,
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 "./errors.js";
11
+ } from "../preview/trace/index.js";
12
12
  function classifyMulticallOperations(input) {
13
13
  const {
14
14
  innerCalls,
15
- executeResults,
16
- protocolCalldatas,
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 executeResult = executeResults[idx];
32
- if (!executeResult) {
33
- throw new TransferAlignmentError(executeResults.length, transferIdx);
31
+ const transfers2 = executeTransfers[idx];
32
+ if (!transfers2) {
33
+ throw new TransferAlignmentError(executeTransfers.length, transferIdx);
34
34
  }
35
- const { transfers: transfers2, targetContract: targetContract2 } = executeResult;
36
- const protocolCalldata = protocolCalldatas[idx];
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
- if (partial) result.push({ ...partial, protocol: targetContract2 });
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 unknownResult = executeResults[unknownIdx];
64
- if (!unknownResult) {
65
- throw new TransferAlignmentError(executeResults.length, transferIdx);
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
- protocolFunctionName: call.functionName,
79
- protocolArgs: call.rawArgs,
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 !== executeResults.length) {
88
- throw new TransferAlignmentError(executeResults.length, transferIdx);
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,4 +1,3 @@
1
- export * from "./inner-operations.js";
2
1
  export * from "./mapOperations.js";
3
2
  import { parseCreditAccountTransaction } from "./parseCreditAccountTransaction.js";
4
3
  export * from "./populateContractsRegister.js";
@@ -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
- executeResults,
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
- executeResults,
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: op.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) {
@@ -3,13 +3,16 @@ import {
3
3
  decodeFunctionData,
4
4
  zeroAddress
5
5
  } from "viem";
6
+ import {
7
+ resolveProtocolCall
8
+ } from "../../../common-utils/utils/trace.js";
6
9
  import {
7
10
  BaseContract,
8
11
  functionArgsToRecord,
9
12
  getFunctionSignature,
10
13
  MissingSerializedParamsError
11
14
  } from "../../../sdk/index.js";
12
- import { swapFromTransfers, toNetTransfers } from "../transferHelpers.js";
15
+ import { swapFromTransfers } from "../transferHelpers.js";
13
16
  class AbstractAdapterContract extends BaseContract {
14
17
  #targetContract;
15
18
  #creditManager;
@@ -50,45 +53,33 @@ class AbstractAdapterContract extends BaseContract {
50
53
  };
51
54
  }
52
55
  /**
53
- * Builds an {@link AdapterOperation} from a parsed call and ordered transfer entries.
56
+ * Decodes the protocol-level call (target contract + function name + args)
57
+ * performed by this adapter, recovered from its adapter-level call trace.
54
58
  *
55
- * Returns `PartialBy<AdapterOperation, "targetContract">` because the adapter
56
- * may not have `targetContract` (adapters created without SDK do not have serializedParams)
59
+ * Both the `targetContract` and the protocol calldata are taken from the
60
+ * execution trace.
57
61
  *
58
- * @param protocolCalldata Raw calldata of the actual CALL to targetContract, extracted from trace
59
- * @param strict When true, throws if protocol ABI is missing or decode fails
60
- */
61
- parseAdapterOperation(parsed, transfers, creditAccount, protocolCalldata, strict) {
62
- const netTransfers = toNetTransfers(transfers, creditAccount);
63
- const protocol = this.parseProtocolCall(protocolCalldata, strict);
64
- return {
65
- operation: "Execute",
66
- adapter: this.address,
67
- protocol: this.#targetContract,
68
- adapterType: this.adapterType,
69
- version: this.version,
70
- label: parsed.label,
71
- adapterFunctionName: parsed.functionName,
72
- adapterArgs: parsed.rawArgs,
73
- ...protocol,
74
- transfers,
75
- legacy: this.classifyLegacyOperation(parsed, netTransfers)
76
- };
77
- }
78
- /**
79
- * Decodes protocol-level function name and args from the raw calldata
80
- * sent to targetContract.
62
+ * Returns `undefined` (in non-strict mode) when no external protocol call can
63
+ * be recovered, in strict mode throws instead.
64
+ *
65
+ * @param trace Adapter-level call trace (a direct child of the facade trace)
66
+ * @param strict When true, throws instead of returning `undefined`
81
67
  */
82
- parseProtocolCall(calldata, strict) {
68
+ parseProtocolCall(trace, strict) {
69
+ const resolved = resolveProtocolCall(trace);
70
+ if (!resolved) {
71
+ if (strict) {
72
+ throw new Error("no external protocol call found in adapter trace");
73
+ }
74
+ return void 0;
75
+ }
76
+ const { contract, calldata } = resolved;
83
77
  const selector = calldata.slice(0, 10);
84
78
  if (this.protocolAbi.length === 0) {
85
79
  if (strict) {
86
80
  throw new Error(`Protocol ABI is missing for selector ${selector}`);
87
81
  }
88
- return {
89
- protocolFunctionName: `unknown function ${selector}`,
90
- protocolArgs: {}
91
- };
82
+ return void 0;
92
83
  }
93
84
  try {
94
85
  const decoded = decodeFunctionData({
@@ -96,12 +87,12 @@ class AbstractAdapterContract extends BaseContract {
96
87
  data: calldata
97
88
  });
98
89
  const functionName = getFunctionSignature(this.protocolAbi, calldata);
99
- const protocolArgs = functionArgsToRecord(
90
+ const functionArgs = functionArgsToRecord(
100
91
  this.protocolAbi,
101
92
  decoded.functionName,
102
93
  decoded.args
103
94
  );
104
- return { protocolFunctionName: functionName, protocolArgs };
95
+ return { contract, functionName, functionArgs };
105
96
  } catch (e) {
106
97
  if (strict) {
107
98
  throw new Error(
@@ -109,10 +100,7 @@ class AbstractAdapterContract extends BaseContract {
109
100
  { cause: e }
110
101
  );
111
102
  }
112
- return {
113
- protocolFunctionName: `unknown function ${selector}`,
114
- protocolArgs: {}
115
- };
103
+ return void 0;
116
104
  }
117
105
  }
118
106
  /**
@@ -126,6 +114,8 @@ class AbstractAdapterContract extends BaseContract {
126
114
  * Override in protocol-specific subclasses for richer classification.
127
115
  *
128
116
  * @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/account_operation.go#L238-L264
117
+ *
118
+ * @deprecated Eventually will be gone, exists to produce output that legacy UI can display
129
119
  */
130
120
  classifyLegacyOperation(_parsed, transfers) {
131
121
  const swap = swapFromTransfers(transfers);