@gearbox-protocol/sdk 14.11.0-next.4 → 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.
- package/dist/cjs/common-utils/utils/index.js +2 -0
- package/dist/cjs/{history/trace-utils.js → common-utils/utils/trace.js} +62 -5
- package/dist/cjs/history/assembleOperations.js +6 -6
- package/dist/cjs/history/classifyMulticallOperations.js +31 -25
- package/dist/cjs/history/index.js +0 -2
- package/dist/cjs/history/parseCreditAccountTransaction.js +5 -6
- package/dist/cjs/history/toLegacyOperation.js +5 -1
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +25 -37
- package/dist/cjs/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/cjs/{history/internal-types.js → plugins/adapters/transfers.js} +2 -2
- package/dist/cjs/preview/index.js +3 -1
- package/dist/cjs/preview/parse/classifyInnerOperations.js +5 -43
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +1 -4
- package/dist/cjs/{history/inner-operations.js → preview/parse/types-adapters.js} +2 -2
- package/dist/cjs/preview/parse/types-facades.js +16 -0
- package/dist/cjs/preview/parse/types-pools.js +16 -0
- package/dist/cjs/preview/parse/types.js +8 -1
- package/dist/cjs/{history → preview/trace}/errors.js +0 -26
- package/dist/cjs/preview/trace/extractAdapterCallTraces.js +58 -0
- package/dist/cjs/{history → preview/trace}/extractTransfers.js +10 -13
- package/dist/cjs/{history → preview/trace}/findFacadeCalls.js +3 -3
- package/dist/cjs/preview/trace/index.js +30 -0
- package/dist/cjs/preview/trace/types.js +16 -0
- package/dist/esm/common-utils/utils/index.js +1 -0
- package/dist/esm/common-utils/utils/trace.js +93 -0
- package/dist/esm/history/assembleOperations.js +8 -6
- package/dist/esm/history/classifyMulticallOperations.js +29 -23
- package/dist/esm/history/index.js +0 -1
- package/dist/esm/history/parseCreditAccountTransaction.js +3 -4
- package/dist/esm/history/toLegacyOperation.js +5 -1
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +28 -38
- package/dist/esm/plugins/adapters/contracts/AccountMigratorAdapterContract.js +9 -0
- package/dist/esm/preview/index.js +1 -0
- package/dist/esm/preview/parse/classifyInnerOperations.js +6 -46
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +2 -9
- package/dist/esm/preview/parse/types-facades.js +0 -0
- package/dist/esm/preview/parse/types-pools.js +0 -0
- package/dist/esm/preview/parse/types.js +3 -0
- package/dist/esm/{history → preview/trace}/errors.js +0 -24
- package/dist/esm/preview/trace/extractAdapterCallTraces.js +40 -0
- package/dist/esm/{history → preview/trace}/extractTransfers.js +10 -13
- package/dist/esm/{history → preview/trace}/findFacadeCalls.js +4 -2
- package/dist/esm/preview/trace/index.js +5 -0
- package/dist/esm/preview/trace/types.js +0 -0
- package/dist/types/common-utils/utils/index.d.ts +1 -0
- package/dist/types/common-utils/utils/trace.d.ts +73 -0
- package/dist/types/history/assembleOperations.d.ts +11 -6
- package/dist/types/history/classifyMulticallOperations.d.ts +21 -9
- package/dist/types/history/index.d.ts +0 -1
- package/dist/types/history/mapOperations.d.ts +7 -9
- package/dist/types/history/types.d.ts +22 -65
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +16 -17
- package/dist/types/plugins/adapters/contracts/AccountMigratorAdapterContract.d.ts +10 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +1 -1
- package/dist/types/plugins/adapters/transferHelpers.d.ts +1 -1
- package/dist/types/plugins/adapters/transfers.d.ts +17 -0
- package/dist/types/plugins/adapters/types.d.ts +8 -46
- package/dist/types/preview/index.d.ts +1 -0
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +8 -8
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +4 -3
- package/dist/types/preview/parse/types-adapters.d.ts +69 -0
- package/dist/types/preview/parse/types-facades.d.ts +124 -0
- package/dist/types/preview/parse/types-pools.d.ts +42 -0
- package/dist/types/preview/parse/types.d.ts +12 -46
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +1 -1
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +1 -1
- package/dist/types/preview/simulate/types.d.ts +1 -1
- package/dist/types/{history → preview/trace}/errors.d.ts +0 -10
- package/dist/types/preview/trace/extractAdapterCallTraces.d.ts +23 -0
- package/dist/types/{history → preview/trace}/extractTransfers.d.ts +14 -5
- package/dist/types/{history → preview/trace}/findFacadeCalls.d.ts +3 -2
- package/dist/types/preview/trace/index.d.ts +5 -0
- package/dist/types/preview/trace/types.d.ts +21 -0
- package/package.json +1 -1
- package/dist/cjs/history/extractProtocolCalls.js +0 -53
- package/dist/esm/history/extractProtocolCalls.js +0 -32
- package/dist/esm/history/trace-utils.js +0 -36
- package/dist/types/history/extractProtocolCalls.d.ts +0 -8
- package/dist/types/history/inner-operations.d.ts +0 -57
- package/dist/types/history/internal-types.d.ts +0 -47
- package/dist/types/history/trace-utils.d.ts +0 -12
- /package/dist/esm/{history/inner-operations.js → plugins/adapters/transfers.js} +0 -0
- /package/dist/esm/{history/internal-types.js → preview/parse/types-adapters.js} +0 -0
|
@@ -1,56 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
AbstractAdapterContract
|
|
4
|
-
} from "../../plugins/adapters/index.js";
|
|
1
|
+
import { AbstractAdapterContract } from "../../plugins/adapters/index.js";
|
|
5
2
|
function classifyInnerOperations(calls, props) {
|
|
6
3
|
const { sdk, underlying } = props;
|
|
7
4
|
const result = [];
|
|
8
5
|
for (const call of calls) {
|
|
9
6
|
const contract = sdk.getContract(call.target);
|
|
10
|
-
if (contract instanceof AbstractAdapterContract) {
|
|
7
|
+
if (contract instanceof AbstractAdapterContract || contract === void 0) {
|
|
11
8
|
result.push({
|
|
12
9
|
operation: "Execute",
|
|
13
10
|
adapter: call.target,
|
|
14
|
-
protocol: contract.targetContract,
|
|
15
11
|
adapterType: call.contractType,
|
|
16
12
|
version: call.version,
|
|
17
13
|
label: call.label,
|
|
18
14
|
adapterFunctionName: call.functionName,
|
|
19
|
-
adapterArgs: call.rawArgs
|
|
20
|
-
// TODO: mirror the adapter call into the protocol fields for now. The
|
|
21
|
-
// real protocol-level call (adapter -> target contract) only exists in
|
|
22
|
-
// the execution call trace, which is not available from raw calldata.
|
|
23
|
-
// Recovering the actual protocol function/args requires a call trace.
|
|
24
|
-
protocolFunctionName: call.functionName,
|
|
25
|
-
protocolArgs: call.rawArgs,
|
|
26
|
-
transfers: [],
|
|
27
|
-
legacy: mockLegacyOperation()
|
|
15
|
+
adapterArgs: call.rawArgs
|
|
28
16
|
});
|
|
29
17
|
continue;
|
|
30
18
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
continue;
|
|
19
|
+
const op = classifyFacadeInnerCall(call, underlying);
|
|
20
|
+
if (op) {
|
|
21
|
+
result.push(op);
|
|
35
22
|
}
|
|
36
|
-
result.push({
|
|
37
|
-
operation: "Execute",
|
|
38
|
-
adapter: call.target,
|
|
39
|
-
protocol: call.target,
|
|
40
|
-
adapterType: call.contractType,
|
|
41
|
-
version: call.version,
|
|
42
|
-
label: call.label,
|
|
43
|
-
adapterFunctionName: call.functionName,
|
|
44
|
-
adapterArgs: call.rawArgs,
|
|
45
|
-
// TODO: mirror the adapter call into the protocol fields for now. The
|
|
46
|
-
// real protocol-level call (adapter -> target contract) only exists in
|
|
47
|
-
// the execution call trace, which is not available from raw calldata.
|
|
48
|
-
// Recovering the actual protocol function/args requires a call trace.
|
|
49
|
-
protocolFunctionName: call.functionName,
|
|
50
|
-
protocolArgs: call.rawArgs,
|
|
51
|
-
transfers: [],
|
|
52
|
-
legacy: mockLegacyOperation()
|
|
53
|
-
});
|
|
54
23
|
}
|
|
55
24
|
return result;
|
|
56
25
|
}
|
|
@@ -94,15 +63,6 @@ function classifyFacadeInnerCall(call, underlying) {
|
|
|
94
63
|
return null;
|
|
95
64
|
}
|
|
96
65
|
}
|
|
97
|
-
function mockLegacyOperation() {
|
|
98
|
-
return {
|
|
99
|
-
operation: "Swap",
|
|
100
|
-
from: zeroAddress,
|
|
101
|
-
fromAmount: "0",
|
|
102
|
-
to: zeroAddress,
|
|
103
|
-
toAmount: "0"
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
66
|
export {
|
|
107
67
|
classifyInnerOperations
|
|
108
68
|
};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isAddressEqual,
|
|
3
|
-
zeroAddress,
|
|
4
|
-
zeroHash
|
|
5
|
-
} from "viem";
|
|
1
|
+
import { isAddressEqual, zeroAddress } from "viem";
|
|
6
2
|
import { classifyInnerOperations } from "./classifyInnerOperations.js";
|
|
7
3
|
function parseFacadeOperationCalldata(props) {
|
|
8
4
|
const { sdk, facade, calldata } = props;
|
|
@@ -17,10 +13,7 @@ function parseFacadeOperationCalldata(props) {
|
|
|
17
13
|
}
|
|
18
14
|
const metadata = {
|
|
19
15
|
creditManager: suite.creditManager.address,
|
|
20
|
-
creditFacade: facade.address
|
|
21
|
-
blockNumber: Number(sdk.currentBlock),
|
|
22
|
-
txHash: zeroHash,
|
|
23
|
-
timestamp: 0
|
|
16
|
+
creditFacade: facade.address
|
|
24
17
|
};
|
|
25
18
|
const innerCalls = rawArgs.calls ?? [];
|
|
26
19
|
const multicall = classifyInnerOperations(innerCalls, {
|
|
File without changes
|
|
File without changes
|
|
@@ -22,28 +22,6 @@ class WithdrawCollateralAlignmentError extends Error {
|
|
|
22
22
|
this.name = "WithdrawCollateralAlignmentError";
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
class ProtocolCallNotFoundError extends Error {
|
|
26
|
-
targetContract;
|
|
27
|
-
executeIndex;
|
|
28
|
-
constructor(targetContract, executeIndex) {
|
|
29
|
-
super(
|
|
30
|
-
`protocol call to ${targetContract} not found in trace for Execute #${executeIndex}`
|
|
31
|
-
);
|
|
32
|
-
this.name = "ProtocolCallNotFoundError";
|
|
33
|
-
this.targetContract = targetContract;
|
|
34
|
-
this.executeIndex = executeIndex;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
class AdapterTraceAlignmentError extends Error {
|
|
38
|
-
constructor(expected, actual) {
|
|
39
|
-
super(`found ${actual} adapter traces for ${expected} execute events`);
|
|
40
|
-
this.expected = expected;
|
|
41
|
-
this.actual = actual;
|
|
42
|
-
this.name = "AdapterTracesAlignmentError";
|
|
43
|
-
}
|
|
44
|
-
expected;
|
|
45
|
-
actual;
|
|
46
|
-
}
|
|
47
25
|
class UnexpectedFacadeEventOrderError extends Error {
|
|
48
26
|
constructor(e) {
|
|
49
27
|
super(
|
|
@@ -63,8 +41,6 @@ class UnknownFacadeCallError extends Error {
|
|
|
63
41
|
}
|
|
64
42
|
}
|
|
65
43
|
export {
|
|
66
|
-
AdapterTraceAlignmentError,
|
|
67
|
-
ProtocolCallNotFoundError,
|
|
68
44
|
TransferAlignmentError,
|
|
69
45
|
UnexpectedFacadeEventOrderError,
|
|
70
46
|
UnknownAdapterError,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAbiParameters,
|
|
3
|
+
isAddressEqual,
|
|
4
|
+
toFunctionSelector
|
|
5
|
+
} from "viem";
|
|
6
|
+
import {
|
|
7
|
+
resolveProtocolCall
|
|
8
|
+
} from "../../common-utils/utils/trace.js";
|
|
9
|
+
const WITHDRAW_PHANTOM_TOKEN_SELECTOR = toFunctionSelector(
|
|
10
|
+
"withdrawPhantomToken(address,uint256)"
|
|
11
|
+
);
|
|
12
|
+
const GET_PHANTOM_TOKEN_INFO_SELECTOR = toFunctionSelector(
|
|
13
|
+
"getPhantomTokenInfo()"
|
|
14
|
+
);
|
|
15
|
+
function isSynthesizedPhantomWithdrawal(siblings, index) {
|
|
16
|
+
const node = siblings[index];
|
|
17
|
+
if (node.type !== "CALL" || node.input.slice(0, 10).toLowerCase() !== WITHDRAW_PHANTOM_TOKEN_SELECTOR) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
const [token] = decodeAbiParameters(
|
|
21
|
+
[{ type: "address" }, { type: "uint256" }],
|
|
22
|
+
`0x${node.input.slice(10)}`
|
|
23
|
+
);
|
|
24
|
+
for (let i = 0; i < index; i++) {
|
|
25
|
+
const sib = siblings[i];
|
|
26
|
+
if (sib.type === "STATICCALL" && sib.input.slice(0, 10).toLowerCase() === GET_PHANTOM_TOKEN_INFO_SELECTOR && isAddressEqual(sib.to, token)) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
function extractAdapterCallTraces(facadeTrace) {
|
|
33
|
+
const subtraces = facadeTrace.calls ?? [];
|
|
34
|
+
return subtraces.filter(
|
|
35
|
+
(sub, index) => resolveProtocolCall(sub) !== void 0 && !isSynthesizedPhantomWithdrawal(subtraces, index)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
extractAdapterCallTraces
|
|
40
|
+
};
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
isAddressEqual,
|
|
4
4
|
parseEventLogs
|
|
5
5
|
} from "viem";
|
|
6
|
-
import { iCreditFacadeV310Abi } from "
|
|
7
|
-
import { ierc20Abi } from "
|
|
8
|
-
import { AddressMap } from "
|
|
6
|
+
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
7
|
+
import { ierc20Abi } from "../../abi/iERC20.js";
|
|
8
|
+
import { AddressMap } from "../../sdk/index.js";
|
|
9
9
|
import { UnexpectedFacadeEventOrderError } from "./errors.js";
|
|
10
10
|
function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
11
11
|
const ranges = buildOperationRanges(logs, creditFacade, creditAccount);
|
|
12
12
|
let currentEntries = [];
|
|
13
|
-
const
|
|
13
|
+
const executeTransfers = [];
|
|
14
14
|
const directTransfers = [];
|
|
15
15
|
const phantomTokens = new AddressMap();
|
|
16
16
|
const withdrawCollateralEvents = [];
|
|
@@ -19,20 +19,17 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
19
19
|
const facadeEvent = tryDecodeFacadeEvent(log, creditFacade);
|
|
20
20
|
if (facadeEvent) {
|
|
21
21
|
if (isExecute(facadeEvent, creditAccount)) {
|
|
22
|
-
|
|
23
|
-
transfers: currentEntries,
|
|
24
|
-
targetContract: facadeEvent.args.targetContract
|
|
25
|
-
});
|
|
22
|
+
executeTransfers.push(currentEntries);
|
|
26
23
|
} else if (isLiquidation(facadeEvent, creditAccount)) {
|
|
27
24
|
liquidationRemainingFunds = facadeEvent.args.remainingFunds;
|
|
28
25
|
} else if (isWithdrawPhantomToken(facadeEvent, creditAccount)) {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
26
|
+
const phantomTransfers = executeTransfers.pop();
|
|
27
|
+
if (!phantomTransfers) {
|
|
31
28
|
throw new Error(
|
|
32
29
|
`WithdrawPhantomToken without preceding Execute at logIndex ${facadeEvent.logIndex}`
|
|
33
30
|
);
|
|
34
31
|
}
|
|
35
|
-
const rawDeposit =
|
|
32
|
+
const rawDeposit = phantomTransfers.find(
|
|
36
33
|
(t) => isAddressEqual(t.to, creditAccount)
|
|
37
34
|
);
|
|
38
35
|
if (!rawDeposit) {
|
|
@@ -67,11 +64,11 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
67
64
|
currentEntries.push({ token, amount: value, from, to });
|
|
68
65
|
}
|
|
69
66
|
if (isAddressEqual(to, creditAccount) && !isInRange(log.logIndex, ranges)) {
|
|
70
|
-
directTransfers.push({ token,
|
|
67
|
+
directTransfers.push({ token, amount: value, from, to });
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
return {
|
|
74
|
-
|
|
71
|
+
executeTransfers,
|
|
75
72
|
directTransfers,
|
|
76
73
|
liquidationRemainingFunds,
|
|
77
74
|
phantomTokens,
|
|
@@ -2,9 +2,11 @@ import {
|
|
|
2
2
|
decodeFunctionResult,
|
|
3
3
|
isAddressEqual
|
|
4
4
|
} from "viem";
|
|
5
|
-
import { iCreditFacadeV310Abi } from "
|
|
5
|
+
import { iCreditFacadeV310Abi } from "../../abi/310/generated.js";
|
|
6
|
+
import {
|
|
7
|
+
collectTraces
|
|
8
|
+
} from "../../common-utils/utils/trace.js";
|
|
6
9
|
import { UnknownFacadeCallError } from "./errors.js";
|
|
7
|
-
import { collectTraces } from "./trace-utils.js";
|
|
8
10
|
const FACADE_CALL_TYPES = {
|
|
9
11
|
multicall: "MultiCall",
|
|
10
12
|
botMulticall: "BotMulticall",
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* A single frame from Ethereum's `debug_traceTransaction` callTracer output.
|
|
4
|
+
* Recursive: each frame may contain nested sub-calls.
|
|
5
|
+
*/
|
|
6
|
+
export interface CallTrace {
|
|
7
|
+
from: Address;
|
|
8
|
+
to: Address;
|
|
9
|
+
input: Hex;
|
|
10
|
+
output: Hex;
|
|
11
|
+
value: Hex;
|
|
12
|
+
/** "CALL", "DELEGATECALL", "STATICCALL", "CREATE", etc. */
|
|
13
|
+
type: string;
|
|
14
|
+
/** Present when the call reverted (e.g. "execution reverted"). */
|
|
15
|
+
error?: string;
|
|
16
|
+
/** ABI-encoded revert data, if available. */
|
|
17
|
+
revertReason?: Hex;
|
|
18
|
+
calls?: CallTrace[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Selector of `CreditManagerV3.execute(bytes)` (`0x09c5eabe`).
|
|
22
|
+
*
|
|
23
|
+
* This is the authoritative marker of an adapter performing an external
|
|
24
|
+
* protocol call: the adapter calls the credit manager's `execute(bytes)`, which
|
|
25
|
+
* forwards the calldata to the credit account, which in turn CALLs the target
|
|
26
|
+
* (protocol) contract. Adapter approvals use a different selector
|
|
27
|
+
* (`execute(address,bytes)` on the credit account), so matching on this
|
|
28
|
+
* selector isolates the real protocol call.
|
|
29
|
+
*/
|
|
30
|
+
export declare const EXECUTE_BYTES_SELECTOR: "0x09c5eabe";
|
|
31
|
+
/**
|
|
32
|
+
* Finds the shallowest non-reverted `CreditManager.execute(bytes)` call in a
|
|
33
|
+
* trace subtree (breadth-first), or `undefined` if none exists.
|
|
34
|
+
*
|
|
35
|
+
* "Shallowest" matters for account migration: a migrate adapter nests the
|
|
36
|
+
* entire target `openCreditAccount` multicall - including that account's own
|
|
37
|
+
* `execute(bytes)` calls - inside its subtree. The shallowest match is the
|
|
38
|
+
* adapter's own protocol call, not a nested one.
|
|
39
|
+
*/
|
|
40
|
+
export declare function findExecuteBytes(node: CallTrace): CallTrace | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Finds the first non-reverted CALL in a subtree whose `input` exactly matches
|
|
43
|
+
* `input` (case-insensitive). Used to locate the leaf CALL to the target
|
|
44
|
+
* contract: `execute(bytes)` forwards the calldata unchanged through the credit
|
|
45
|
+
* account proxy DELEGATECALL down to the final CALL to the protocol contract.
|
|
46
|
+
*/
|
|
47
|
+
export declare function findCallWithInput(node: CallTrace, input: Hex): CallTrace | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the external protocol call performed by an adapter-level call trace.
|
|
50
|
+
*
|
|
51
|
+
* Locates the shallowest `CreditManager.execute(bytes)`, decodes the forwarded
|
|
52
|
+
* calldata, then finds the leaf CALL whose input matches that calldata to
|
|
53
|
+
* recover the target (protocol) contract address. Returns `undefined` when the
|
|
54
|
+
* subtree does not actually reach an external protocol CALL (e.g. the
|
|
55
|
+
* facade-internal `depositPhantomToken` / `withdrawPhantomToken` accounting
|
|
56
|
+
* calls, which forward calldata but make no external CALL).
|
|
57
|
+
*
|
|
58
|
+
* @param node - direct child node of the upper-level facade call trace
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveProtocolCall(node: CallTrace): {
|
|
61
|
+
contract: Address;
|
|
62
|
+
calldata: Hex;
|
|
63
|
+
} | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Finds the first non-reverted CALL to `target` anywhere in a trace subtree.
|
|
66
|
+
*/
|
|
67
|
+
export declare function findCallTo(node: CallTrace, target: Address): CallTrace | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* DFS walk of the call trace tree, collecting non-reverted CALL entries
|
|
70
|
+
* to the given address.
|
|
71
|
+
* Does not recurse into children of matched nodes
|
|
72
|
+
*/
|
|
73
|
+
export declare function collectTraces(node: CallTrace, target: Address): CallTrace[];
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
+
import type { TokenTransfer } from "../preview/parse/index.js";
|
|
3
|
+
import { type FacadeParsedCall, type WithdrawCollateralEventInfo } from "../preview/trace/index.js";
|
|
2
4
|
import type { AddressMap, ChainContractsRegister } from "../sdk/index.js";
|
|
3
|
-
import type {
|
|
4
|
-
import type { ExecuteResult, FacadeParsedCall } from "./internal-types.js";
|
|
5
|
-
import type { FacadeOperationMetadata, OuterFacadeOperation } from "./types.js";
|
|
5
|
+
import type { HistoryFacadeMetadata, OuterFacadeOperation } from "./types.js";
|
|
6
6
|
export interface AssembleOperationsInput {
|
|
7
7
|
facadeCalls: FacadeParsedCall[];
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* ERC-20 transfers grouped per facade `Execute` event, one inner array per
|
|
10
|
+
* Execute event across the whole transaction, in emission order. Sliced per
|
|
11
|
+
* facade call and consumed one inner array per adapter/unknown inner call.
|
|
12
|
+
*/
|
|
13
|
+
executeTransfers: TokenTransfer[][];
|
|
9
14
|
register: ChainContractsRegister;
|
|
10
15
|
underlying: Address;
|
|
11
16
|
liquidationRemainingFunds?: bigint;
|
|
@@ -17,8 +22,8 @@ export interface AssembleOperationsInput {
|
|
|
17
22
|
* Combines parsed facade calls with per-Execute transfer data into
|
|
18
23
|
* fully classified {@link OuterFacadeOperation} entries.
|
|
19
24
|
*
|
|
20
|
-
* The flat `
|
|
25
|
+
* The flat `executeTransfers` array (one inner array per Execute event across
|
|
21
26
|
* the entire transaction) is sliced per facade call based on how many
|
|
22
27
|
* adapter/unknown inner calls each one contains.
|
|
23
28
|
*/
|
|
24
|
-
export declare function assembleOperations(input: AssembleOperationsInput): Omit<OuterFacadeOperation, keyof
|
|
29
|
+
export declare function assembleOperations(input: AssembleOperationsInput): Omit<OuterFacadeOperation, keyof HistoryFacadeMetadata>[];
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { type Address
|
|
1
|
+
import { type Address } from "viem";
|
|
2
|
+
import type { CallTrace } from "../common-utils/utils/trace.js";
|
|
3
|
+
import type { TokenTransfer } from "../preview/parse/index.js";
|
|
4
|
+
import { type WithdrawCollateralEventInfo } from "../preview/trace/index.js";
|
|
2
5
|
import type { AddressMap, ChainContractsRegister, ParsedCallV2 } from "../sdk/index.js";
|
|
3
|
-
import type {
|
|
4
|
-
import type { InnerOperation } from "./inner-operations.js";
|
|
5
|
-
import type { ExecuteResult } from "./internal-types.js";
|
|
6
|
+
import type { InnerOperation } from "./types.js";
|
|
6
7
|
export interface ClassifyMulticallOperationsInput {
|
|
7
8
|
innerCalls: ParsedCallV2[];
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* ERC-20 transfers grouped per facade `Execute` event for this facade call,
|
|
11
|
+
* one inner array per Execute event, in order. One inner array is consumed
|
|
12
|
+
* per adapter/unknown inner call.
|
|
13
|
+
*/
|
|
14
|
+
executeTransfers: TokenTransfer[][];
|
|
15
|
+
/**
|
|
16
|
+
* Adapter-level call traces (one per Execute event, in order) used to recover
|
|
17
|
+
* the protocol-level call for adapter inner calls. See
|
|
18
|
+
* `extractAdapterCallTraces`.
|
|
19
|
+
*/
|
|
20
|
+
adapterTraces: CallTrace[];
|
|
10
21
|
register: ChainContractsRegister;
|
|
11
22
|
creditAccount: Address;
|
|
12
23
|
underlying: Address;
|
|
@@ -17,9 +28,10 @@ export interface ClassifyMulticallOperationsInput {
|
|
|
17
28
|
/**
|
|
18
29
|
* Classifies each multicall inner call into a {@link InnerOperation}:
|
|
19
30
|
*
|
|
20
|
-
* - **Adapter calls** (target registered as an adapter):
|
|
21
|
-
* `adapter.
|
|
22
|
-
*
|
|
31
|
+
* - **Adapter calls** (target registered as an adapter): decodes the
|
|
32
|
+
* protocol-level call via `adapter.parseProtocolCall()`, classifies the
|
|
33
|
+
* legacy operation via `adapter.classifyLegacyOperation()`, and consumes the
|
|
34
|
+
* next entry from `executeTransfers` (one Execute event per adapter call).
|
|
23
35
|
*
|
|
24
36
|
* - **Facade self-calls** (`increaseDebt`, `updateQuota`, etc.): mapped
|
|
25
37
|
* directly from `functionName` / `rawArgs`. No transfer consumed.
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import type { AdapterOperation } from "
|
|
2
|
-
import type { AddCollateralOp, DecreaseDebtOp, IncreaseDebtOp, UpdateQuotaOp, WithdrawCollateralOp } from "./inner-operations.js";
|
|
3
|
-
import type { CloseCreditAccountOperation, CreditAccountOperation, DirectTokenTransferOperation, FacadeOperationMetadata, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, PartialLiquidationOperation } from "./types.js";
|
|
1
|
+
import type { AdapterOperation, AddCollateralOp, CloseCreditAccountOperation, CreditAccountOperation, DecreaseDebtOp, DirectTokenTransferOperation, HistoryFacadeMetadata, IncreaseDebtOp, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, PartialLiquidationOperation, UpdateQuotaOp, WithdrawCollateralOp } from "./types.js";
|
|
4
2
|
/**
|
|
5
3
|
* Visitor that maps each operation node in a {@link CreditAccountOperation}
|
|
6
4
|
* tree to a new representation.
|
|
7
5
|
*
|
|
8
6
|
*/
|
|
9
7
|
export interface OperationVisitor<TInner, TOuter> {
|
|
10
|
-
Execute(op: AdapterOperation, ctx:
|
|
11
|
-
IncreaseBorrowedAmount(op: IncreaseDebtOp, ctx:
|
|
12
|
-
DecreaseBorrowedAmount(op: DecreaseDebtOp, ctx:
|
|
13
|
-
AddCollateral(op: AddCollateralOp, ctx:
|
|
14
|
-
WithdrawCollateral(op: WithdrawCollateralOp, ctx:
|
|
15
|
-
UpdateQuota(op: UpdateQuotaOp, ctx:
|
|
8
|
+
Execute(op: AdapterOperation, ctx: HistoryFacadeMetadata): TInner;
|
|
9
|
+
IncreaseBorrowedAmount(op: IncreaseDebtOp, ctx: HistoryFacadeMetadata): TInner;
|
|
10
|
+
DecreaseBorrowedAmount(op: DecreaseDebtOp, ctx: HistoryFacadeMetadata): TInner;
|
|
11
|
+
AddCollateral(op: AddCollateralOp, ctx: HistoryFacadeMetadata): TInner;
|
|
12
|
+
WithdrawCollateral(op: WithdrawCollateralOp, ctx: HistoryFacadeMetadata): TInner;
|
|
13
|
+
UpdateQuota(op: UpdateQuotaOp, ctx: HistoryFacadeMetadata): TInner;
|
|
16
14
|
DirectTokenTransfer(op: DirectTokenTransferOperation): TOuter;
|
|
17
15
|
MultiCall(op: MulticallOperation, multicall: TInner[]): TOuter;
|
|
18
16
|
OpenCreditAccount(op: OpenCreditAccountOperation, multicall: TInner[]): TOuter;
|
|
@@ -1,71 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { InnerOperation } from "
|
|
1
|
+
import type { LegacyAdapterOperation } from "../plugins/adapters/index.js";
|
|
2
|
+
import type { AdapterOperation as BaseAdapterOperation, CloseCreditAccountOperation as BaseCloseCreditAccountOperation, DirectTokenTransferOperation as BaseDirectTokenTransferOperation, InnerOperation as BaseInnerOperation, LiquidateCreditAccountOperation as BaseLiquidateCreditAccountOperation, MulticallOperation as BaseMulticallOperation, OpenCreditAccountOperation as BaseOpenCreditAccountOperation, PartialLiquidationOperation as BasePartialLiquidationOperation, FacadeOperationMetadata, OperationMetadata, TraceAdapterExt } from "../preview/parse/index.js";
|
|
3
|
+
export type { AddCollateralOp, DecreaseDebtOp, FacadeOperationMetadata, IncreaseDebtOp, InnerFacadeOperation, OperationMetadata, UpdateQuotaOp, WithdrawCollateralOp, } from "../preview/parse/index.js";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* History-specific adapter-operation extension: trace-derived data
|
|
6
|
+
* ({@link TraceAdapterExt}) plus the backward-compatible `legacy` classification
|
|
7
|
+
* used by charts_server serialization. The `legacy` field lives only in
|
|
8
|
+
* `history`; the base `preview` operations carry no `legacy`.
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
amount: bigint;
|
|
11
|
-
}
|
|
12
|
-
export interface OperationMetadata {
|
|
13
|
-
txHash: Hex;
|
|
14
|
-
blockNumber: number;
|
|
15
|
-
timestamp: number;
|
|
16
|
-
}
|
|
17
|
-
export interface FacadeOperationMetadata extends OperationMetadata {
|
|
18
|
-
creditManager: Address;
|
|
19
|
-
creditFacade: Address;
|
|
20
|
-
}
|
|
21
|
-
export interface MulticallOperation extends FacadeOperationMetadata {
|
|
22
|
-
operation: "MultiCall" | "BotMulticall";
|
|
23
|
-
creditAccount: Address;
|
|
24
|
-
multicall: InnerOperation[];
|
|
25
|
-
}
|
|
26
|
-
export interface OpenCreditAccountOperation extends FacadeOperationMetadata {
|
|
27
|
-
operation: "OpenCreditAccount";
|
|
28
|
-
creditAccount: Address;
|
|
29
|
-
onBehalfOf: Address;
|
|
30
|
-
referralCode: bigint;
|
|
31
|
-
multicall: InnerOperation[];
|
|
32
|
-
}
|
|
33
|
-
export interface CloseCreditAccountOperation extends FacadeOperationMetadata {
|
|
34
|
-
operation: "CloseCreditAccount";
|
|
35
|
-
creditAccount: Address;
|
|
36
|
-
multicall: InnerOperation[];
|
|
37
|
-
}
|
|
38
|
-
export interface LiquidateCreditAccountOperation extends FacadeOperationMetadata {
|
|
39
|
-
operation: "LiquidateCreditAccount";
|
|
40
|
-
creditAccount: Address;
|
|
41
|
-
to: Address;
|
|
42
|
-
token: Address;
|
|
43
|
-
remainingFunds: bigint;
|
|
44
|
-
multicall: InnerOperation[];
|
|
45
|
-
}
|
|
46
|
-
export interface PartialLiquidationOperation extends FacadeOperationMetadata {
|
|
47
|
-
operation: "PartiallyLiquidateCreditAccount";
|
|
48
|
-
creditAccount: Address;
|
|
49
|
-
token: Address;
|
|
50
|
-
repaidAmount: bigint;
|
|
51
|
-
minSeizedAmount: bigint;
|
|
52
|
-
to: Address;
|
|
53
|
-
}
|
|
54
|
-
export interface DirectTokenTransferOperation extends OperationMetadata {
|
|
55
|
-
operation: "DirectTokenTransfer";
|
|
56
|
-
protocol: Address;
|
|
57
|
-
token: Address;
|
|
58
|
-
from: Address;
|
|
59
|
-
creditAccount: Address;
|
|
60
|
-
amount: bigint;
|
|
61
|
-
}
|
|
10
|
+
export type HistoryAdapterExt = TraceAdapterExt & {
|
|
11
|
+
legacy: LegacyAdapterOperation;
|
|
12
|
+
};
|
|
62
13
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
14
|
+
* Facade context available in `history` mode: the base facade metadata
|
|
15
|
+
* (`creditManager`/`creditFacade`) plus the transaction-level
|
|
16
|
+
* {@link OperationMetadata} that is only known once the transaction is mined.
|
|
65
17
|
*/
|
|
18
|
+
export type HistoryFacadeMetadata = FacadeOperationMetadata & OperationMetadata;
|
|
19
|
+
export type AdapterOperation = BaseAdapterOperation<HistoryAdapterExt>;
|
|
20
|
+
export type InnerOperation = BaseInnerOperation<HistoryAdapterExt>;
|
|
21
|
+
export type MulticallOperation = BaseMulticallOperation<HistoryAdapterExt> & OperationMetadata;
|
|
22
|
+
export type OpenCreditAccountOperation = BaseOpenCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
|
|
23
|
+
export type CloseCreditAccountOperation = BaseCloseCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
|
|
24
|
+
export type LiquidateCreditAccountOperation = BaseLiquidateCreditAccountOperation<HistoryAdapterExt> & OperationMetadata;
|
|
25
|
+
export type PartialLiquidationOperation = BasePartialLiquidationOperation & OperationMetadata;
|
|
26
|
+
export type DirectTokenTransferOperation = BaseDirectTokenTransferOperation & OperationMetadata;
|
|
66
27
|
export type OuterFacadeOperation = MulticallOperation | OpenCreditAccountOperation | CloseCreditAccountOperation | LiquidateCreditAccountOperation | PartialLiquidationOperation;
|
|
67
|
-
/**
|
|
68
|
-
* Discriminated union of all credit account operation types
|
|
69
|
-
* (facade operations + direct token transfers).
|
|
70
|
-
*/
|
|
71
28
|
export type CreditAccountOperation = OuterFacadeOperation | DirectTokenTransferOperation;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type Abi, type Address
|
|
1
|
+
import { type Abi, type Address } from "viem";
|
|
2
|
+
import { type CallTrace } from "../../../common-utils/utils/trace.js";
|
|
2
3
|
import type { ConstructOptions, ParsedCallV2, RelaxedBaseParams } from "../../../sdk/index.js";
|
|
3
4
|
import { BaseContract } from "../../../sdk/index.js";
|
|
4
5
|
import type { LegacyAdapterOperation, Transfers } from "../legacyAdapterOperations.js";
|
|
5
|
-
import type { AdapterContractStateHuman, AdapterContractType,
|
|
6
|
+
import type { AdapterContractStateHuman, AdapterContractType, AdapterProtocolOperation } from "../types.js";
|
|
6
7
|
export interface ConcreteAdapterContractOptions {
|
|
7
8
|
baseParams: RelaxedBaseParams;
|
|
8
9
|
}
|
|
@@ -22,23 +23,19 @@ export declare class AbstractAdapterContract<const abi extends Abi | readonly un
|
|
|
22
23
|
get adapterType(): AdapterContractType;
|
|
23
24
|
stateHuman(raw?: boolean): AdapterContractStateHuman;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* Decodes the protocol-level call (target contract + function name + args)
|
|
27
|
+
* performed by this adapter, recovered from its adapter-level call trace.
|
|
26
28
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
+
* Both the `targetContract` and the protocol calldata are taken from the
|
|
30
|
+
* execution trace.
|
|
29
31
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
* Decodes protocol-level function name and args from the raw calldata
|
|
36
|
-
* sent to targetContract.
|
|
32
|
+
* Returns `undefined` (in non-strict mode) when no external protocol call can
|
|
33
|
+
* be recovered, in strict mode throws instead.
|
|
34
|
+
*
|
|
35
|
+
* @param trace Adapter-level call trace (a direct child of the facade trace)
|
|
36
|
+
* @param strict When true, throws instead of returning `undefined`
|
|
37
37
|
*/
|
|
38
|
-
|
|
39
|
-
protocolFunctionName: string;
|
|
40
|
-
protocolArgs: Record<string, unknown>;
|
|
41
|
-
};
|
|
38
|
+
parseProtocolCall(trace: CallTrace, strict?: boolean): AdapterProtocolOperation | undefined;
|
|
42
39
|
/**
|
|
43
40
|
* Classifies an adapter call into a {@link LegacyAdapterOperation} using the
|
|
44
41
|
* parsed call and credit-account transfer deltas.
|
|
@@ -50,6 +47,8 @@ export declare class AbstractAdapterContract<const abi extends Abi | readonly un
|
|
|
50
47
|
* Override in protocol-specific subclasses for richer classification.
|
|
51
48
|
*
|
|
52
49
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/account_operation.go#L238-L264
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Eventually will be gone, exists to produce output that legacy UI can display
|
|
53
52
|
*/
|
|
54
|
-
|
|
53
|
+
classifyLegacyOperation(_parsed: ParsedCallV2, transfers: Transfers): LegacyAdapterOperation;
|
|
55
54
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { CallTrace } from "../../../common-utils/utils/trace.js";
|
|
1
2
|
import type { ConstructOptions, ParsedCallV2 } from "../../../sdk/index.js";
|
|
2
3
|
import type { LegacyAdapterOperation, Transfers } from "../legacyAdapterOperations.js";
|
|
4
|
+
import type { AdapterProtocolOperation } from "../types.js";
|
|
3
5
|
import type { ConcreteAdapterContractOptions } from "./AbstractAdapter.js";
|
|
4
6
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
5
7
|
declare const abi: readonly [{
|
|
@@ -467,6 +469,13 @@ type protocolAbi = typeof protocolAbi;
|
|
|
467
469
|
export declare class AccountMigratorAdapterContract extends AbstractAdapterContract<abi, protocolAbi> {
|
|
468
470
|
constructor(options: ConstructOptions, args: ConcreteAdapterContractOptions);
|
|
469
471
|
/** Legacy adapter not present in integrations-v3. */
|
|
470
|
-
|
|
472
|
+
classifyLegacyOperation(_parsed: ParsedCallV2, _transfers: Transfers): LegacyAdapterOperation;
|
|
473
|
+
/**
|
|
474
|
+
* The account-migrator adapter's `execute` targets the migrator bot, not an
|
|
475
|
+
* external protocol, so there is no protocol-level call to recover. Returning
|
|
476
|
+
* `undefined` keeps the `protocol` field aligned with its external-protocol
|
|
477
|
+
* semantics (see {@link TraceAdapterExt}).
|
|
478
|
+
*/
|
|
479
|
+
parseProtocolCall(_trace: CallTrace, _strict?: boolean): AdapterProtocolOperation | undefined;
|
|
471
480
|
}
|
|
472
481
|
export {};
|
|
@@ -689,6 +689,6 @@ export declare class ConvexV1BaseRewardPoolAdapterContract extends AbstractAdapt
|
|
|
689
689
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type.go#L200-L262
|
|
690
690
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L76-L83
|
|
691
691
|
*/
|
|
692
|
-
|
|
692
|
+
classifyLegacyOperation(parsed: ParsedCallV2, transfers: Transfers): LegacyAdapterOperation;
|
|
693
693
|
}
|
|
694
694
|
export {};
|