@gearbox-protocol/sdk 14.10.10 → 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/isOutOfSyncError.js +1 -3
- 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/permissionless/bindings/pricefeeds/curve-twap.js +2 -2
- 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 +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/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/isOutOfSyncError.js +1 -3
- 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/permissionless/bindings/pricefeeds/curve-twap.js +2 -2
- 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 +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/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 +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 +157 -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
|
@@ -22,14 +22,14 @@ __export(extractTransfers_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(extractTransfers_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
-
var import_generated = require("
|
|
26
|
-
var import_iERC20 = require("
|
|
27
|
-
var import_sdk = require("
|
|
25
|
+
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
+
var import_iERC20 = require("../../abi/iERC20.js");
|
|
27
|
+
var import_sdk = require("../../sdk/index.js");
|
|
28
28
|
var import_errors = require("./errors.js");
|
|
29
29
|
function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
30
30
|
const ranges = buildOperationRanges(logs, creditFacade, creditAccount);
|
|
31
31
|
let currentEntries = [];
|
|
32
|
-
const
|
|
32
|
+
const executeTransfers = [];
|
|
33
33
|
const directTransfers = [];
|
|
34
34
|
const phantomTokens = new import_sdk.AddressMap();
|
|
35
35
|
const withdrawCollateralEvents = [];
|
|
@@ -38,20 +38,17 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
38
38
|
const facadeEvent = tryDecodeFacadeEvent(log, creditFacade);
|
|
39
39
|
if (facadeEvent) {
|
|
40
40
|
if (isExecute(facadeEvent, creditAccount)) {
|
|
41
|
-
|
|
42
|
-
transfers: currentEntries,
|
|
43
|
-
targetContract: facadeEvent.args.targetContract
|
|
44
|
-
});
|
|
41
|
+
executeTransfers.push(currentEntries);
|
|
45
42
|
} else if (isLiquidation(facadeEvent, creditAccount)) {
|
|
46
43
|
liquidationRemainingFunds = facadeEvent.args.remainingFunds;
|
|
47
44
|
} else if (isWithdrawPhantomToken(facadeEvent, creditAccount)) {
|
|
48
|
-
const
|
|
49
|
-
if (!
|
|
45
|
+
const phantomTransfers = executeTransfers.pop();
|
|
46
|
+
if (!phantomTransfers) {
|
|
50
47
|
throw new Error(
|
|
51
48
|
`WithdrawPhantomToken without preceding Execute at logIndex ${facadeEvent.logIndex}`
|
|
52
49
|
);
|
|
53
50
|
}
|
|
54
|
-
const rawDeposit =
|
|
51
|
+
const rawDeposit = phantomTransfers.find(
|
|
55
52
|
(t) => (0, import_viem.isAddressEqual)(t.to, creditAccount)
|
|
56
53
|
);
|
|
57
54
|
if (!rawDeposit) {
|
|
@@ -86,11 +83,11 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
86
83
|
currentEntries.push({ token, amount: value, from, to });
|
|
87
84
|
}
|
|
88
85
|
if ((0, import_viem.isAddressEqual)(to, creditAccount) && !isInRange(log.logIndex, ranges)) {
|
|
89
|
-
directTransfers.push({ token,
|
|
86
|
+
directTransfers.push({ token, amount: value, from, to });
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
89
|
return {
|
|
93
|
-
|
|
90
|
+
executeTransfers,
|
|
94
91
|
directTransfers,
|
|
95
92
|
liquidationRemainingFunds,
|
|
96
93
|
phantomTokens,
|
|
@@ -22,9 +22,9 @@ __export(findFacadeCalls_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(findFacadeCalls_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
|
-
var import_generated = require("
|
|
25
|
+
var import_generated = require("../../abi/310/generated.js");
|
|
26
|
+
var import_trace = require("../../common-utils/utils/trace.js");
|
|
26
27
|
var import_errors = require("./errors.js");
|
|
27
|
-
var import_trace_utils = require("./trace-utils.js");
|
|
28
28
|
const FACADE_CALL_TYPES = {
|
|
29
29
|
multicall: "MultiCall",
|
|
30
30
|
botMulticall: "BotMulticall",
|
|
@@ -48,7 +48,7 @@ function extractCreditAccount(operation, rawArgs, traceOutput) {
|
|
|
48
48
|
return ca;
|
|
49
49
|
}
|
|
50
50
|
function findFacadeCalls(trace, creditFacade, creditAccount, register, strict) {
|
|
51
|
-
const facadeTraces = (0,
|
|
51
|
+
const facadeTraces = (0, import_trace.collectTraces)(trace, creditFacade);
|
|
52
52
|
const results = [];
|
|
53
53
|
for (const trace2 of facadeTraces) {
|
|
54
54
|
const parsed = register.parseFunctionDataV2(
|
|
@@ -0,0 +1,30 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var trace_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(trace_exports);
|
|
18
|
+
__reExport(trace_exports, require("./errors.js"), module.exports);
|
|
19
|
+
__reExport(trace_exports, require("./extractAdapterCallTraces.js"), module.exports);
|
|
20
|
+
__reExport(trace_exports, require("./extractTransfers.js"), module.exports);
|
|
21
|
+
__reExport(trace_exports, require("./findFacadeCalls.js"), module.exports);
|
|
22
|
+
__reExport(trace_exports, require("./types.js"), module.exports);
|
|
23
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
24
|
+
0 && (module.exports = {
|
|
25
|
+
...require("./errors.js"),
|
|
26
|
+
...require("./extractAdapterCallTraces.js"),
|
|
27
|
+
...require("./extractTransfers.js"),
|
|
28
|
+
...require("./findFacadeCalls.js"),
|
|
29
|
+
...require("./types.js")
|
|
30
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -1552,6 +1552,160 @@ class CreditAccountsServiceV310 extends import_base.SDKConstruct {
|
|
|
1552
1552
|
callsWithPrices
|
|
1553
1553
|
);
|
|
1554
1554
|
}
|
|
1555
|
+
/**
|
|
1556
|
+
* {@inheritDoc ICreditAccountsService.prependPriceUpdates}
|
|
1557
|
+
*/
|
|
1558
|
+
async prependPriceUpdates(creditManager, calls, creditAccount, options) {
|
|
1559
|
+
return this.#prependPriceUpdates(
|
|
1560
|
+
creditManager,
|
|
1561
|
+
calls,
|
|
1562
|
+
creditAccount,
|
|
1563
|
+
options
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* {@inheritDoc ICreditAccountsService.assembleCaUpdateCalls}
|
|
1568
|
+
*/
|
|
1569
|
+
assembleCaUpdateCalls({
|
|
1570
|
+
operations,
|
|
1571
|
+
routerCallGroups,
|
|
1572
|
+
creditFacade,
|
|
1573
|
+
withdrawTo,
|
|
1574
|
+
creditAccount,
|
|
1575
|
+
underlyingToken
|
|
1576
|
+
}) {
|
|
1577
|
+
const calls = [];
|
|
1578
|
+
let swapGroupIndex = 0;
|
|
1579
|
+
let routerGroupsConsumed = 0;
|
|
1580
|
+
for (const op of operations) {
|
|
1581
|
+
switch (op.type) {
|
|
1582
|
+
case "increaseDebt":
|
|
1583
|
+
calls.push(this.#prepareIncreaseDebt(creditFacade, op.amount));
|
|
1584
|
+
break;
|
|
1585
|
+
case "decreaseDebt":
|
|
1586
|
+
calls.push(this.#prepareChangeDebt(creditFacade, op.amount, true));
|
|
1587
|
+
break;
|
|
1588
|
+
case "addCollateral":
|
|
1589
|
+
calls.push(
|
|
1590
|
+
...this.#prepareAddCollateral(
|
|
1591
|
+
creditFacade,
|
|
1592
|
+
[{ token: op.token, balance: op.amount }],
|
|
1593
|
+
{}
|
|
1594
|
+
)
|
|
1595
|
+
);
|
|
1596
|
+
break;
|
|
1597
|
+
case "withdrawCollateral":
|
|
1598
|
+
calls.push(
|
|
1599
|
+
this.#prepareWithdrawToken(
|
|
1600
|
+
creditFacade,
|
|
1601
|
+
op.token,
|
|
1602
|
+
op.amount,
|
|
1603
|
+
withdrawTo
|
|
1604
|
+
)
|
|
1605
|
+
);
|
|
1606
|
+
break;
|
|
1607
|
+
case "swap": {
|
|
1608
|
+
const routerCalls = routerCallGroups[swapGroupIndex];
|
|
1609
|
+
if (!routerCalls) {
|
|
1610
|
+
throw new Error(
|
|
1611
|
+
`assembleCaUpdateCalls: missing router calls for swap leg ${swapGroupIndex}`
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
calls.push(...routerCalls);
|
|
1615
|
+
swapGroupIndex += 1;
|
|
1616
|
+
routerGroupsConsumed += 1;
|
|
1617
|
+
break;
|
|
1618
|
+
}
|
|
1619
|
+
case "changeQuota": {
|
|
1620
|
+
const quotaAssets = [...op.quotaIncrease, ...op.quotaDecrease];
|
|
1621
|
+
if (quotaAssets.length === 0) {
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
calls.push(
|
|
1625
|
+
...this.#prepareUpdateQuotas(creditFacade, {
|
|
1626
|
+
averageQuota: quotaAssets,
|
|
1627
|
+
minQuota: quotaAssets
|
|
1628
|
+
})
|
|
1629
|
+
);
|
|
1630
|
+
break;
|
|
1631
|
+
}
|
|
1632
|
+
case "closeCreditAccount": {
|
|
1633
|
+
for (const group of routerCallGroups) {
|
|
1634
|
+
calls.push(...group);
|
|
1635
|
+
routerGroupsConsumed += 1;
|
|
1636
|
+
}
|
|
1637
|
+
calls.push(
|
|
1638
|
+
...this.#prepareDisableQuotas({
|
|
1639
|
+
creditFacade,
|
|
1640
|
+
tokens: Object.entries(creditAccount.initialQuotas).map(
|
|
1641
|
+
([token, { quota }]) => ({
|
|
1642
|
+
token,
|
|
1643
|
+
quota
|
|
1644
|
+
})
|
|
1645
|
+
)
|
|
1646
|
+
})
|
|
1647
|
+
);
|
|
1648
|
+
if (creditAccount.debt > 0n) {
|
|
1649
|
+
calls.push(
|
|
1650
|
+
...this.#prepareDecreaseDebt({
|
|
1651
|
+
creditFacade,
|
|
1652
|
+
debt: creditAccount.debt
|
|
1653
|
+
})
|
|
1654
|
+
);
|
|
1655
|
+
}
|
|
1656
|
+
const hasAssets = creditAccount.assets.some(
|
|
1657
|
+
(asset) => asset.balance > 0n
|
|
1658
|
+
);
|
|
1659
|
+
if (hasAssets) {
|
|
1660
|
+
calls.push(
|
|
1661
|
+
this.#prepareWithdrawToken(
|
|
1662
|
+
creditFacade,
|
|
1663
|
+
underlyingToken,
|
|
1664
|
+
import_constants.MAX_UINT256,
|
|
1665
|
+
withdrawTo
|
|
1666
|
+
)
|
|
1667
|
+
);
|
|
1668
|
+
}
|
|
1669
|
+
break;
|
|
1670
|
+
}
|
|
1671
|
+
default: {
|
|
1672
|
+
const _exhaustive = op;
|
|
1673
|
+
throw new Error(
|
|
1674
|
+
`assembleCaUpdateCalls: unsupported operation ${_exhaustive}`
|
|
1675
|
+
);
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (routerGroupsConsumed !== routerCallGroups.length) {
|
|
1680
|
+
throw new Error(
|
|
1681
|
+
`assembleCaUpdateCalls: router call group mismatch (consumed ${routerGroupsConsumed}, got ${routerCallGroups.length})`
|
|
1682
|
+
);
|
|
1683
|
+
}
|
|
1684
|
+
return calls;
|
|
1685
|
+
}
|
|
1686
|
+
/**
|
|
1687
|
+
* {@inheritDoc ICreditAccountsService.executeCaUpdate}
|
|
1688
|
+
*/
|
|
1689
|
+
async executeCaUpdate(creditAccount, calls, options) {
|
|
1690
|
+
const cm = this.sdk.marketRegister.findCreditManager(
|
|
1691
|
+
creditAccount.creditManager
|
|
1692
|
+
);
|
|
1693
|
+
const callsWithPrices = await this.#prependPriceUpdates(
|
|
1694
|
+
creditAccount.creditManager,
|
|
1695
|
+
calls,
|
|
1696
|
+
creditAccount,
|
|
1697
|
+
{ ignoreReservePrices: options?.ignoreReservePrices }
|
|
1698
|
+
);
|
|
1699
|
+
const tx = await this.#multicallTx(
|
|
1700
|
+
cm,
|
|
1701
|
+
creditAccount.creditAccount,
|
|
1702
|
+
callsWithPrices
|
|
1703
|
+
);
|
|
1704
|
+
if (options?.ethAmount && options.ethAmount > 0n) {
|
|
1705
|
+
tx.value = options.ethAmount.toString(10);
|
|
1706
|
+
}
|
|
1707
|
+
return { tx, calls: callsWithPrices };
|
|
1708
|
+
}
|
|
1555
1709
|
#prepareDisableQuotas(ca) {
|
|
1556
1710
|
const calls = [];
|
|
1557
1711
|
for (const { token, quota } of ca.tokens) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeAbiParameters,
|
|
3
|
+
getAddress,
|
|
4
|
+
isAddressEqual
|
|
5
|
+
} from "viem";
|
|
6
|
+
const EXECUTE_BYTES_SELECTOR = "0x09c5eabe";
|
|
7
|
+
function findExecuteBytes(node) {
|
|
8
|
+
const queue = [node];
|
|
9
|
+
while (queue.length > 0) {
|
|
10
|
+
const current = queue.shift();
|
|
11
|
+
if (current.error) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (current.input.slice(0, 10).toLowerCase() === EXECUTE_BYTES_SELECTOR) {
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
17
|
+
if (current.calls) {
|
|
18
|
+
queue.push(...current.calls);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
function findCallWithInput(node, input) {
|
|
24
|
+
if (node.error) {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
if (node.type === "CALL" && node.input.toLowerCase() === input.toLowerCase()) {
|
|
28
|
+
return node;
|
|
29
|
+
}
|
|
30
|
+
if (node.calls) {
|
|
31
|
+
for (const child of node.calls) {
|
|
32
|
+
const found = findCallWithInput(child, input);
|
|
33
|
+
if (found) {
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
function resolveProtocolCall(node) {
|
|
41
|
+
const executeNode = findExecuteBytes(node);
|
|
42
|
+
if (!executeNode) {
|
|
43
|
+
return void 0;
|
|
44
|
+
}
|
|
45
|
+
const [calldata] = decodeAbiParameters(
|
|
46
|
+
[{ type: "bytes" }],
|
|
47
|
+
`0x${executeNode.input.slice(10)}`
|
|
48
|
+
);
|
|
49
|
+
const targetCall = findCallWithInput(executeNode, calldata);
|
|
50
|
+
if (!targetCall) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
return { contract: getAddress(targetCall.to), calldata };
|
|
54
|
+
}
|
|
55
|
+
function findCallTo(node, target) {
|
|
56
|
+
if (node.error) {
|
|
57
|
+
return void 0;
|
|
58
|
+
}
|
|
59
|
+
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
60
|
+
return node;
|
|
61
|
+
}
|
|
62
|
+
if (node.calls) {
|
|
63
|
+
for (const child of node.calls) {
|
|
64
|
+
const found = findCallTo(child, target);
|
|
65
|
+
if (found) {
|
|
66
|
+
return found;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
function collectTraces(node, target) {
|
|
73
|
+
const results = [];
|
|
74
|
+
if (node.error) {
|
|
75
|
+
return results;
|
|
76
|
+
}
|
|
77
|
+
if (node.type === "CALL" && isAddressEqual(node.to, target)) {
|
|
78
|
+
results.push(node);
|
|
79
|
+
} else if (node.calls) {
|
|
80
|
+
for (const child of node.calls) {
|
|
81
|
+
results.push(...collectTraces(child, target));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
EXECUTE_BYTES_SELECTOR,
|
|
88
|
+
collectTraces,
|
|
89
|
+
findCallTo,
|
|
90
|
+
findCallWithInput,
|
|
91
|
+
findExecuteBytes,
|
|
92
|
+
resolveProtocolCall
|
|
93
|
+
};
|
package/dist/esm/dev/index.js
CHANGED
|
@@ -15,9 +15,7 @@ const OUT_OF_SYNC_PATTERNS = [
|
|
|
15
15
|
// Optimism proxyd (code -32019) for future/non-existent blocks
|
|
16
16
|
/block is out of range/i,
|
|
17
17
|
// EIP-1474 standard (code -32001) when block/state is not available
|
|
18
|
-
/resource not found/i
|
|
19
|
-
// DRPC when a requested block is ahead of the node's latest block
|
|
20
|
-
/greater than latest block/i
|
|
18
|
+
/resource not found/i
|
|
21
19
|
];
|
|
22
20
|
function isOutOfSyncError(e) {
|
|
23
21
|
if (e instanceof BaseError) {
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const ONCHAIN_EXECUTION_ID_ADDRESS = "0x34131bc13eaa4ef5f98c2a423f93bc88d6ee01ba";
|
|
2
|
+
const iOnchainExecutionIdAbi = [
|
|
3
|
+
{
|
|
4
|
+
type: "function",
|
|
5
|
+
name: "deployer",
|
|
6
|
+
inputs: [],
|
|
7
|
+
outputs: [
|
|
8
|
+
{
|
|
9
|
+
name: "",
|
|
10
|
+
type: "string",
|
|
11
|
+
internalType: "string"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
stateMutability: "view"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
name: "executionId",
|
|
19
|
+
inputs: [],
|
|
20
|
+
outputs: [
|
|
21
|
+
{
|
|
22
|
+
name: "",
|
|
23
|
+
type: "string",
|
|
24
|
+
internalType: "string"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
stateMutability: "view"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "function",
|
|
31
|
+
name: "forkAlias",
|
|
32
|
+
inputs: [],
|
|
33
|
+
outputs: [
|
|
34
|
+
{
|
|
35
|
+
name: "",
|
|
36
|
+
type: "string",
|
|
37
|
+
internalType: "string"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
stateMutability: "view"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "function",
|
|
44
|
+
name: "info",
|
|
45
|
+
inputs: [],
|
|
46
|
+
outputs: [
|
|
47
|
+
{
|
|
48
|
+
name: "",
|
|
49
|
+
type: "tuple",
|
|
50
|
+
internalType: "struct ExecutionId.Info",
|
|
51
|
+
components: [
|
|
52
|
+
{
|
|
53
|
+
name: "deployer",
|
|
54
|
+
type: "string",
|
|
55
|
+
internalType: "string"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "executionId",
|
|
59
|
+
type: "string",
|
|
60
|
+
internalType: "string"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "forkAlias",
|
|
64
|
+
type: "string",
|
|
65
|
+
internalType: "string"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
stateMutability: "view"
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
async function verifyTestnet(client, expected) {
|
|
74
|
+
try {
|
|
75
|
+
const { deployer, executionId, forkAlias } = await client.readContract({
|
|
76
|
+
abi: iOnchainExecutionIdAbi,
|
|
77
|
+
address: ONCHAIN_EXECUTION_ID_ADDRESS,
|
|
78
|
+
functionName: "info"
|
|
79
|
+
});
|
|
80
|
+
if (deployer !== "anvil-manager") {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if ("executionId" in expected && expected.executionId && expected.executionId !== executionId) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if ("alias" in expected && expected.alias && expected.alias !== forkAlias) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
} catch {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
ONCHAIN_EXECUTION_ID_ADDRESS,
|
|
96
|
+
iOnchainExecutionIdAbi,
|
|
97
|
+
verifyTestnet
|
|
98
|
+
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { AbstractAdapterContract } from "../plugins/adapters/index.js";
|
|
2
|
+
import {
|
|
3
|
+
extractAdapterCallTraces
|
|
4
|
+
} from "../preview/trace/index.js";
|
|
2
5
|
import { classifyMulticallOperations } from "./classifyMulticallOperations.js";
|
|
3
|
-
import { extractProtocolCalls } from "./extractProtocolCalls.js";
|
|
4
6
|
function assembleOperations(input) {
|
|
5
7
|
const {
|
|
6
8
|
facadeCalls,
|
|
7
|
-
|
|
9
|
+
executeTransfers,
|
|
8
10
|
register,
|
|
9
11
|
underlying,
|
|
10
12
|
liquidationRemainingFunds,
|
|
@@ -19,7 +21,7 @@ function assembleOperations(input) {
|
|
|
19
21
|
return assemblePartialLiquidation(fc);
|
|
20
22
|
}
|
|
21
23
|
const count = countAdapterCalls(fc.innerCalls, register);
|
|
22
|
-
const sliced =
|
|
24
|
+
const sliced = executeTransfers.slice(executeOffset, executeOffset + count);
|
|
23
25
|
executeOffset += count;
|
|
24
26
|
const withdrawCount = countWithdrawCollateralCalls(fc.innerCalls);
|
|
25
27
|
const slicedWithdrawEvents = withdrawCollateralEvents.slice(
|
|
@@ -27,11 +29,11 @@ function assembleOperations(input) {
|
|
|
27
29
|
withdrawOffset + withdrawCount
|
|
28
30
|
);
|
|
29
31
|
withdrawOffset += withdrawCount;
|
|
30
|
-
const
|
|
32
|
+
const adapterTraces = extractAdapterCallTraces(fc.trace);
|
|
31
33
|
const multicall = classifyMulticallOperations({
|
|
32
34
|
innerCalls: fc.innerCalls,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
executeTransfers: sliced,
|
|
36
|
+
adapterTraces,
|
|
35
37
|
register,
|
|
36
38
|
creditAccount: fc.creditAccount,
|
|
37
39
|
underlying,
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
TransferAlignmentError,
|
|
9
9
|
UnknownAdapterError,
|
|
10
10
|
WithdrawCollateralAlignmentError
|
|
11
|
-
} from "
|
|
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,
|