@gearbox-protocol/sdk 14.11.0-next.4 → 14.11.0-next.6
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/extractExpectedBalanceChanges.js +48 -0
- package/dist/cjs/preview/parse/index.js +2 -0
- package/dist/cjs/preview/parse/parseFacadeOperationCalldata.js +13 -9
- 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/extractExpectedBalanceChanges.js +24 -0
- package/dist/esm/preview/parse/index.js +1 -0
- package/dist/esm/preview/parse/parseFacadeOperationCalldata.js +14 -14
- 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/extractExpectedBalanceChanges.d.ts +22 -0
- package/dist/types/preview/parse/index.d.ts +1 -0
- 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 +157 -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
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { Address, Hex } from "viem";
|
|
2
|
+
import type { AdapterOperation } from "./types-adapters.js";
|
|
3
|
+
/**
|
|
4
|
+
* Increase debt (borrow more).
|
|
5
|
+
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L149-L154
|
|
6
|
+
*/
|
|
7
|
+
export interface IncreaseDebtOp {
|
|
8
|
+
operation: "IncreaseBorrowedAmount";
|
|
9
|
+
token: Address;
|
|
10
|
+
amount: bigint;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Decrease debt (repay).
|
|
14
|
+
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L155-L161
|
|
15
|
+
*/
|
|
16
|
+
export interface DecreaseDebtOp {
|
|
17
|
+
operation: "DecreaseBorrowedAmount";
|
|
18
|
+
token: Address;
|
|
19
|
+
amount: bigint;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Add collateral to credit account.
|
|
23
|
+
*/
|
|
24
|
+
export interface AddCollateralOp {
|
|
25
|
+
operation: "AddCollateral";
|
|
26
|
+
token: Address;
|
|
27
|
+
amount: bigint;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Withdraw collateral from credit account.
|
|
31
|
+
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L162-L171
|
|
32
|
+
*/
|
|
33
|
+
export interface WithdrawCollateralOp {
|
|
34
|
+
operation: "WithdrawCollateral";
|
|
35
|
+
token: Address;
|
|
36
|
+
amount: bigint;
|
|
37
|
+
to: Address;
|
|
38
|
+
phantomToken?: Address;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Update token quota on credit account.
|
|
42
|
+
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L172-L178
|
|
43
|
+
*/
|
|
44
|
+
export interface UpdateQuotaOp {
|
|
45
|
+
operation: "UpdateQuota";
|
|
46
|
+
token: Address;
|
|
47
|
+
change: bigint;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Union of facade inner-call operation types (non-adapter credit account operations).
|
|
51
|
+
* Discriminated on the `operation` field.
|
|
52
|
+
*/
|
|
53
|
+
export type InnerFacadeOperation = IncreaseDebtOp | DecreaseDebtOp | AddCollateralOp | WithdrawCollateralOp | UpdateQuotaOp;
|
|
54
|
+
/**
|
|
55
|
+
* All operations that can happen within a CreditFacade's multicall and that we're interested in.
|
|
56
|
+
*
|
|
57
|
+
* Generic over the adapter-operation extension `Ext` (see {@link AdapterOperation}).
|
|
58
|
+
*/
|
|
59
|
+
export type InnerOperation<Ext extends object = {}> = AdapterOperation<Ext> | InnerFacadeOperation;
|
|
60
|
+
/**
|
|
61
|
+
* Transaction-level metadata available only when parsing a mined transaction
|
|
62
|
+
* (the `history` mode). It is intentionally absent from base `preview`
|
|
63
|
+
* operations, which describe not-yet-mined calls where these values are unknown.
|
|
64
|
+
*/
|
|
65
|
+
export interface OperationMetadata {
|
|
66
|
+
txHash: Hex;
|
|
67
|
+
blockNumber: number;
|
|
68
|
+
timestamp: number;
|
|
69
|
+
}
|
|
70
|
+
export interface FacadeOperationMetadata {
|
|
71
|
+
creditManager: Address;
|
|
72
|
+
creditFacade: Address;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Signed token balance delta recovered from a router-generated
|
|
76
|
+
* `storeExpectedBalances` call (the `BalanceDelta` struct). `amount` is the
|
|
77
|
+
* signed `int256` delta, so it may be negative.
|
|
78
|
+
*/
|
|
79
|
+
export interface ExpectedBalanceChange {
|
|
80
|
+
token: Address;
|
|
81
|
+
delta: bigint;
|
|
82
|
+
}
|
|
83
|
+
export interface MulticallOperation<Ext extends object = {}> extends FacadeOperationMetadata {
|
|
84
|
+
operation: "MultiCall" | "BotMulticall";
|
|
85
|
+
creditAccount: Address;
|
|
86
|
+
multicall: InnerOperation<Ext>[];
|
|
87
|
+
/**
|
|
88
|
+
* Potential balance changes declared by a router-generated
|
|
89
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
90
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
91
|
+
*/
|
|
92
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
93
|
+
}
|
|
94
|
+
export interface OpenCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
|
|
95
|
+
operation: "OpenCreditAccount";
|
|
96
|
+
creditAccount: Address;
|
|
97
|
+
onBehalfOf: Address;
|
|
98
|
+
referralCode: bigint;
|
|
99
|
+
multicall: InnerOperation<Ext>[];
|
|
100
|
+
/**
|
|
101
|
+
* Potential balance changes declared by a router-generated
|
|
102
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
103
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
104
|
+
*/
|
|
105
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
106
|
+
}
|
|
107
|
+
export interface CloseCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
|
|
108
|
+
operation: "CloseCreditAccount";
|
|
109
|
+
creditAccount: Address;
|
|
110
|
+
multicall: InnerOperation<Ext>[];
|
|
111
|
+
/**
|
|
112
|
+
* Potential balance changes declared by a router-generated
|
|
113
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
114
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
115
|
+
*/
|
|
116
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
117
|
+
}
|
|
118
|
+
export interface LiquidateCreditAccountOperation<Ext extends object = {}> extends FacadeOperationMetadata {
|
|
119
|
+
operation: "LiquidateCreditAccount";
|
|
120
|
+
creditAccount: Address;
|
|
121
|
+
to: Address;
|
|
122
|
+
token: Address;
|
|
123
|
+
remainingFunds: bigint;
|
|
124
|
+
multicall: InnerOperation<Ext>[];
|
|
125
|
+
/**
|
|
126
|
+
* Potential balance changes declared by a router-generated
|
|
127
|
+
* `storeExpectedBalances`/`compareBalances` pair, or `undefined` when the
|
|
128
|
+
* multicall is not router-shaped. See {@link ExpectedBalanceChange}.
|
|
129
|
+
*/
|
|
130
|
+
expectedBalanceChanges?: ExpectedBalanceChange[];
|
|
131
|
+
}
|
|
132
|
+
export interface PartialLiquidationOperation extends FacadeOperationMetadata {
|
|
133
|
+
operation: "PartiallyLiquidateCreditAccount";
|
|
134
|
+
creditAccount: Address;
|
|
135
|
+
token: Address;
|
|
136
|
+
repaidAmount: bigint;
|
|
137
|
+
minSeizedAmount: bigint;
|
|
138
|
+
to: Address;
|
|
139
|
+
}
|
|
140
|
+
export interface DirectTokenTransferOperation {
|
|
141
|
+
operation: "DirectTokenTransfer";
|
|
142
|
+
protocol: Address;
|
|
143
|
+
token: Address;
|
|
144
|
+
from: Address;
|
|
145
|
+
creditAccount: Address;
|
|
146
|
+
amount: bigint;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Discriminated union of all facade-level operation types.
|
|
150
|
+
* One per facade entry-point call within a transaction.
|
|
151
|
+
*/
|
|
152
|
+
export type OuterFacadeOperation<Ext extends object = {}> = MulticallOperation<Ext> | OpenCreditAccountOperation<Ext> | CloseCreditAccountOperation<Ext> | LiquidateCreditAccountOperation<Ext> | PartialLiquidationOperation;
|
|
153
|
+
/**
|
|
154
|
+
* Discriminated union of all credit account operation types
|
|
155
|
+
* (facade operations + direct token transfers).
|
|
156
|
+
*/
|
|
157
|
+
export type CreditAccountOperation<Ext extends object = {}> = OuterFacadeOperation<Ext> | DirectTokenTransferOperation;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { TokenTransfer } from "./types-adapters.js";
|
|
3
|
+
/**
|
|
4
|
+
* ERC4626 `deposit` into a Gearbox pool.
|
|
5
|
+
* Token metadata (symbol/decimals) is intentionally omitted: consumers resolve
|
|
6
|
+
* it from `sdk.tokensMeta` using the token addresses below.
|
|
7
|
+
*/
|
|
8
|
+
export interface PoolDepositOperation {
|
|
9
|
+
operation: "Deposit";
|
|
10
|
+
pool: Address;
|
|
11
|
+
receiver: Address;
|
|
12
|
+
/** Underlying assets supplied to the pool. */
|
|
13
|
+
assets: bigint;
|
|
14
|
+
underlying: Address;
|
|
15
|
+
/** Referral code, present only for `depositWithReferral` calls. */
|
|
16
|
+
referralCode?: bigint;
|
|
17
|
+
/**
|
|
18
|
+
* ERC-20 transfers involving the wallet, recovered by simulating the call.
|
|
19
|
+
* Empty for the calldata-only parse; populated by the simulation stage.
|
|
20
|
+
*/
|
|
21
|
+
transfers: TokenTransfer[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* ERC4626 `redeem` from a Gearbox pool.
|
|
25
|
+
* Token metadata (symbol/decimals) is intentionally omitted: consumers resolve
|
|
26
|
+
* it from `sdk.tokensMeta` using the token addresses below.
|
|
27
|
+
*/
|
|
28
|
+
export interface PoolRedeemOperation {
|
|
29
|
+
operation: "Redeem";
|
|
30
|
+
pool: Address;
|
|
31
|
+
receiver: Address;
|
|
32
|
+
owner: Address;
|
|
33
|
+
/** Pool shares (diesel) burned. */
|
|
34
|
+
shares: bigint;
|
|
35
|
+
underlying: Address;
|
|
36
|
+
/**
|
|
37
|
+
* ERC-20 transfers involving the wallet, recovered by simulating the call.
|
|
38
|
+
* Empty for the calldata-only parse; populated by the simulation stage.
|
|
39
|
+
*/
|
|
40
|
+
transfers: TokenTransfer[];
|
|
41
|
+
}
|
|
42
|
+
export type PoolOperation = PoolDepositOperation | PoolRedeemOperation;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { OuterFacadeOperation } from "../../history/index.js";
|
|
3
|
-
import type { AdaptersPlugin, TokenTransfer } from "../../plugins/adapters/index.js";
|
|
1
|
+
import type { AdaptersPlugin } from "../../plugins/adapters/index.js";
|
|
4
2
|
import type { OnchainSDK, PluginsMap } from "../../sdk/index.js";
|
|
3
|
+
import type { OuterFacadeOperation } from "./types-facades.js";
|
|
4
|
+
import type { PoolOperation } from "./types-pools.js";
|
|
5
|
+
export * from "./types-adapters.js";
|
|
6
|
+
export * from "./types-facades.js";
|
|
7
|
+
export * from "./types-pools.js";
|
|
5
8
|
/**
|
|
6
9
|
* True when the plugin map `P` contains the {@link AdaptersPlugin} under any
|
|
7
10
|
* key. Matched nominally (the plugin's private fields make it non-structural),
|
|
@@ -26,53 +29,16 @@ export type RequireAdaptersPlugin<P extends PluginsMap> = HasAdaptersPlugin<P> e
|
|
|
26
29
|
*/
|
|
27
30
|
export type SdkWithAdapters<P extends PluginsMap = PluginsMap> = OnchainSDK<P> & RequireAdaptersPlugin<P>;
|
|
28
31
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
operation: "Deposit";
|
|
35
|
-
pool: Address;
|
|
36
|
-
receiver: Address;
|
|
37
|
-
/** Underlying assets supplied to the pool. */
|
|
38
|
-
assets: bigint;
|
|
39
|
-
underlying: Address;
|
|
40
|
-
/** Referral code, present only for `depositWithReferral` calls. */
|
|
41
|
-
referralCode?: bigint;
|
|
42
|
-
/**
|
|
43
|
-
* ERC-20 transfers involving the wallet, recovered by simulating the call.
|
|
44
|
-
* Empty for the calldata-only parse; populated by the simulation stage.
|
|
45
|
-
*/
|
|
46
|
-
transfers: TokenTransfer[];
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* ERC4626 `redeem` from a Gearbox pool.
|
|
50
|
-
* Token metadata (symbol/decimals) is intentionally omitted: consumers resolve
|
|
51
|
-
* it from `sdk.tokensMeta` using the token addresses below.
|
|
32
|
+
* Result of decoding a single raw operation calldata: either a pool
|
|
33
|
+
* deposit/redeem or one of the credit-facade operations.
|
|
34
|
+
*
|
|
35
|
+
* Calldata-only parse produces base (descriptor) adapter operations, so the
|
|
36
|
+
* facade operations are used with the default `Ext = {}`.
|
|
52
37
|
*/
|
|
53
|
-
export
|
|
54
|
-
operation: "Redeem";
|
|
55
|
-
pool: Address;
|
|
56
|
-
receiver: Address;
|
|
57
|
-
owner: Address;
|
|
58
|
-
/** Pool shares (diesel) burned. */
|
|
59
|
-
shares: bigint;
|
|
60
|
-
underlying: Address;
|
|
61
|
-
/**
|
|
62
|
-
* ERC-20 transfers involving the wallet, recovered by simulating the call.
|
|
63
|
-
* Empty for the calldata-only parse; populated by the simulation stage.
|
|
64
|
-
*/
|
|
65
|
-
transfers: TokenTransfer[];
|
|
66
|
-
}
|
|
67
|
-
export type PoolOperation = PoolDepositOperation | PoolRedeemOperation;
|
|
38
|
+
export type Operation = PoolOperation | OuterFacadeOperation;
|
|
68
39
|
/**
|
|
69
40
|
* Narrows an {@link Operation} to a {@link PoolOperation} (deposit or redeem).
|
|
70
41
|
* Used by the UI to decide whether a custom view exists for the parsed result;
|
|
71
42
|
* everything else falls back to the raw JSON view.
|
|
72
43
|
*/
|
|
73
44
|
export declare function isPoolOperation(tx: Operation): tx is PoolOperation;
|
|
74
|
-
/**
|
|
75
|
-
* Result of decoding a single raw operation calldata: either a pool
|
|
76
|
-
* deposit/redeem or one of the credit-facade operations from `sdk/history`.
|
|
77
|
-
*/
|
|
78
|
-
export type Operation = PoolOperation | OuterFacadeOperation;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Address, type Log } from "viem";
|
|
2
|
-
import type { TokenTransfer } from "
|
|
2
|
+
import type { TokenTransfer } from "../parse/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Parses ERC-20 `Transfer` logs and keeps only those involving one of the
|
|
5
5
|
* watched addresses (as sender or receiver). A log that touches several watched
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Address, Hex } from "viem";
|
|
2
|
-
import type { OuterFacadeOperation } from "../../history/index.js";
|
|
3
2
|
import type { OnchainSDK } from "../../sdk/index.js";
|
|
3
|
+
import type { OuterFacadeOperation } from "../parse/index.js";
|
|
4
4
|
import type { PoolSimulationResult } from "./types.js";
|
|
5
5
|
export interface SimulateFacadeOperationInput {
|
|
6
6
|
/** Only `client` is used, so any OnchainSDK works. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
|
-
import type { TokenTransfer } from "
|
|
2
|
+
import type { TokenTransfer } from "../parse/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Change in an address's balance of a single token over the simulated call.
|
|
5
5
|
* `delta` is `after - before` (negative when the address spent the token).
|
|
@@ -9,16 +9,6 @@ export declare class TransferAlignmentError extends Error {
|
|
|
9
9
|
export declare class WithdrawCollateralAlignmentError extends Error {
|
|
10
10
|
constructor(expected: number, actual: number);
|
|
11
11
|
}
|
|
12
|
-
export declare class ProtocolCallNotFoundError extends Error {
|
|
13
|
-
readonly targetContract: Address;
|
|
14
|
-
readonly executeIndex: number;
|
|
15
|
-
constructor(targetContract: Address, executeIndex: number);
|
|
16
|
-
}
|
|
17
|
-
export declare class AdapterTraceAlignmentError extends Error {
|
|
18
|
-
readonly expected: number;
|
|
19
|
-
readonly actual: number;
|
|
20
|
-
constructor(expected: number, actual: number);
|
|
21
|
-
}
|
|
22
12
|
export declare class UnexpectedFacadeEventOrderError extends Error {
|
|
23
13
|
constructor(e: {
|
|
24
14
|
eventName: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type CallTrace } from "../../common-utils/utils/trace.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the user multicall's adapter-level call traces from a single facade
|
|
4
|
+
* call trace.
|
|
5
|
+
*
|
|
6
|
+
* Returns the direct children of the facade trace that perform an external
|
|
7
|
+
* protocol call (their subtree resolves to a `CreditManager.execute(bytes)`
|
|
8
|
+
* that reaches a leaf CALL to a target contract), in trace order.
|
|
9
|
+
*
|
|
10
|
+
* Scoping to direct children of the facade trace (rather than flattening the
|
|
11
|
+
* whole subtree) avoids over-counting in nested credit-manager scenarios such
|
|
12
|
+
* as account migration, where a single migrate-adapter subtree nests another
|
|
13
|
+
* account's `execute(bytes)` calls.
|
|
14
|
+
*
|
|
15
|
+
* Facade-synthesized phantom-token withdrawals are excluded: while processing
|
|
16
|
+
* `withdrawCollateral` on a phantom token the facade issues its own
|
|
17
|
+
* `withdrawPhantomToken` adapter call, which also reaches an external target
|
|
18
|
+
* but does not correspond to a user multicall inner call. These are detected
|
|
19
|
+
* via the preceding `getPhantomTokenInfo()` probe (see
|
|
20
|
+
* {@link isSynthesizedPhantomWithdrawal}), so the returned traces line up 1:1,
|
|
21
|
+
* in order, with the multicall's adapter inner calls.
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractAdapterCallTraces(facadeTrace: CallTrace): CallTrace[];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Address, type Log } from "viem";
|
|
2
|
-
import { AddressMap } from "
|
|
3
|
-
import type {
|
|
4
|
-
import type { DirectTransferInfo } from "./types.js";
|
|
2
|
+
import { AddressMap } from "../../sdk/index.js";
|
|
3
|
+
import type { TokenTransfer } from "../parse/index.js";
|
|
5
4
|
type RawLog = Log<bigint | number, number, false>;
|
|
6
5
|
/**
|
|
7
6
|
* Effective `withdrawCollateral` outcome decoded from the facade's
|
|
@@ -25,8 +24,18 @@ export interface WithdrawCollateralEventInfo {
|
|
|
25
24
|
* @param creditAccount - the credit account address to track
|
|
26
25
|
*/
|
|
27
26
|
export interface ExtractTransfersResult {
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* ERC-20 transfers grouped per facade `Execute` event, one inner array per
|
|
29
|
+
* Execute event across the whole transaction, in emission order. Each inner
|
|
30
|
+
* array holds the transfers to/from the credit account that occurred between
|
|
31
|
+
* that Execute boundary and the previous one.
|
|
32
|
+
*/
|
|
33
|
+
executeTransfers: TokenTransfer[][];
|
|
34
|
+
/**
|
|
35
|
+
* ERC-20 transfers that are not part of a facade `Execute` event and are
|
|
36
|
+
* direct incoming transfers to the credit account.
|
|
37
|
+
*/
|
|
38
|
+
directTransfers: TokenTransfer[];
|
|
30
39
|
liquidationRemainingFunds?: bigint;
|
|
31
40
|
/** Maps phantom token address to its deposited (underlying) token address. */
|
|
32
41
|
phantomTokens: AddressMap<Address>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Address } from "viem";
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
2
|
+
import { type CallTrace } from "../../common-utils/utils/trace.js";
|
|
3
|
+
import type { ChainContractsRegister } from "../../sdk/index.js";
|
|
4
|
+
import type { FacadeParsedCall } from "./types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Walks a `debug_traceTransaction` callTracer tree, finds all non-reverted
|
|
6
7
|
* calls to the credit facade, parses them via the register, and returns
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CallTrace } from "../../common-utils/utils/trace.js";
|
|
3
|
+
import type { ParsedCallV2 } from "../../sdk/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* The set of credit facade entry-point functions that produce history operations.
|
|
6
|
+
*/
|
|
7
|
+
export type FacadeCallType = "MultiCall" | "BotMulticall" | "OpenCreditAccount" | "CloseCreditAccount" | "LiquidateCreditAccount" | "PartiallyLiquidateCreditAccount";
|
|
8
|
+
/**
|
|
9
|
+
* A parsed credit facade call extracted from a call trace,
|
|
10
|
+
* with inner multicall calls already decoded.
|
|
11
|
+
*/
|
|
12
|
+
export interface FacadeParsedCall {
|
|
13
|
+
operation: FacadeCallType;
|
|
14
|
+
creditAccount: Address;
|
|
15
|
+
/** The full ParsedCallV2 from facade calldata parsing. */
|
|
16
|
+
parsed: ParsedCallV2;
|
|
17
|
+
/** Inner multicall entries from rawArgs.calls (empty for partiallyLiquidateCreditAccount). */
|
|
18
|
+
innerCalls: ParsedCallV2[];
|
|
19
|
+
/** The full call trace node for this facade call (used to extract protocol-level calldata). */
|
|
20
|
+
trace: CallTrace;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var extractProtocolCalls_exports = {};
|
|
20
|
-
__export(extractProtocolCalls_exports, {
|
|
21
|
-
extractProtocolCalls: () => extractProtocolCalls
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(extractProtocolCalls_exports);
|
|
24
|
-
var import_errors = require("./errors.js");
|
|
25
|
-
var import_trace_utils = require("./trace-utils.js");
|
|
26
|
-
function extractProtocolCalls(facadeTrace, executeResults) {
|
|
27
|
-
if (executeResults.length === 0) {
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
const subtraces = facadeTrace.calls ?? [];
|
|
31
|
-
const result = [];
|
|
32
|
-
let subtraceIdx = 0;
|
|
33
|
-
for (let i = 0; i < executeResults.length; i++) {
|
|
34
|
-
const { targetContract } = executeResults[i];
|
|
35
|
-
let found;
|
|
36
|
-
while (subtraceIdx < subtraces.length && !found) {
|
|
37
|
-
found = (0, import_trace_utils.findCallTo)(subtraces[subtraceIdx], targetContract);
|
|
38
|
-
subtraceIdx++;
|
|
39
|
-
}
|
|
40
|
-
if (!found) {
|
|
41
|
-
throw new import_errors.ProtocolCallNotFoundError(targetContract, i);
|
|
42
|
-
}
|
|
43
|
-
result.push(found.input);
|
|
44
|
-
}
|
|
45
|
-
if (result.length !== executeResults.length) {
|
|
46
|
-
throw new import_errors.AdapterTraceAlignmentError(executeResults.length, result.length);
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
-
0 && (module.exports = {
|
|
52
|
-
extractProtocolCalls
|
|
53
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AdapterTraceAlignmentError,
|
|
3
|
-
ProtocolCallNotFoundError
|
|
4
|
-
} from "./errors.js";
|
|
5
|
-
import { findCallTo } from "./trace-utils.js";
|
|
6
|
-
function extractProtocolCalls(facadeTrace, executeResults) {
|
|
7
|
-
if (executeResults.length === 0) {
|
|
8
|
-
return [];
|
|
9
|
-
}
|
|
10
|
-
const subtraces = facadeTrace.calls ?? [];
|
|
11
|
-
const result = [];
|
|
12
|
-
let subtraceIdx = 0;
|
|
13
|
-
for (let i = 0; i < executeResults.length; i++) {
|
|
14
|
-
const { targetContract } = executeResults[i];
|
|
15
|
-
let found;
|
|
16
|
-
while (subtraceIdx < subtraces.length && !found) {
|
|
17
|
-
found = findCallTo(subtraces[subtraceIdx], targetContract);
|
|
18
|
-
subtraceIdx++;
|
|
19
|
-
}
|
|
20
|
-
if (!found) {
|
|
21
|
-
throw new ProtocolCallNotFoundError(targetContract, i);
|
|
22
|
-
}
|
|
23
|
-
result.push(found.input);
|
|
24
|
-
}
|
|
25
|
-
if (result.length !== executeResults.length) {
|
|
26
|
-
throw new AdapterTraceAlignmentError(executeResults.length, result.length);
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
extractProtocolCalls
|
|
32
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { isAddressEqual } from "viem";
|
|
2
|
-
function findCallTo(node, target) {
|
|
3
|
-
if (node.error) {
|
|
4
|
-
return void 0;
|
|
5
|
-
}
|
|
6
|
-
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
7
|
-
return node;
|
|
8
|
-
}
|
|
9
|
-
if (node.calls) {
|
|
10
|
-
for (const child of node.calls) {
|
|
11
|
-
const found = findCallTo(child, target);
|
|
12
|
-
if (found) {
|
|
13
|
-
return found;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return void 0;
|
|
18
|
-
}
|
|
19
|
-
function collectTraces(node, target) {
|
|
20
|
-
const results = [];
|
|
21
|
-
if (node.error) {
|
|
22
|
-
return results;
|
|
23
|
-
}
|
|
24
|
-
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
25
|
-
results.push(node);
|
|
26
|
-
} else if (node.calls) {
|
|
27
|
-
for (const child of node.calls) {
|
|
28
|
-
results.push(...collectTraces(child, target));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return results;
|
|
32
|
-
}
|
|
33
|
-
export {
|
|
34
|
-
collectTraces,
|
|
35
|
-
findCallTo
|
|
36
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Hex } from "viem";
|
|
2
|
-
import type { CallTrace, ExecuteResult } from "./internal-types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Extracts calldata sent to target contract for each Execute event.
|
|
5
|
-
*
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare function extractProtocolCalls(facadeTrace: CallTrace, executeResults: ExecuteResult[]): Hex[];
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { AdapterOperation } from "../plugins/adapters/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Increase debt (borrow more).
|
|
5
|
-
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L149-L154
|
|
6
|
-
*/
|
|
7
|
-
export interface IncreaseDebtOp {
|
|
8
|
-
operation: "IncreaseBorrowedAmount";
|
|
9
|
-
token: Address;
|
|
10
|
-
amount: bigint;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Decrease debt (repay).
|
|
14
|
-
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L155-L161
|
|
15
|
-
*/
|
|
16
|
-
export interface DecreaseDebtOp {
|
|
17
|
-
operation: "DecreaseBorrowedAmount";
|
|
18
|
-
token: Address;
|
|
19
|
-
amount: bigint;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Add collateral to credit account.
|
|
23
|
-
*/
|
|
24
|
-
export interface AddCollateralOp {
|
|
25
|
-
operation: "AddCollateral";
|
|
26
|
-
token: Address;
|
|
27
|
-
amount: bigint;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Withdraw collateral from credit account.
|
|
31
|
-
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L162-L171
|
|
32
|
-
*/
|
|
33
|
-
export interface WithdrawCollateralOp {
|
|
34
|
-
operation: "WithdrawCollateral";
|
|
35
|
-
token: Address;
|
|
36
|
-
amount: bigint;
|
|
37
|
-
to: Address;
|
|
38
|
-
phantomToken?: Address;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Update token quota on credit account.
|
|
42
|
-
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L172-L178
|
|
43
|
-
*/
|
|
44
|
-
export interface UpdateQuotaOp {
|
|
45
|
-
operation: "UpdateQuota";
|
|
46
|
-
token: Address;
|
|
47
|
-
change: bigint;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Union of facade inner-call operation types (non-adapter credit account operations).
|
|
51
|
-
* Discriminated on the `operation` field.
|
|
52
|
-
*/
|
|
53
|
-
export type InnerFacadeOperation = IncreaseDebtOp | DecreaseDebtOp | AddCollateralOp | WithdrawCollateralOp | UpdateQuotaOp;
|
|
54
|
-
/**
|
|
55
|
-
* All operations that can happen within a CreditFacade's multicall and that we're interested in.
|
|
56
|
-
*/
|
|
57
|
-
export type InnerOperation = AdapterOperation | InnerFacadeOperation;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Address, Hex } from "viem";
|
|
2
|
-
import type { TokenTransfer } from "../plugins/adapters/index.js";
|
|
3
|
-
import type { ParsedCallV2 } from "../sdk/index.js";
|
|
4
|
-
/**
|
|
5
|
-
* A single frame from Ethereum's `debug_traceTransaction` callTracer output.
|
|
6
|
-
* Recursive: each frame may contain nested sub-calls.
|
|
7
|
-
*/
|
|
8
|
-
export interface CallTrace {
|
|
9
|
-
from: Address;
|
|
10
|
-
to: Address;
|
|
11
|
-
input: Hex;
|
|
12
|
-
output: Hex;
|
|
13
|
-
value: Hex;
|
|
14
|
-
/** "CALL", "DELEGATECALL", "STATICCALL", "CREATE", etc. */
|
|
15
|
-
type: string;
|
|
16
|
-
/** Present when the call reverted (e.g. "execution reverted"). */
|
|
17
|
-
error?: string;
|
|
18
|
-
/** ABI-encoded revert data, if available. */
|
|
19
|
-
revertReason?: Hex;
|
|
20
|
-
calls?: CallTrace[];
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* The set of credit facade entry-point functions that produce history operations.
|
|
24
|
-
*/
|
|
25
|
-
export type FacadeCallType = "MultiCall" | "BotMulticall" | "OpenCreditAccount" | "CloseCreditAccount" | "LiquidateCreditAccount" | "PartiallyLiquidateCreditAccount";
|
|
26
|
-
/**
|
|
27
|
-
* A parsed credit facade call extracted from a call trace,
|
|
28
|
-
* with inner multicall calls already decoded.
|
|
29
|
-
*/
|
|
30
|
-
export interface FacadeParsedCall {
|
|
31
|
-
operation: FacadeCallType;
|
|
32
|
-
creditAccount: Address;
|
|
33
|
-
/** The full ParsedCallV2 from facade calldata parsing. */
|
|
34
|
-
parsed: ParsedCallV2;
|
|
35
|
-
/** Inner multicall entries from rawArgs.calls (empty for partiallyLiquidateCreditAccount). */
|
|
36
|
-
innerCalls: ParsedCallV2[];
|
|
37
|
-
/** The full call trace node for this facade call (used to extract protocol-level calldata). */
|
|
38
|
-
trace: CallTrace;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Data extracted from a single Execute event: the ERC-20 transfers that
|
|
42
|
-
* occurred between Execute boundaries and the target contract address.
|
|
43
|
-
*/
|
|
44
|
-
export interface ExecuteResult {
|
|
45
|
-
transfers: TokenTransfer[];
|
|
46
|
-
targetContract: Address;
|
|
47
|
-
}
|