@gearbox-protocol/sdk 14.11.2 → 14.12.0-next.1
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/dev/abi.js +162 -6
- package/dist/cjs/dev/index.js +3 -1
- package/dist/cjs/dev/verifyTestnet.js +52 -0
- 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 +28 -0
- package/dist/cjs/preview/package.json +1 -0
- package/dist/cjs/preview/parse/classifyInnerOperations.js +92 -0
- package/dist/cjs/preview/parse/errors.js +47 -0
- package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +48 -0
- package/dist/cjs/preview/parse/index.js +34 -0
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +115 -0
- package/dist/cjs/preview/parse/parseOperationCalldata.js +46 -0
- package/dist/cjs/preview/parse/parsePoolOperationCalldata.js +77 -0
- 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 +37 -0
- package/dist/cjs/preview/prerequisites/AllowancePrerequisite.js +78 -0
- package/dist/cjs/preview/prerequisites/BalancePrerequisite.js +77 -0
- package/dist/cjs/preview/prerequisites/Prerequisite.js +85 -0
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +187 -0
- package/dist/cjs/preview/prerequisites/index.js +34 -0
- package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
- package/dist/cjs/preview/prerequisites/runPrerequisites.js +71 -0
- package/dist/cjs/preview/prerequisites/types.js +16 -0
- package/dist/cjs/preview/simulate/constants.js +28 -0
- package/dist/cjs/preview/simulate/errors.js +98 -0
- package/dist/cjs/preview/simulate/extractERC20Transfers.js +47 -0
- package/dist/cjs/preview/simulate/holders.js +45 -0
- package/dist/cjs/preview/simulate/index.js +40 -0
- package/dist/cjs/preview/simulate/simulateFacadeOperation.js +30 -0
- package/dist/cjs/preview/simulate/simulateOperation.js +37 -0
- package/dist/cjs/preview/simulate/simulatePoolOpMulticall.js +155 -0
- package/dist/cjs/preview/simulate/simulatePoolOpV1.js +106 -0
- package/dist/cjs/preview/simulate/simulatePoolOperation.js +62 -0
- package/dist/cjs/preview/simulate/types.js +16 -0
- 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 +9 -12
- 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/cjs/sdk/accounts/CreditAccountsServiceV310.js +154 -0
- package/dist/esm/common-utils/utils/index.js +1 -0
- package/dist/esm/common-utils/utils/trace.js +93 -0
- package/dist/esm/dev/abi.js +162 -6
- package/dist/esm/dev/index.js +1 -0
- package/dist/esm/dev/verifyTestnet.js +27 -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 +4 -0
- package/dist/esm/preview/package.json +1 -0
- package/dist/esm/preview/parse/classifyInnerOperations.js +68 -0
- package/dist/esm/preview/parse/errors.js +22 -0
- package/dist/esm/preview/parse/extractExpectedBalanceChanges.js +24 -0
- package/dist/esm/preview/parse/index.js +7 -0
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +91 -0
- package/dist/esm/preview/parse/parseOperationCalldata.js +25 -0
- package/dist/esm/preview/parse/parsePoolOperationCalldata.js +53 -0
- 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 +9 -0
- package/dist/esm/preview/prerequisites/AllowancePrerequisite.js +57 -0
- package/dist/esm/preview/prerequisites/BalancePrerequisite.js +56 -0
- package/dist/esm/preview/prerequisites/Prerequisite.js +63 -0
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +163 -0
- package/dist/esm/preview/prerequisites/index.js +7 -0
- package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
- package/dist/esm/preview/prerequisites/runPrerequisites.js +47 -0
- package/dist/esm/preview/prerequisites/types.js +0 -0
- package/dist/esm/preview/simulate/constants.js +4 -0
- package/dist/esm/preview/simulate/errors.js +75 -0
- package/dist/esm/preview/simulate/extractERC20Transfers.js +23 -0
- package/dist/esm/preview/simulate/holders.js +21 -0
- package/dist/esm/preview/simulate/index.js +12 -0
- package/dist/esm/preview/simulate/simulateFacadeOperation.js +6 -0
- package/dist/esm/preview/simulate/simulateOperation.js +13 -0
- package/dist/esm/preview/simulate/simulatePoolOpMulticall.js +130 -0
- package/dist/esm/preview/simulate/simulatePoolOpV1.js +82 -0
- package/dist/esm/preview/simulate/simulatePoolOperation.js +41 -0
- package/dist/esm/preview/simulate/types.js +0 -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 +9 -12
- 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/esm/sdk/accounts/CreditAccountsServiceV310.js +154 -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/dev/abi.d.ts +98 -16
- package/dist/types/dev/index.d.ts +1 -0
- package/dist/types/dev/verifyTestnet.d.ts +24 -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 -71
- 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 +4 -0
- package/dist/types/preview/parse/classifyInnerOperations.d.ts +21 -0
- package/dist/types/preview/parse/errors.d.ts +17 -0
- package/dist/types/preview/parse/extractExpectedBalanceChanges.d.ts +22 -0
- package/dist/types/preview/parse/index.d.ts +7 -0
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +19 -0
- package/dist/types/preview/parse/parseOperationCalldata.d.ts +23 -0
- package/dist/types/preview/parse/parsePoolOperationCalldata.d.ts +17 -0
- package/dist/types/preview/parse/types-adapters.d.ts +69 -0
- package/dist/types/preview/parse/types-facades.d.ts +158 -0
- package/dist/types/preview/parse/types-pools.d.ts +55 -0
- package/dist/types/preview/parse/types.d.ts +44 -0
- package/dist/types/preview/prerequisites/AllowancePrerequisite.d.ts +24 -0
- package/dist/types/preview/prerequisites/BalancePrerequisite.d.ts +23 -0
- package/dist/types/preview/prerequisites/Prerequisite.d.ts +60 -0
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +16 -0
- package/dist/types/preview/prerequisites/index.d.ts +7 -0
- package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -0
- package/dist/types/preview/prerequisites/runPrerequisites.d.ts +12 -0
- package/dist/types/preview/prerequisites/types.d.ts +78 -0
- package/dist/types/preview/simulate/constants.d.ts +6 -0
- package/dist/types/preview/simulate/errors.d.ts +51 -0
- package/dist/types/preview/simulate/extractERC20Transfers.d.ts +11 -0
- package/dist/types/preview/simulate/holders.d.ts +7 -0
- package/dist/types/preview/simulate/index.d.ts +9 -0
- package/dist/types/preview/simulate/simulateFacadeOperation.d.ts +25 -0
- package/dist/types/preview/simulate/simulateOperation.d.ts +20 -0
- package/dist/types/preview/simulate/simulatePoolOpMulticall.d.ts +28 -0
- package/dist/types/preview/simulate/simulatePoolOpV1.d.ts +14 -0
- package/dist/types/preview/simulate/simulatePoolOperation.d.ts +8 -0
- package/dist/types/preview/simulate/types.d.ts +79 -0
- 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/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +21 -1
- package/dist/types/sdk/accounts/types.d.ts +82 -0
- package/package.json +6 -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
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
TransferAlignmentError,
|
|
9
9
|
UnknownAdapterError,
|
|
10
10
|
WithdrawCollateralAlignmentError
|
|
11
|
-
} from "
|
|
11
|
+
} from "../preview/trace/index.js";
|
|
12
12
|
function classifyMulticallOperations(input) {
|
|
13
13
|
const {
|
|
14
14
|
innerCalls,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
executeTransfers,
|
|
16
|
+
adapterTraces,
|
|
17
17
|
register,
|
|
18
18
|
creditAccount,
|
|
19
19
|
underlying,
|
|
@@ -28,20 +28,27 @@ function classifyMulticallOperations(input) {
|
|
|
28
28
|
const contract = register.getContract(call.target);
|
|
29
29
|
if (contract instanceof AbstractAdapterContract) {
|
|
30
30
|
const idx = transferIdx++;
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
33
|
-
throw new TransferAlignmentError(
|
|
31
|
+
const transfers2 = executeTransfers[idx];
|
|
32
|
+
if (!transfers2) {
|
|
33
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const partial = contract.parseAdapterOperation(
|
|
35
|
+
const protocol = contract.parseProtocolCall(adapterTraces[idx], strict);
|
|
36
|
+
const legacy = contract.classifyLegacyOperation(
|
|
38
37
|
call,
|
|
39
|
-
transfers2,
|
|
40
|
-
creditAccount,
|
|
41
|
-
protocolCalldata,
|
|
42
|
-
strict
|
|
38
|
+
toNetTransfers(transfers2, creditAccount)
|
|
43
39
|
);
|
|
44
|
-
|
|
40
|
+
result.push({
|
|
41
|
+
operation: "Execute",
|
|
42
|
+
adapter: call.target,
|
|
43
|
+
adapterType: call.contractType,
|
|
44
|
+
version: call.version,
|
|
45
|
+
label: call.label,
|
|
46
|
+
adapterFunctionName: call.functionName,
|
|
47
|
+
adapterArgs: call.rawArgs,
|
|
48
|
+
protocol,
|
|
49
|
+
transfers: transfers2,
|
|
50
|
+
legacy
|
|
51
|
+
});
|
|
45
52
|
continue;
|
|
46
53
|
}
|
|
47
54
|
if (contract !== void 0) {
|
|
@@ -60,23 +67,22 @@ function classifyMulticallOperations(input) {
|
|
|
60
67
|
throw new UnknownAdapterError(call.target);
|
|
61
68
|
}
|
|
62
69
|
const unknownIdx = transferIdx++;
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
65
|
-
throw new TransferAlignmentError(
|
|
70
|
+
const transfers = executeTransfers[unknownIdx];
|
|
71
|
+
if (!transfers) {
|
|
72
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
66
73
|
}
|
|
67
|
-
const { transfers, targetContract } = unknownResult;
|
|
68
74
|
const netTransfers = toNetTransfers(transfers, creditAccount);
|
|
69
75
|
result.push({
|
|
70
76
|
operation: "Execute",
|
|
71
77
|
adapter: call.target,
|
|
72
|
-
protocol: targetContract,
|
|
73
78
|
adapterType: call.contractType,
|
|
74
79
|
version: call.version,
|
|
75
80
|
label: call.label,
|
|
76
81
|
adapterFunctionName: call.functionName,
|
|
77
82
|
adapterArgs: call.rawArgs,
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
// Unknown adapter (non-strict): we have no ABI to decode the protocol
|
|
84
|
+
// call, so `protocol` is left absent rather than filled with placeholders.
|
|
85
|
+
protocol: void 0,
|
|
80
86
|
transfers,
|
|
81
87
|
legacy: {
|
|
82
88
|
operation: "Swap",
|
|
@@ -84,8 +90,8 @@ function classifyMulticallOperations(input) {
|
|
|
84
90
|
}
|
|
85
91
|
});
|
|
86
92
|
}
|
|
87
|
-
if (transferIdx !==
|
|
88
|
-
throw new TransferAlignmentError(
|
|
93
|
+
if (transferIdx !== executeTransfers.length) {
|
|
94
|
+
throw new TransferAlignmentError(executeTransfers.length, transferIdx);
|
|
89
95
|
}
|
|
90
96
|
if (withdrawCollateralEvents && withdrawCollateralEvents.length > 0 && withdrawIdx !== withdrawCollateralEvents.length) {
|
|
91
97
|
throw new WithdrawCollateralAlignmentError(
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { extractTransfers, findFacadeCalls } from "../preview/trace/index.js";
|
|
1
2
|
import { assembleOperations } from "./assembleOperations.js";
|
|
2
|
-
import { extractTransfers } from "./extractTransfers.js";
|
|
3
|
-
import { findFacadeCalls } from "./findFacadeCalls.js";
|
|
4
3
|
function parseCreditAccountTransaction(input) {
|
|
5
4
|
const {
|
|
6
5
|
trace,
|
|
@@ -25,7 +24,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
25
24
|
strict
|
|
26
25
|
);
|
|
27
26
|
const {
|
|
28
|
-
|
|
27
|
+
executeTransfers,
|
|
29
28
|
directTransfers,
|
|
30
29
|
liquidationRemainingFunds,
|
|
31
30
|
phantomTokens,
|
|
@@ -40,7 +39,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
40
39
|
};
|
|
41
40
|
const facadeOps = assembleOperations({
|
|
42
41
|
facadeCalls,
|
|
43
|
-
|
|
42
|
+
executeTransfers,
|
|
44
43
|
register,
|
|
45
44
|
underlying,
|
|
46
45
|
liquidationRemainingFunds,
|
|
@@ -24,7 +24,11 @@ function createLegacyVisitor(params) {
|
|
|
24
24
|
blockNum: ctx.blockNumber,
|
|
25
25
|
timestamp: ctx.timestamp,
|
|
26
26
|
sessionId: params.sessionId,
|
|
27
|
-
protocol
|
|
27
|
+
// `protocol` may be absent (migrator adapter, unknown adapter in
|
|
28
|
+
// non-strict mode, or undecodable calldata). The deprecated charts
|
|
29
|
+
// output still needs an address, so fall back to the on-chain adapter
|
|
30
|
+
// address, which is the closest meaningful value.
|
|
31
|
+
protocol: op.protocol?.contract ?? op.adapter
|
|
28
32
|
};
|
|
29
33
|
},
|
|
30
34
|
IncreaseBorrowedAmount(op, ctx) {
|
|
@@ -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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
56
|
-
*
|
|
59
|
+
* Both the `targetContract` and the protocol calldata are taken from the
|
|
60
|
+
* execution trace.
|
|
57
61
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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(
|
|
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
|
|
90
|
+
const functionArgs = functionArgsToRecord(
|
|
100
91
|
this.protocolAbi,
|
|
101
92
|
decoded.functionName,
|
|
102
93
|
decoded.args
|
|
103
94
|
);
|
|
104
|
-
return {
|
|
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);
|
|
@@ -12,6 +12,15 @@ class AccountMigratorAdapterContract extends AbstractAdapterContract {
|
|
|
12
12
|
`classifyLegacyOperation is not supported for legacy adapter: ${this.contractType}`
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* The account-migrator adapter's `execute` targets the migrator bot, not an
|
|
17
|
+
* external protocol, so there is no protocol-level call to recover. Returning
|
|
18
|
+
* `undefined` keeps the `protocol` field aligned with its external-protocol
|
|
19
|
+
* semantics (see {@link TraceAdapterExt}).
|
|
20
|
+
*/
|
|
21
|
+
parseProtocolCall(_trace, _strict) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
export {
|
|
17
26
|
AccountMigratorAdapterContract
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type": "module","sideEffects":false}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { AbstractAdapterContract } from "../../plugins/adapters/index.js";
|
|
2
|
+
function classifyInnerOperations(calls, props) {
|
|
3
|
+
const { sdk, underlying } = props;
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const call of calls) {
|
|
6
|
+
const contract = sdk.getContract(call.target);
|
|
7
|
+
if (contract instanceof AbstractAdapterContract || contract === void 0) {
|
|
8
|
+
result.push({
|
|
9
|
+
operation: "Execute",
|
|
10
|
+
adapter: call.target,
|
|
11
|
+
adapterType: call.contractType,
|
|
12
|
+
version: call.version,
|
|
13
|
+
label: call.label,
|
|
14
|
+
adapterFunctionName: call.functionName,
|
|
15
|
+
adapterArgs: call.rawArgs
|
|
16
|
+
});
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const op = classifyFacadeInnerCall(call, underlying);
|
|
20
|
+
if (op) {
|
|
21
|
+
result.push(op);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
function classifyFacadeInnerCall(call, underlying) {
|
|
27
|
+
const functionName = call.functionName.split("(")[0];
|
|
28
|
+
const { rawArgs } = call;
|
|
29
|
+
switch (functionName) {
|
|
30
|
+
case "increaseDebt":
|
|
31
|
+
return {
|
|
32
|
+
operation: "IncreaseBorrowedAmount",
|
|
33
|
+
token: underlying,
|
|
34
|
+
amount: rawArgs.amount
|
|
35
|
+
};
|
|
36
|
+
case "decreaseDebt":
|
|
37
|
+
return {
|
|
38
|
+
operation: "DecreaseBorrowedAmount",
|
|
39
|
+
token: underlying,
|
|
40
|
+
amount: rawArgs.amount
|
|
41
|
+
};
|
|
42
|
+
case "addCollateral":
|
|
43
|
+
case "addCollateralWithPermit":
|
|
44
|
+
return {
|
|
45
|
+
operation: "AddCollateral",
|
|
46
|
+
token: rawArgs.token,
|
|
47
|
+
amount: rawArgs.amount
|
|
48
|
+
};
|
|
49
|
+
case "withdrawCollateral":
|
|
50
|
+
return {
|
|
51
|
+
operation: "WithdrawCollateral",
|
|
52
|
+
token: rawArgs.token,
|
|
53
|
+
amount: rawArgs.amount,
|
|
54
|
+
to: rawArgs.to
|
|
55
|
+
};
|
|
56
|
+
case "updateQuota":
|
|
57
|
+
return {
|
|
58
|
+
operation: "UpdateQuota",
|
|
59
|
+
token: rawArgs.token,
|
|
60
|
+
change: rawArgs.quotaChange
|
|
61
|
+
};
|
|
62
|
+
default:
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
classifyInnerOperations
|
|
68
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class UnsupportedTargetError extends Error {
|
|
2
|
+
target;
|
|
3
|
+
constructor(target) {
|
|
4
|
+
super(`unsupported transaction target: ${target}`);
|
|
5
|
+
this.name = "UnsupportedTargetError";
|
|
6
|
+
this.target = target;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class UnsupportedPoolFunctionError extends Error {
|
|
10
|
+
pool;
|
|
11
|
+
functionName;
|
|
12
|
+
constructor(pool, functionName) {
|
|
13
|
+
super(`unsupported pool function "${functionName}" on ${pool}`);
|
|
14
|
+
this.name = "UnsupportedPoolFunctionError";
|
|
15
|
+
this.pool = pool;
|
|
16
|
+
this.functionName = functionName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
UnsupportedPoolFunctionError,
|
|
21
|
+
UnsupportedTargetError
|
|
22
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function extractExpectedBalanceChanges(innerCalls) {
|
|
2
|
+
const calls = innerCalls.filter(
|
|
3
|
+
(call) => functionName(call) !== "onDemandPriceUpdates"
|
|
4
|
+
);
|
|
5
|
+
if (calls.length === 0) {
|
|
6
|
+
return void 0;
|
|
7
|
+
}
|
|
8
|
+
const first = calls[0];
|
|
9
|
+
const last = calls[calls.length - 1];
|
|
10
|
+
if (functionName(first) !== "storeExpectedBalances" || functionName(last) !== "compareBalances") {
|
|
11
|
+
return void 0;
|
|
12
|
+
}
|
|
13
|
+
const balanceDeltas = first.rawArgs.balanceDeltas;
|
|
14
|
+
if (!balanceDeltas) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
return balanceDeltas.map(({ token, amount }) => ({ token, delta: amount }));
|
|
18
|
+
}
|
|
19
|
+
function functionName(call) {
|
|
20
|
+
return call.functionName.split("(")[0];
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
extractExpectedBalanceChanges
|
|
24
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./classifyInnerOperations.js";
|
|
2
|
+
export * from "./errors.js";
|
|
3
|
+
export * from "./extractExpectedBalanceChanges.js";
|
|
4
|
+
export * from "./parseFacadeOperationCalldata.js";
|
|
5
|
+
export * from "./parseOperationCalldata.js";
|
|
6
|
+
export * from "./parsePoolOperationCalldata.js";
|
|
7
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { isAddressEqual, zeroAddress } from "viem";
|
|
2
|
+
import { classifyInnerOperations } from "./classifyInnerOperations.js";
|
|
3
|
+
import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
|
|
4
|
+
function parseFacadeOperationCalldata(props) {
|
|
5
|
+
const { sdk, facade, calldata } = props;
|
|
6
|
+
const parsed = sdk.parseFunctionDataV2(facade.address, calldata);
|
|
7
|
+
const functionName = parsed.functionName.split("(")[0];
|
|
8
|
+
const { rawArgs } = parsed;
|
|
9
|
+
const suite = sdk.marketRegister.creditManagers.find(
|
|
10
|
+
(cm) => isAddressEqual(cm.creditFacade.address, facade.address)
|
|
11
|
+
);
|
|
12
|
+
if (!suite) {
|
|
13
|
+
throw new Error(`no credit suite found for facade ${facade.address}`);
|
|
14
|
+
}
|
|
15
|
+
const metadata = {
|
|
16
|
+
creditManager: suite.creditManager.address,
|
|
17
|
+
creditFacade: facade.address
|
|
18
|
+
};
|
|
19
|
+
const innerCalls = rawArgs.calls ?? [];
|
|
20
|
+
const multicall = classifyInnerOperations(innerCalls, {
|
|
21
|
+
sdk,
|
|
22
|
+
underlying: suite.underlying
|
|
23
|
+
});
|
|
24
|
+
const expectedBalanceChanges = extractExpectedBalanceChanges(innerCalls);
|
|
25
|
+
switch (functionName) {
|
|
26
|
+
case "multicall":
|
|
27
|
+
return {
|
|
28
|
+
...metadata,
|
|
29
|
+
operation: "MultiCall",
|
|
30
|
+
creditAccount: rawArgs.creditAccount,
|
|
31
|
+
multicall,
|
|
32
|
+
expectedBalanceChanges
|
|
33
|
+
};
|
|
34
|
+
case "botMulticall":
|
|
35
|
+
return {
|
|
36
|
+
...metadata,
|
|
37
|
+
operation: "BotMulticall",
|
|
38
|
+
creditAccount: rawArgs.creditAccount,
|
|
39
|
+
multicall,
|
|
40
|
+
expectedBalanceChanges
|
|
41
|
+
};
|
|
42
|
+
case "openCreditAccount":
|
|
43
|
+
return {
|
|
44
|
+
...metadata,
|
|
45
|
+
operation: "OpenCreditAccount",
|
|
46
|
+
creditAccount: zeroAddress,
|
|
47
|
+
onBehalfOf: rawArgs.onBehalfOf,
|
|
48
|
+
referralCode: rawArgs.referralCode,
|
|
49
|
+
multicall,
|
|
50
|
+
expectedBalanceChanges
|
|
51
|
+
};
|
|
52
|
+
case "closeCreditAccount":
|
|
53
|
+
return {
|
|
54
|
+
...metadata,
|
|
55
|
+
operation: "CloseCreditAccount",
|
|
56
|
+
creditAccount: rawArgs.creditAccount,
|
|
57
|
+
multicall,
|
|
58
|
+
expectedBalanceChanges
|
|
59
|
+
};
|
|
60
|
+
case "liquidateCreditAccount":
|
|
61
|
+
return {
|
|
62
|
+
...metadata,
|
|
63
|
+
operation: "LiquidateCreditAccount",
|
|
64
|
+
creditAccount: rawArgs.creditAccount,
|
|
65
|
+
to: rawArgs.to,
|
|
66
|
+
// `token` and `remainingFunds` are only emitted on-chain during
|
|
67
|
+
// liquidation, so they are not recoverable from raw calldata.
|
|
68
|
+
token: zeroAddress,
|
|
69
|
+
remainingFunds: 0n,
|
|
70
|
+
multicall,
|
|
71
|
+
expectedBalanceChanges
|
|
72
|
+
};
|
|
73
|
+
case "partiallyLiquidateCreditAccount":
|
|
74
|
+
return {
|
|
75
|
+
...metadata,
|
|
76
|
+
operation: "PartiallyLiquidateCreditAccount",
|
|
77
|
+
creditAccount: rawArgs.creditAccount,
|
|
78
|
+
token: rawArgs.token,
|
|
79
|
+
repaidAmount: rawArgs.repaidAmount,
|
|
80
|
+
minSeizedAmount: rawArgs.minSeizedAmount,
|
|
81
|
+
to: rawArgs.to
|
|
82
|
+
};
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(
|
|
85
|
+
`unsupported credit facade function "${parsed.functionName}" on ${facade.address}`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
parseFacadeOperationCalldata
|
|
91
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreditFacadeV310Contract,
|
|
3
|
+
PoolV310Contract
|
|
4
|
+
} from "../../sdk/index.js";
|
|
5
|
+
import { UnsupportedTargetError } from "./errors.js";
|
|
6
|
+
import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
|
|
7
|
+
import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
|
|
8
|
+
function parseOperationCalldata(input) {
|
|
9
|
+
const { sdk, to, calldata } = input;
|
|
10
|
+
const contract = sdk.getContract(to);
|
|
11
|
+
if (contract instanceof PoolV310Contract) {
|
|
12
|
+
return parsePoolOperationCalldata({ sdk, pool: contract, calldata });
|
|
13
|
+
}
|
|
14
|
+
if (contract instanceof CreditFacadeV310Contract) {
|
|
15
|
+
return parseFacadeOperationCalldata({
|
|
16
|
+
sdk,
|
|
17
|
+
facade: contract,
|
|
18
|
+
calldata
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
throw new UnsupportedTargetError(to);
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
parseOperationCalldata
|
|
25
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { UnsupportedPoolFunctionError } from "./errors.js";
|
|
2
|
+
function parsePoolOperationCalldata(props) {
|
|
3
|
+
const { sdk, pool, calldata } = props;
|
|
4
|
+
const parsed = sdk.parseFunctionDataV2(pool.address, calldata);
|
|
5
|
+
const functionName = parsed.functionName.split("(")[0];
|
|
6
|
+
const { rawArgs } = parsed;
|
|
7
|
+
const underlying = pool.underlying;
|
|
8
|
+
switch (functionName) {
|
|
9
|
+
case "deposit":
|
|
10
|
+
case "depositWithReferral":
|
|
11
|
+
return {
|
|
12
|
+
operation: "Deposit",
|
|
13
|
+
pool: pool.address,
|
|
14
|
+
receiver: rawArgs.receiver,
|
|
15
|
+
assets: rawArgs.assets,
|
|
16
|
+
underlying,
|
|
17
|
+
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
18
|
+
};
|
|
19
|
+
case "mint":
|
|
20
|
+
case "mintWithReferral":
|
|
21
|
+
return {
|
|
22
|
+
operation: "Mint",
|
|
23
|
+
pool: pool.address,
|
|
24
|
+
receiver: rawArgs.receiver,
|
|
25
|
+
shares: rawArgs.shares,
|
|
26
|
+
underlying,
|
|
27
|
+
referralCode: functionName === "mintWithReferral" ? rawArgs.referralCode : void 0
|
|
28
|
+
};
|
|
29
|
+
case "withdraw":
|
|
30
|
+
return {
|
|
31
|
+
operation: "Withdraw",
|
|
32
|
+
pool: pool.address,
|
|
33
|
+
receiver: rawArgs.receiver,
|
|
34
|
+
owner: rawArgs.owner,
|
|
35
|
+
assets: rawArgs.assets,
|
|
36
|
+
underlying
|
|
37
|
+
};
|
|
38
|
+
case "redeem":
|
|
39
|
+
return {
|
|
40
|
+
operation: "Redeem",
|
|
41
|
+
pool: pool.address,
|
|
42
|
+
receiver: rawArgs.receiver,
|
|
43
|
+
owner: rawArgs.owner,
|
|
44
|
+
shares: rawArgs.shares,
|
|
45
|
+
underlying
|
|
46
|
+
};
|
|
47
|
+
default:
|
|
48
|
+
throw new UnsupportedPoolFunctionError(pool.address, parsed.functionName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
parsePoolOperationCalldata
|
|
53
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types-adapters.js";
|
|
2
|
+
export * from "./types-facades.js";
|
|
3
|
+
export * from "./types-pools.js";
|
|
4
|
+
function isPoolOperation(tx) {
|
|
5
|
+
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
isPoolOperation
|
|
9
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { erc20Abi } from "viem";
|
|
2
|
+
import {
|
|
3
|
+
Prerequisite,
|
|
4
|
+
toPrerequisiteError
|
|
5
|
+
} from "./Prerequisite.js";
|
|
6
|
+
class AllowancePrerequisite extends Prerequisite {
|
|
7
|
+
_id;
|
|
8
|
+
_title;
|
|
9
|
+
_detail;
|
|
10
|
+
constructor(props) {
|
|
11
|
+
super();
|
|
12
|
+
this._id = props.id ?? `allowance:${props.token}:${props.owner}:${props.spender}`;
|
|
13
|
+
this._title = props.title ?? "Token approval";
|
|
14
|
+
this._detail = {
|
|
15
|
+
token: props.token,
|
|
16
|
+
owner: props.owner,
|
|
17
|
+
spender: props.spender,
|
|
18
|
+
required: props.required
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
get id() {
|
|
22
|
+
return this._id;
|
|
23
|
+
}
|
|
24
|
+
get kind() {
|
|
25
|
+
return "allowance";
|
|
26
|
+
}
|
|
27
|
+
get title() {
|
|
28
|
+
return this._title;
|
|
29
|
+
}
|
|
30
|
+
get detail() {
|
|
31
|
+
return this._detail;
|
|
32
|
+
}
|
|
33
|
+
calls() {
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
address: this._detail.token,
|
|
37
|
+
abi: erc20Abi,
|
|
38
|
+
functionName: "allowance",
|
|
39
|
+
args: [this._detail.owner, this._detail.spender]
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
resolve(slice) {
|
|
44
|
+
const res = slice[0];
|
|
45
|
+
if (!res || res.status === "failure") {
|
|
46
|
+
return this.errorResult(toPrerequisiteError(res?.error));
|
|
47
|
+
}
|
|
48
|
+
const actual = res.result;
|
|
49
|
+
return this.satisfiedResult(actual >= this._detail.required, {
|
|
50
|
+
...this._detail,
|
|
51
|
+
actual
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
AllowancePrerequisite
|
|
57
|
+
};
|