@gearbox-protocol/sdk 14.11.0-next.1 → 14.11.0-next.10
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/index.js +3 -1
- package/dist/cjs/dev/verifyTestnet.js +124 -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 +3 -1
- package/dist/cjs/preview/parse/classifyInnerOperations.js +5 -43
- package/dist/cjs/preview/parse/extractExpectedBalanceChanges.js +48 -0
- package/dist/cjs/preview/parse/index.js +8 -6
- package/dist/cjs/preview/parse/{parseCreditFacadeOperation.js → parseFacadeOperationCalldata.js} +19 -15
- package/dist/cjs/preview/parse/{parseTransaction.js → parseOperationCalldata.js} +10 -10
- package/dist/cjs/preview/parse/{parsePoolOperation.js → parsePoolOperationCalldata.js} +27 -12
- 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 +9 -2
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/cjs/preview/prerequisites/index.js +2 -0
- package/dist/cjs/preview/prerequisites/prepareAction.js +48 -0
- package/dist/cjs/preview/simulate/constants.js +28 -0
- package/dist/cjs/preview/simulate/{decodeSimulationError.js → errors.js} +37 -3
- package/dist/cjs/preview/simulate/holders.js +45 -0
- package/dist/cjs/preview/simulate/index.js +21 -9
- 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 +30 -62
- 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/cjs/rewards/rewards/api.js +4 -2
- package/dist/cjs/rewards/rewards/merkl-api.js +9 -3
- 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/index.js +1 -0
- package/dist/esm/dev/verifyTestnet.js +98 -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/extractExpectedBalanceChanges.js +24 -0
- package/dist/esm/preview/parse/index.js +4 -3
- package/dist/esm/preview/parse/{parseCreditFacadeOperation.js → parseFacadeOperationCalldata.js} +16 -16
- package/dist/esm/preview/parse/{parseTransaction.js → parseOperationCalldata.js} +6 -6
- package/dist/esm/preview/parse/{parsePoolOperation.js → parsePoolOperationCalldata.js} +23 -8
- 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 +4 -1
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +46 -0
- package/dist/esm/preview/prerequisites/index.js +1 -0
- package/dist/esm/preview/prerequisites/prepareAction.js +23 -0
- package/dist/esm/preview/simulate/constants.js +4 -0
- package/dist/esm/preview/simulate/{decodeSimulationError.js → errors.js} +31 -0
- package/dist/esm/preview/simulate/holders.js +21 -0
- package/dist/esm/preview/simulate/index.js +12 -4
- 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 +33 -62
- 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/esm/rewards/rewards/api.js +4 -2
- package/dist/esm/rewards/rewards/merkl-api.js +9 -3
- 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/index.d.ts +1 -0
- package/dist/types/dev/verifyTestnet.d.ts +82 -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/extractExpectedBalanceChanges.d.ts +22 -0
- package/dist/types/preview/parse/index.d.ts +4 -3
- package/dist/types/preview/parse/parseFacadeOperationCalldata.d.ts +19 -0
- package/dist/types/preview/parse/{parseTransaction.d.ts → parseOperationCalldata.d.ts} +4 -4
- 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 +157 -0
- package/dist/types/preview/parse/types-pools.d.ts +55 -0
- package/dist/types/preview/parse/types.d.ts +16 -50
- package/dist/types/preview/prerequisites/buildPrerequisites.d.ts +3 -3
- package/dist/types/preview/prerequisites/index.d.ts +1 -0
- package/dist/types/preview/prerequisites/prepareAction.d.ts +52 -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 +1 -1
- package/dist/types/preview/simulate/holders.d.ts +7 -0
- package/dist/types/preview/simulate/index.d.ts +9 -4
- 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 +5 -27
- package/dist/types/preview/simulate/types.d.ts +54 -18
- 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/rewards/rewards/api.d.ts +2 -1
- package/dist/types/rewards/rewards/merkl-api.d.ts +2 -1
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +21 -1
- package/dist/types/sdk/accounts/types.d.ts +82 -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/types/preview/parse/parseCreditFacadeOperation.d.ts +0 -18
- package/dist/types/preview/parse/parsePoolOperation.d.ts +0 -15
- package/dist/types/preview/simulate/decodeSimulationError.d.ts +0 -18
- /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,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
|
|
@@ -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
|
};
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./classifyInnerOperations.js";
|
|
2
2
|
export * from "./errors.js";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
3
|
+
export * from "./extractExpectedBalanceChanges.js";
|
|
4
|
+
export * from "./parseFacadeOperationCalldata.js";
|
|
5
|
+
export * from "./parseOperationCalldata.js";
|
|
6
|
+
export * from "./parsePoolOperationCalldata.js";
|
|
6
7
|
export * from "./types.js";
|
package/dist/esm/preview/parse/{parseCreditFacadeOperation.js → parseFacadeOperationCalldata.js}
RENAMED
|
@@ -1,10 +1,7 @@
|
|
|
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
|
+
import { extractExpectedBalanceChanges } from "./extractExpectedBalanceChanges.js";
|
|
4
|
+
function parseFacadeOperationCalldata(props) {
|
|
8
5
|
const { sdk, facade, calldata } = props;
|
|
9
6
|
const parsed = sdk.parseFunctionDataV2(facade.address, calldata);
|
|
10
7
|
const functionName = parsed.functionName.split("(")[0];
|
|
@@ -17,30 +14,30 @@ function parseCreditFacadeOperation(props) {
|
|
|
17
14
|
}
|
|
18
15
|
const metadata = {
|
|
19
16
|
creditManager: suite.creditManager.address,
|
|
20
|
-
creditFacade: facade.address
|
|
21
|
-
blockNumber: Number(sdk.currentBlock),
|
|
22
|
-
txHash: zeroHash,
|
|
23
|
-
timestamp: 0
|
|
17
|
+
creditFacade: facade.address
|
|
24
18
|
};
|
|
25
19
|
const innerCalls = rawArgs.calls ?? [];
|
|
26
20
|
const multicall = classifyInnerOperations(innerCalls, {
|
|
27
21
|
sdk,
|
|
28
22
|
underlying: suite.underlying
|
|
29
23
|
});
|
|
24
|
+
const expectedBalanceChanges = extractExpectedBalanceChanges(innerCalls);
|
|
30
25
|
switch (functionName) {
|
|
31
26
|
case "multicall":
|
|
32
27
|
return {
|
|
33
28
|
...metadata,
|
|
34
29
|
operation: "MultiCall",
|
|
35
30
|
creditAccount: rawArgs.creditAccount,
|
|
36
|
-
multicall
|
|
31
|
+
multicall,
|
|
32
|
+
expectedBalanceChanges
|
|
37
33
|
};
|
|
38
34
|
case "botMulticall":
|
|
39
35
|
return {
|
|
40
36
|
...metadata,
|
|
41
37
|
operation: "BotMulticall",
|
|
42
38
|
creditAccount: rawArgs.creditAccount,
|
|
43
|
-
multicall
|
|
39
|
+
multicall,
|
|
40
|
+
expectedBalanceChanges
|
|
44
41
|
};
|
|
45
42
|
case "openCreditAccount":
|
|
46
43
|
return {
|
|
@@ -49,14 +46,16 @@ function parseCreditFacadeOperation(props) {
|
|
|
49
46
|
creditAccount: zeroAddress,
|
|
50
47
|
onBehalfOf: rawArgs.onBehalfOf,
|
|
51
48
|
referralCode: rawArgs.referralCode,
|
|
52
|
-
multicall
|
|
49
|
+
multicall,
|
|
50
|
+
expectedBalanceChanges
|
|
53
51
|
};
|
|
54
52
|
case "closeCreditAccount":
|
|
55
53
|
return {
|
|
56
54
|
...metadata,
|
|
57
55
|
operation: "CloseCreditAccount",
|
|
58
56
|
creditAccount: rawArgs.creditAccount,
|
|
59
|
-
multicall
|
|
57
|
+
multicall,
|
|
58
|
+
expectedBalanceChanges
|
|
60
59
|
};
|
|
61
60
|
case "liquidateCreditAccount":
|
|
62
61
|
return {
|
|
@@ -68,7 +67,8 @@ function parseCreditFacadeOperation(props) {
|
|
|
68
67
|
// liquidation, so they are not recoverable from raw calldata.
|
|
69
68
|
token: zeroAddress,
|
|
70
69
|
remainingFunds: 0n,
|
|
71
|
-
multicall
|
|
70
|
+
multicall,
|
|
71
|
+
expectedBalanceChanges
|
|
72
72
|
};
|
|
73
73
|
case "partiallyLiquidateCreditAccount":
|
|
74
74
|
return {
|
|
@@ -87,5 +87,5 @@ function parseCreditFacadeOperation(props) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
export {
|
|
90
|
-
|
|
90
|
+
parseFacadeOperationCalldata
|
|
91
91
|
};
|
|
@@ -3,16 +3,16 @@ import {
|
|
|
3
3
|
PoolV310Contract
|
|
4
4
|
} from "../../sdk/index.js";
|
|
5
5
|
import { UnsupportedTargetError } from "./errors.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
function
|
|
6
|
+
import { parseFacadeOperationCalldata } from "./parseFacadeOperationCalldata.js";
|
|
7
|
+
import { parsePoolOperationCalldata } from "./parsePoolOperationCalldata.js";
|
|
8
|
+
function parseOperationCalldata(input) {
|
|
9
9
|
const { sdk, to, calldata } = input;
|
|
10
10
|
const contract = sdk.getContract(to);
|
|
11
11
|
if (contract instanceof PoolV310Contract) {
|
|
12
|
-
return
|
|
12
|
+
return parsePoolOperationCalldata({ sdk, pool: contract, calldata });
|
|
13
13
|
}
|
|
14
14
|
if (contract instanceof CreditFacadeV310Contract) {
|
|
15
|
-
return
|
|
15
|
+
return parseFacadeOperationCalldata({
|
|
16
16
|
sdk,
|
|
17
17
|
facade: contract,
|
|
18
18
|
calldata
|
|
@@ -21,5 +21,5 @@ function parseTransaction(input) {
|
|
|
21
21
|
throw new UnsupportedTargetError(to);
|
|
22
22
|
}
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
parseOperationCalldata
|
|
25
25
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsupportedPoolFunctionError } from "./errors.js";
|
|
2
|
-
function
|
|
2
|
+
function parsePoolOperationCalldata(props) {
|
|
3
3
|
const { sdk, pool, calldata } = props;
|
|
4
4
|
const parsed = sdk.parseFunctionDataV2(pool.address, calldata);
|
|
5
5
|
const functionName = parsed.functionName.split("(")[0];
|
|
@@ -14,9 +14,26 @@ function parsePoolOperation(props) {
|
|
|
14
14
|
receiver: rawArgs.receiver,
|
|
15
15
|
assets: rawArgs.assets,
|
|
16
16
|
underlying,
|
|
17
|
-
referralCode: functionName === "depositWithReferral" ? rawArgs.referralCode : void 0
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
20
37
|
};
|
|
21
38
|
case "redeem":
|
|
22
39
|
return {
|
|
@@ -25,14 +42,12 @@ function parsePoolOperation(props) {
|
|
|
25
42
|
receiver: rawArgs.receiver,
|
|
26
43
|
owner: rawArgs.owner,
|
|
27
44
|
shares: rawArgs.shares,
|
|
28
|
-
underlying
|
|
29
|
-
// Calldata-only parse: transfers are recovered later by simulation.
|
|
30
|
-
transfers: []
|
|
45
|
+
underlying
|
|
31
46
|
};
|
|
32
47
|
default:
|
|
33
48
|
throw new UnsupportedPoolFunctionError(pool.address, parsed.functionName);
|
|
34
49
|
}
|
|
35
50
|
}
|
|
36
51
|
export {
|
|
37
|
-
|
|
52
|
+
parsePoolOperationCalldata
|
|
38
53
|
};
|
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export * from "./types-adapters.js";
|
|
2
|
+
export * from "./types-facades.js";
|
|
3
|
+
export * from "./types-pools.js";
|
|
1
4
|
function isPoolOperation(tx) {
|
|
2
|
-
return tx.operation === "Deposit" || tx.operation === "Redeem";
|
|
5
|
+
return tx.operation === "Deposit" || tx.operation === "Mint" || tx.operation === "Withdraw" || tx.operation === "Redeem";
|
|
3
6
|
}
|
|
4
7
|
export {
|
|
5
8
|
isPoolOperation
|
|
@@ -4,6 +4,12 @@ import { BalancePrerequisite } from "./BalancePrerequisite.js";
|
|
|
4
4
|
function buildPrerequisites(tx, ctx) {
|
|
5
5
|
const { wallet } = ctx;
|
|
6
6
|
switch (tx.operation) {
|
|
7
|
+
// Deposit and Mint both pull the underlying from the caller into the pool;
|
|
8
|
+
// they only differ in which side (assets vs shares) the caller specifies.
|
|
9
|
+
// The exact underlying amount for Mint is resolved by the pool, so we can
|
|
10
|
+
// only require an allowance/balance against the known specified amount —
|
|
11
|
+
// here we approximate Mint by its shares amount (a lower bound on assets is
|
|
12
|
+
// not knowable from calldata alone).
|
|
7
13
|
case "Deposit":
|
|
8
14
|
return [
|
|
9
15
|
new AllowancePrerequisite({
|
|
@@ -20,6 +26,24 @@ function buildPrerequisites(tx, ctx) {
|
|
|
20
26
|
title: "Sufficient token balance"
|
|
21
27
|
})
|
|
22
28
|
];
|
|
29
|
+
case "Mint":
|
|
30
|
+
return [
|
|
31
|
+
new AllowancePrerequisite({
|
|
32
|
+
token: tx.underlying,
|
|
33
|
+
owner: wallet,
|
|
34
|
+
spender: tx.pool,
|
|
35
|
+
required: tx.shares,
|
|
36
|
+
title: "Token approved to pool"
|
|
37
|
+
}),
|
|
38
|
+
new BalancePrerequisite({
|
|
39
|
+
token: tx.underlying,
|
|
40
|
+
owner: wallet,
|
|
41
|
+
required: tx.shares,
|
|
42
|
+
title: "Sufficient token balance"
|
|
43
|
+
})
|
|
44
|
+
];
|
|
45
|
+
// Redeem and Withdraw both burn LP shares from `owner`; they only differ in
|
|
46
|
+
// which side (shares vs assets) the caller specifies.
|
|
23
47
|
case "Redeem": {
|
|
24
48
|
const prereqs = [
|
|
25
49
|
new BalancePrerequisite({
|
|
@@ -42,6 +66,28 @@ function buildPrerequisites(tx, ctx) {
|
|
|
42
66
|
}
|
|
43
67
|
return prereqs;
|
|
44
68
|
}
|
|
69
|
+
case "Withdraw": {
|
|
70
|
+
const prereqs = [
|
|
71
|
+
new BalancePrerequisite({
|
|
72
|
+
token: tx.pool,
|
|
73
|
+
owner: tx.owner,
|
|
74
|
+
required: tx.assets,
|
|
75
|
+
title: "Sufficient LP token balance"
|
|
76
|
+
})
|
|
77
|
+
];
|
|
78
|
+
if (!isAddressEqual(tx.owner, wallet)) {
|
|
79
|
+
prereqs.push(
|
|
80
|
+
new AllowancePrerequisite({
|
|
81
|
+
token: tx.pool,
|
|
82
|
+
owner: tx.owner,
|
|
83
|
+
spender: wallet,
|
|
84
|
+
required: tx.assets,
|
|
85
|
+
title: "LP token approved to caller"
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return prereqs;
|
|
90
|
+
}
|
|
45
91
|
case "MultiCall":
|
|
46
92
|
case "BotMulticall":
|
|
47
93
|
case "OpenCreditAccount":
|
|
@@ -2,5 +2,6 @@ export * from "./AllowancePrerequisite.js";
|
|
|
2
2
|
export * from "./BalancePrerequisite.js";
|
|
3
3
|
export * from "./buildPrerequisites.js";
|
|
4
4
|
export * from "./Prerequisite.js";
|
|
5
|
+
export * from "./prepareAction.js";
|
|
5
6
|
export * from "./runPrerequisites.js";
|
|
6
7
|
export * from "./types.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { encodeFunctionData, erc20Abi } from "viem";
|
|
2
|
+
function preparePrerequisiteAction(result) {
|
|
3
|
+
if (result.kind === "allowance" && result.satisfied === false) {
|
|
4
|
+
const { token, spender, required } = result.detail;
|
|
5
|
+
return {
|
|
6
|
+
kind: "allowance",
|
|
7
|
+
to: token,
|
|
8
|
+
data: encodeFunctionData({
|
|
9
|
+
abi: erc20Abi,
|
|
10
|
+
functionName: "approve",
|
|
11
|
+
args: [spender, required]
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
function isActionablePrerequisite(result) {
|
|
18
|
+
return preparePrerequisiteAction(result) !== null;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
isActionablePrerequisite,
|
|
22
|
+
preparePrerequisiteAction
|
|
23
|
+
};
|
|
@@ -4,6 +4,34 @@ import {
|
|
|
4
4
|
decodeErrorResult
|
|
5
5
|
} from "viem";
|
|
6
6
|
import { errorAbis } from "../../abi/errors.js";
|
|
7
|
+
class PreviewSimulationError extends BaseError {
|
|
8
|
+
name = "PreviewSimulationError";
|
|
9
|
+
/** Per-flow decoded failures behind this error. */
|
|
10
|
+
failures;
|
|
11
|
+
constructor(failures) {
|
|
12
|
+
const shortMessage = failures.length <= 1 ? failures[0]?.detail.reason ?? "simulation failed" : "all simulation flows failed";
|
|
13
|
+
const cause = failures.find((f) => f.detail.cause instanceof Error)?.detail.cause;
|
|
14
|
+
super(shortMessage, {
|
|
15
|
+
metaMessages: failures.map((f) => `[${f.source}] ${f.detail.reason}`),
|
|
16
|
+
cause
|
|
17
|
+
});
|
|
18
|
+
this.failures = failures;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function asPreviewSimulationError(reason, source) {
|
|
22
|
+
if (reason instanceof PreviewSimulationError) {
|
|
23
|
+
return reason;
|
|
24
|
+
}
|
|
25
|
+
const error = reason instanceof Error ? reason : new Error(String(reason));
|
|
26
|
+
return new PreviewSimulationError([
|
|
27
|
+
{ source, detail: decodeSimulationError({ error }) }
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
function combinePreviewSimulationErrors(...errors) {
|
|
31
|
+
return new PreviewSimulationError(
|
|
32
|
+
errors.filter((e) => e).flatMap((e) => e?.failures ?? [])
|
|
33
|
+
);
|
|
34
|
+
}
|
|
7
35
|
function decodeSimulationError(revert) {
|
|
8
36
|
const { error, data } = revert;
|
|
9
37
|
if (data && data !== "0x") {
|
|
@@ -40,5 +68,8 @@ function formatDecodedError(errorName, args) {
|
|
|
40
68
|
return `${errorName}(${args.map((arg) => String(arg)).join(", ")})`;
|
|
41
69
|
}
|
|
42
70
|
export {
|
|
71
|
+
PreviewSimulationError,
|
|
72
|
+
asPreviewSimulationError,
|
|
73
|
+
combinePreviewSimulationErrors,
|
|
43
74
|
decodeSimulationError
|
|
44
75
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AddressSet } from "../../sdk/index.js";
|
|
2
|
+
function sourceHolder(operation, wallet) {
|
|
3
|
+
switch (operation.operation) {
|
|
4
|
+
case "Deposit":
|
|
5
|
+
case "Mint":
|
|
6
|
+
return wallet;
|
|
7
|
+
case "Withdraw":
|
|
8
|
+
case "Redeem":
|
|
9
|
+
return operation.owner;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function watchedHolders(operation, wallet) {
|
|
13
|
+
const holders = new AddressSet([
|
|
14
|
+
sourceHolder(operation, wallet),
|
|
15
|
+
operation.receiver
|
|
16
|
+
]);
|
|
17
|
+
return holders.asArray();
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
watchedHolders
|
|
21
|
+
};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { ETH_SIMULATE_V1_NETWORKS } from "./constants.js";
|
|
2
|
+
import { PreviewSimulationError } from "./errors.js";
|
|
3
|
+
import { simulateFacadeOperation } from "./simulateFacadeOperation.js";
|
|
4
|
+
import { simulateOperation } from "./simulateOperation.js";
|
|
5
|
+
import { simulatePoolOperation } from "./simulatePoolOperation.js";
|
|
6
|
+
export {
|
|
7
|
+
ETH_SIMULATE_V1_NETWORKS,
|
|
8
|
+
PreviewSimulationError,
|
|
9
|
+
simulateFacadeOperation,
|
|
10
|
+
simulateOperation,
|
|
11
|
+
simulatePoolOperation
|
|
12
|
+
};
|