@gearbox-protocol/sdk 14.12.0-next.7 → 14.12.0-next.8
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/plugins/adapters/abi/iConvexV1BoosterAdapter.js +143 -0
- package/dist/cjs/plugins/adapters/abi/index.js +2 -0
- package/dist/cjs/plugins/adapters/balanceChanges.js +47 -0
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +35 -0
- package/dist/cjs/plugins/adapters/contracts/BalancerV3RouterAdapterContract.js +20 -0
- package/dist/cjs/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.js +20 -0
- package/dist/cjs/plugins/adapters/contracts/CamelotV3AdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.js +23 -0
- package/dist/cjs/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.js +29 -2
- package/dist/cjs/plugins/adapters/contracts/Curve2AssetsAdapterContract.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/Curve3AssetsAdapterContract.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/Curve4AssetsAdapterContract.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/CurveV1AdapterDeposit.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/CurveV1AdapterStETHContract.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/CurveV1StableNGAdapterContract.js +27 -0
- package/dist/cjs/plugins/adapters/contracts/DaiUsdsAdapterContract.js +15 -0
- package/dist/cjs/plugins/adapters/contracts/ERC4626AdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/contracts/ERC4626ReferralAdapterContract.js +15 -0
- package/dist/cjs/plugins/adapters/contracts/FluidDexAdapterContract.js +15 -0
- package/dist/cjs/plugins/adapters/contracts/InfinifiGatewayAdapterContract.js +22 -0
- package/dist/cjs/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.js +11 -0
- package/dist/cjs/plugins/adapters/contracts/LidoV1AdapterContract.js +12 -0
- package/dist/cjs/plugins/adapters/contracts/MellowDVVAdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/contracts/MellowWrapperAdapterContract.js +12 -0
- package/dist/cjs/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +11 -0
- package/dist/cjs/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +13 -0
- package/dist/cjs/plugins/adapters/contracts/PendleRouterAdapterContract.js +53 -0
- package/dist/cjs/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.js +12 -0
- package/dist/cjs/plugins/adapters/contracts/SecuritizeSwapAdapterContract.js +23 -1
- package/dist/cjs/plugins/adapters/contracts/StakingRewardsAdapterContract.js +22 -0
- package/dist/cjs/plugins/adapters/contracts/TraderJoeRouterAdapterContract.js +11 -0
- package/dist/cjs/plugins/adapters/contracts/UniswapV2AdapterContract.js +11 -0
- package/dist/cjs/plugins/adapters/contracts/UniswapV3AdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/contracts/UniswapV4AdapterContract.js +15 -0
- package/dist/cjs/plugins/adapters/contracts/UpshiftVaultAdapterContract.js +15 -0
- package/dist/cjs/plugins/adapters/contracts/VelodromeV2AdapterContract.js +11 -0
- package/dist/cjs/plugins/adapters/contracts/WstETHV1AdapterContract.js +16 -0
- package/dist/cjs/plugins/adapters/index.js +2 -0
- package/dist/cjs/preview/preview/errors.js +16 -0
- package/dist/cjs/preview/preview/extractExpectedBalanceChanges.js +33 -11
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +46 -7
- package/dist/cjs/preview/preview/unwrapNativeCollateral.js +59 -0
- package/dist/cjs/sdk/market/credit/CreditFacadeV310BaseContract.js +31 -0
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +25 -0
- package/dist/esm/plugins/adapters/abi/iConvexV1BoosterAdapter.js +119 -0
- package/dist/esm/plugins/adapters/abi/index.js +1 -0
- package/dist/esm/plugins/adapters/balanceChanges.js +21 -0
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +35 -0
- package/dist/esm/plugins/adapters/contracts/BalancerV3RouterAdapterContract.js +23 -1
- package/dist/esm/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.js +23 -1
- package/dist/esm/plugins/adapters/contracts/CamelotV3AdapterContract.js +19 -1
- package/dist/esm/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.js +27 -1
- package/dist/esm/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.js +31 -2
- package/dist/esm/plugins/adapters/contracts/Curve2AssetsAdapterContract.js +30 -1
- package/dist/esm/plugins/adapters/contracts/Curve3AssetsAdapterContract.js +30 -1
- package/dist/esm/plugins/adapters/contracts/Curve4AssetsAdapterContract.js +30 -1
- package/dist/esm/plugins/adapters/contracts/CurveV1AdapterDeposit.js +30 -1
- package/dist/esm/plugins/adapters/contracts/CurveV1AdapterStETHContract.js +30 -1
- package/dist/esm/plugins/adapters/contracts/CurveV1StableNGAdapterContract.js +30 -1
- package/dist/esm/plugins/adapters/contracts/DaiUsdsAdapterContract.js +18 -1
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +20 -1
- package/dist/esm/plugins/adapters/contracts/ERC4626ReferralAdapterContract.js +18 -1
- package/dist/esm/plugins/adapters/contracts/FluidDexAdapterContract.js +18 -1
- package/dist/esm/plugins/adapters/contracts/InfinifiGatewayAdapterContract.js +25 -1
- package/dist/esm/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.js +14 -1
- package/dist/esm/plugins/adapters/contracts/LidoV1AdapterContract.js +15 -1
- package/dist/esm/plugins/adapters/contracts/MellowDVVAdapterContract.js +19 -1
- package/dist/esm/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.js +19 -1
- package/dist/esm/plugins/adapters/contracts/MellowWrapperAdapterContract.js +15 -1
- package/dist/esm/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +14 -1
- package/dist/esm/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +16 -1
- package/dist/esm/plugins/adapters/contracts/PendleRouterAdapterContract.js +56 -1
- package/dist/esm/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.js +15 -1
- package/dist/esm/plugins/adapters/contracts/SecuritizeSwapAdapterContract.js +26 -2
- package/dist/esm/plugins/adapters/contracts/StakingRewardsAdapterContract.js +25 -1
- package/dist/esm/plugins/adapters/contracts/TraderJoeRouterAdapterContract.js +14 -1
- package/dist/esm/plugins/adapters/contracts/UniswapV2AdapterContract.js +11 -0
- package/dist/esm/plugins/adapters/contracts/UniswapV3AdapterContract.js +16 -0
- package/dist/esm/plugins/adapters/contracts/UniswapV4AdapterContract.js +18 -1
- package/dist/esm/plugins/adapters/contracts/UpshiftVaultAdapterContract.js +18 -1
- package/dist/esm/plugins/adapters/contracts/VelodromeV2AdapterContract.js +14 -1
- package/dist/esm/plugins/adapters/contracts/WstETHV1AdapterContract.js +19 -1
- package/dist/esm/plugins/adapters/index.js +1 -0
- package/dist/esm/preview/preview/errors.js +15 -0
- package/dist/esm/preview/preview/extractExpectedBalanceChanges.js +33 -11
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +54 -8
- package/dist/esm/preview/preview/unwrapNativeCollateral.js +35 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +33 -0
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +27 -1
- package/dist/types/plugins/adapters/abi/iConvexV1BoosterAdapter.d.ts +204 -0
- package/dist/types/plugins/adapters/abi/index.d.ts +1 -0
- package/dist/types/plugins/adapters/balanceChanges.d.ts +21 -0
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +22 -2
- package/dist/types/plugins/adapters/contracts/BalancerV3RouterAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/CamelotV3AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +7 -6
- package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +3 -1
- package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/FluidDexAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/InfinifiGatewayAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/MellowWrapperAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/PendleRouterAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/SecuritizeSwapAdapterContract.d.ts +14 -3
- package/dist/types/plugins/adapters/contracts/StakingRewardsAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/TraderJoeRouterAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/UniswapV2AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/UniswapV3AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/UniswapV4AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/UpshiftVaultAdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/VelodromeV2AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +3 -2
- package/dist/types/plugins/adapters/index.d.ts +1 -0
- package/dist/types/preview/preview/errors.d.ts +12 -0
- package/dist/types/preview/preview/extractExpectedBalanceChanges.d.ts +26 -14
- package/dist/types/preview/preview/types.d.ts +5 -1
- package/dist/types/preview/preview/unwrapNativeCollateral.d.ts +20 -0
- package/dist/types/sdk/market/credit/CreditFacadeV310BaseContract.d.ts +13 -1
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +13 -1
- package/package.json +1 -1
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(UniswapV4AdapterContract_exports);
|
|
|
24
24
|
var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_sdk = require("../../../sdk/index.js");
|
|
27
|
+
var import_balanceChanges = require("../balanceChanges.js");
|
|
27
28
|
var import_transferHelpers = require("../transferHelpers.js");
|
|
28
29
|
var import_AbstractAdapter = require("./AbstractAdapter.js");
|
|
29
30
|
const abi = import_integrations_v3.iUniswapV4AdapterAbi;
|
|
@@ -81,6 +82,20 @@ class UniswapV4AdapterContract extends import_AbstractAdapter.AbstractAdapterCon
|
|
|
81
82
|
classifyLegacyOperation(_parsed, transfers) {
|
|
82
83
|
return { operation: "UniswapSwap", ...(0, import_transferHelpers.swapFromTransfers)(transfers) };
|
|
83
84
|
}
|
|
85
|
+
previewDecodedBalanceChanges(balances, decoded) {
|
|
86
|
+
switch (decoded.functionName) {
|
|
87
|
+
case "swapExactInputSingleDiff": {
|
|
88
|
+
const [poolKey, zeroForOne, leftoverAmount] = decoded.args;
|
|
89
|
+
return (0, import_balanceChanges.clampToLeftover)(
|
|
90
|
+
balances,
|
|
91
|
+
zeroForOne ? poolKey.token0 : poolKey.token1,
|
|
92
|
+
leftoverAmount
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
return super.previewDecodedBalanceChanges(balances, decoded);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
84
99
|
}
|
|
85
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
101
|
0 && (module.exports = {
|
|
@@ -24,6 +24,7 @@ module.exports = __toCommonJS(UpshiftVaultAdapterContract_exports);
|
|
|
24
24
|
var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_sdk = require("../../../sdk/index.js");
|
|
27
|
+
var import_balanceChanges = require("../balanceChanges.js");
|
|
27
28
|
var import_AbstractAdapter = require("./AbstractAdapter.js");
|
|
28
29
|
const abi = import_integrations_v3.iUpshiftVaultAdapterAbi;
|
|
29
30
|
const protocolAbi = import_integrations_v3.iUpshiftVaultGatewayAbi;
|
|
@@ -70,6 +71,20 @@ class UpshiftVaultAdapterContract extends import_AbstractAdapter.AbstractAdapter
|
|
|
70
71
|
stakedPhantomToken: this.#stakedPhantomToken ? this.labelAddress(this.#stakedPhantomToken) : void 0
|
|
71
72
|
};
|
|
72
73
|
}
|
|
74
|
+
previewDecodedBalanceChanges(balances, decoded) {
|
|
75
|
+
switch (decoded.functionName) {
|
|
76
|
+
case "depositDiff": {
|
|
77
|
+
const [leftoverAmount] = decoded.args;
|
|
78
|
+
return (0, import_balanceChanges.clampToLeftover)(balances, this.asset, leftoverAmount);
|
|
79
|
+
}
|
|
80
|
+
case "redeemDiff": {
|
|
81
|
+
const [leftoverAmount] = decoded.args;
|
|
82
|
+
return (0, import_balanceChanges.clampToLeftover)(balances, this.vault, leftoverAmount);
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return super.previewDecodedBalanceChanges(balances, decoded);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
73
88
|
}
|
|
74
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
90
|
0 && (module.exports = {
|
|
@@ -25,6 +25,7 @@ var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_sdk = require("../../../sdk/index.js");
|
|
27
27
|
var import_targetContractAbi = require("../abi/targetContractAbi.js");
|
|
28
|
+
var import_balanceChanges = require("../balanceChanges.js");
|
|
28
29
|
var import_AbstractAdapter = require("./AbstractAdapter.js");
|
|
29
30
|
const abi = import_integrations_v3.iVelodromeV2RouterAdapterAbi;
|
|
30
31
|
const protocolAbi = import_targetContractAbi.iVelodromeV2RouterAbi;
|
|
@@ -74,6 +75,16 @@ class VelodromeV2RouterAdapterContract extends import_AbstractAdapter.AbstractAd
|
|
|
74
75
|
}))
|
|
75
76
|
};
|
|
76
77
|
}
|
|
78
|
+
previewDecodedBalanceChanges(balances, decoded) {
|
|
79
|
+
switch (decoded.functionName) {
|
|
80
|
+
case "swapDiffTokensForTokens": {
|
|
81
|
+
const [leftoverAmount, , routes] = decoded.args;
|
|
82
|
+
return (0, import_balanceChanges.clampToLeftover)(balances, routes[0].from, leftoverAmount);
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
return super.previewDecodedBalanceChanges(balances, decoded);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
90
|
0 && (module.exports = {
|
|
@@ -25,6 +25,7 @@ var import_integrations_v3 = require("@gearbox-protocol/integrations-v3");
|
|
|
25
25
|
var import_viem = require("viem");
|
|
26
26
|
var import_sdk = require("../../../sdk/index.js");
|
|
27
27
|
var import_targetContractAbi = require("../abi/targetContractAbi.js");
|
|
28
|
+
var import_balanceChanges = require("../balanceChanges.js");
|
|
28
29
|
var import_transferHelpers = require("../transferHelpers.js");
|
|
29
30
|
var import_AbstractAdapter = require("./AbstractAdapter.js");
|
|
30
31
|
const abi = import_integrations_v3.iwstEthv1AdapterAbi;
|
|
@@ -65,6 +66,21 @@ class WstETHV1AdapterContract extends import_AbstractAdapter.AbstractAdapterCont
|
|
|
65
66
|
}
|
|
66
67
|
return super.classifyLegacyOperation(parsed, transfers);
|
|
67
68
|
}
|
|
69
|
+
previewDecodedBalanceChanges(balances, decoded) {
|
|
70
|
+
switch (decoded.functionName) {
|
|
71
|
+
case "wrapDiff": {
|
|
72
|
+
const [leftoverAmount] = decoded.args;
|
|
73
|
+
return (0, import_balanceChanges.clampToLeftover)(balances, this.stETH, leftoverAmount);
|
|
74
|
+
}
|
|
75
|
+
// wstETH is the adapter's target contract
|
|
76
|
+
case "unwrapDiff": {
|
|
77
|
+
const [leftoverAmount] = decoded.args;
|
|
78
|
+
return (0, import_balanceChanges.clampToLeftover)(balances, this.targetContract, leftoverAmount);
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
return super.previewDecodedBalanceChanges(balances, decoded);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
68
84
|
}
|
|
69
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
86
|
0 && (module.exports = {
|
|
@@ -17,6 +17,7 @@ var adapters_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(adapters_exports);
|
|
18
18
|
__reExport(adapters_exports, require("./AdaptersPlugin.js"), module.exports);
|
|
19
19
|
__reExport(adapters_exports, require("./abi/index.js"), module.exports);
|
|
20
|
+
__reExport(adapters_exports, require("./balanceChanges.js"), module.exports);
|
|
20
21
|
__reExport(adapters_exports, require("./contracts/index.js"), module.exports);
|
|
21
22
|
__reExport(adapters_exports, require("./createAdapter.js"), module.exports);
|
|
22
23
|
__reExport(adapters_exports, require("./legacyAdapterOperations.js"), module.exports);
|
|
@@ -26,6 +27,7 @@ __reExport(adapters_exports, require("./types.js"), module.exports);
|
|
|
26
27
|
0 && (module.exports = {
|
|
27
28
|
...require("./AdaptersPlugin.js"),
|
|
28
29
|
...require("./abi/index.js"),
|
|
30
|
+
...require("./balanceChanges.js"),
|
|
29
31
|
...require("./contracts/index.js"),
|
|
30
32
|
...require("./createAdapter.js"),
|
|
31
33
|
...require("./legacyAdapterOperations.js"),
|
|
@@ -18,9 +18,24 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var errors_exports = {};
|
|
20
20
|
__export(errors_exports, {
|
|
21
|
+
InvalidTransactionValueError: () => InvalidTransactionValueError,
|
|
21
22
|
UnsupportedOperationError: () => UnsupportedOperationError
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(errors_exports);
|
|
25
|
+
class InvalidTransactionValueError extends Error {
|
|
26
|
+
/** Transaction `msg.value`. */
|
|
27
|
+
value;
|
|
28
|
+
/** Amount of wrapped native token added as collateral. */
|
|
29
|
+
wethCollateral;
|
|
30
|
+
constructor(value, wethCollateral) {
|
|
31
|
+
super(
|
|
32
|
+
`transaction value ${value} exceeds WETH collateral ${wethCollateral}`
|
|
33
|
+
);
|
|
34
|
+
this.name = "InvalidTransactionValueError";
|
|
35
|
+
this.value = value;
|
|
36
|
+
this.wethCollateral = wethCollateral;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
24
39
|
class UnsupportedOperationError extends Error {
|
|
25
40
|
/** The parsed operation kind (the `operation` discriminant). */
|
|
26
41
|
operation;
|
|
@@ -32,5 +47,6 @@ class UnsupportedOperationError extends Error {
|
|
|
32
47
|
}
|
|
33
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
49
|
0 && (module.exports = {
|
|
50
|
+
InvalidTransactionValueError,
|
|
35
51
|
UnsupportedOperationError
|
|
36
52
|
});
|
|
@@ -22,22 +22,44 @@ __export(extractExpectedBalanceChanges_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(extractExpectedBalanceChanges_exports);
|
|
24
24
|
function extractExpectedBalanceChanges(innerCalls) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const storeIndices = [];
|
|
26
|
+
const compareIndices = [];
|
|
27
|
+
for (let i = 0; i < innerCalls.length; i++) {
|
|
28
|
+
const name = functionName(innerCalls[i]);
|
|
29
|
+
if (name === "storeExpectedBalances") {
|
|
30
|
+
storeIndices.push(i);
|
|
31
|
+
} else if (name === "compareBalances") {
|
|
32
|
+
compareIndices.push(i);
|
|
33
|
+
}
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
const last = calls[calls.length - 1];
|
|
33
|
-
if (functionName(first) !== "storeExpectedBalances" || functionName(last) !== "compareBalances") {
|
|
35
|
+
if (storeIndices.length === 0 && compareIndices.length === 0) {
|
|
34
36
|
return void 0;
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
if (storeIndices.length !== 1 || compareIndices.length !== 1) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`malformed multicall: expected exactly one storeExpectedBalances/compareBalances pair, got ${storeIndices.length} storeExpectedBalances and ${compareIndices.length} compareBalances calls`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (compareIndices[0] < storeIndices[0]) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"malformed multicall: compareBalances appears before storeExpectedBalances"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const store = innerCalls[storeIndices[0]];
|
|
49
|
+
const balanceDeltas = store.rawArgs.balanceDeltas;
|
|
37
50
|
if (!balanceDeltas) {
|
|
38
|
-
|
|
51
|
+
throw new Error(
|
|
52
|
+
"malformed multicall: storeExpectedBalances has no balanceDeltas argument"
|
|
53
|
+
);
|
|
39
54
|
}
|
|
40
|
-
return
|
|
55
|
+
return {
|
|
56
|
+
deltas: balanceDeltas.map(({ token, amount }) => ({
|
|
57
|
+
token,
|
|
58
|
+
balance: amount
|
|
59
|
+
})),
|
|
60
|
+
startIndex: storeIndices[0],
|
|
61
|
+
endIndex: compareIndices[0]
|
|
62
|
+
};
|
|
41
63
|
}
|
|
42
64
|
function functionName(call) {
|
|
43
65
|
return call.functionName.split("(")[0];
|
|
@@ -21,10 +21,12 @@ __export(previewOpenCreditAccount_exports, {
|
|
|
21
21
|
previewOpenCreditAccount: () => previewOpenCreditAccount
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(previewOpenCreditAccount_exports);
|
|
24
|
+
var import_adapters = require("../../plugins/adapters/index.js");
|
|
24
25
|
var import_sdk = require("../../sdk/index.js");
|
|
25
26
|
var import_extractExpectedBalanceChanges = require("./extractExpectedBalanceChanges.js");
|
|
27
|
+
var import_unwrapNativeCollateral = require("./unwrapNativeCollateral.js");
|
|
26
28
|
function previewOpenCreditAccount(input, operation) {
|
|
27
|
-
const { sdk, to, calldata } = input;
|
|
29
|
+
const { sdk, to, calldata, value = 0n } = input;
|
|
28
30
|
const market = sdk.marketRegister.findByCreditManager(
|
|
29
31
|
operation.creditManager
|
|
30
32
|
);
|
|
@@ -62,21 +64,49 @@ function previewOpenCreditAccount(input, operation) {
|
|
|
62
64
|
break;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
|
|
67
|
+
let collateral = collateralByToken.values();
|
|
66
68
|
const collateralValue = collateral.reduce(
|
|
67
69
|
(acc, { token, balance }) => acc + market.priceOracle.convert(token, market.underlying, balance),
|
|
68
70
|
0n
|
|
69
71
|
);
|
|
72
|
+
collateral = (0, import_unwrapNativeCollateral.unwrapNativeCollateral)(
|
|
73
|
+
collateral,
|
|
74
|
+
value,
|
|
75
|
+
sdk.addressProvider.getAddress(import_sdk.AP_WETH_TOKEN, import_sdk.NO_VERSION)
|
|
76
|
+
);
|
|
70
77
|
const parsed = sdk.parseFunctionDataV2(to, calldata);
|
|
71
78
|
const innerCalls = parsed.rawArgs.calls ?? [];
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
const expected = (0, import_extractExpectedBalanceChanges.extractExpectedBalanceChanges)(innerCalls);
|
|
80
|
+
let finalBalances = balances;
|
|
81
|
+
if (expected) {
|
|
82
|
+
const rawCalls = extractRawInnerCalls(sdk, to, calldata);
|
|
83
|
+
if (rawCalls.length !== innerCalls.length) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`raw and parsed inner calls of ${to} are misaligned: ${rawCalls.length} raw vs ${innerCalls.length} parsed`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const snapshot = (0, import_adapters.copyBalances)(balances);
|
|
89
|
+
for (let i = expected.startIndex + 1; i < expected.endIndex; i++) {
|
|
90
|
+
const call = rawCalls[i];
|
|
91
|
+
const adapter = sdk.getContract(call.target);
|
|
92
|
+
if (!(adapter instanceof import_adapters.AbstractAdapterContract)) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`call to ${call.target} between storeExpectedBalances and compareBalances is not an adapter call`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
finalBalances = adapter.previewBalanceChanges(
|
|
98
|
+
finalBalances,
|
|
99
|
+
call.callData
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
for (const { token, balance } of expected.deltas) {
|
|
103
|
+
finalBalances.upsert(token, (snapshot.get(token) ?? 0n) + balance);
|
|
104
|
+
}
|
|
75
105
|
}
|
|
76
|
-
const assets =
|
|
106
|
+
const assets = finalBalances.entries().filter(([, balance]) => balance > 1n).map(([token, balance]) => ({ token, balance }));
|
|
77
107
|
return {
|
|
78
108
|
operation: operation.operation,
|
|
79
|
-
target: inferTargetAsset(operation.multicall,
|
|
109
|
+
target: inferTargetAsset(operation.multicall, finalBalances),
|
|
80
110
|
collateral,
|
|
81
111
|
collateralValue,
|
|
82
112
|
debt,
|
|
@@ -84,6 +114,15 @@ function previewOpenCreditAccount(input, operation) {
|
|
|
84
114
|
assets
|
|
85
115
|
};
|
|
86
116
|
}
|
|
117
|
+
function extractRawInnerCalls(sdk, to, calldata) {
|
|
118
|
+
const entry = sdk.getContract(to);
|
|
119
|
+
if (entry instanceof import_sdk.CreditFacadeV310BaseContract || entry instanceof import_sdk.SecuritizeRWAFactory) {
|
|
120
|
+
return entry.extractRawInnerCalls(calldata);
|
|
121
|
+
}
|
|
122
|
+
throw new Error(
|
|
123
|
+
`cannot extract raw inner calls from ${to}: neither a credit facade nor a supported RWA factory`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
87
126
|
function inferTargetAsset(multicall, balances) {
|
|
88
127
|
for (const op of multicall) {
|
|
89
128
|
if (op.operation === "UpdateQuota" && op.change > 0n) {
|
|
@@ -0,0 +1,59 @@
|
|
|
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 unwrapNativeCollateral_exports = {};
|
|
20
|
+
__export(unwrapNativeCollateral_exports, {
|
|
21
|
+
unwrapNativeCollateral: () => unwrapNativeCollateral
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(unwrapNativeCollateral_exports);
|
|
24
|
+
var import_viem = require("viem");
|
|
25
|
+
var import_sdk = require("../../sdk/index.js");
|
|
26
|
+
var import_errors = require("./errors.js");
|
|
27
|
+
function unwrapNativeCollateral(collateral, nativeAmount, wethToken) {
|
|
28
|
+
if (nativeAmount === 0n) {
|
|
29
|
+
return collateral;
|
|
30
|
+
}
|
|
31
|
+
let unwrapped = false;
|
|
32
|
+
const result = [];
|
|
33
|
+
for (const asset of collateral) {
|
|
34
|
+
const isWeth = !unwrapped && (0, import_viem.isAddressEqual)(asset.token, wethToken);
|
|
35
|
+
if (!isWeth) {
|
|
36
|
+
result.push(asset);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (asset.balance < nativeAmount) {
|
|
40
|
+
throw new import_errors.InvalidTransactionValueError(nativeAmount, asset.balance);
|
|
41
|
+
}
|
|
42
|
+
result.push({ token: import_sdk.NATIVE_ADDRESS, balance: nativeAmount });
|
|
43
|
+
if (asset.balance > nativeAmount) {
|
|
44
|
+
result.push({
|
|
45
|
+
token: asset.token,
|
|
46
|
+
balance: asset.balance - nativeAmount
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
unwrapped = true;
|
|
50
|
+
}
|
|
51
|
+
if (!unwrapped) {
|
|
52
|
+
throw new import_errors.InvalidTransactionValueError(nativeAmount, 0n);
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
unwrapNativeCollateral
|
|
59
|
+
});
|
|
@@ -22,6 +22,7 @@ __export(CreditFacadeV310BaseContract_exports, {
|
|
|
22
22
|
creditFacadeV310Abi: () => abi
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(CreditFacadeV310BaseContract_exports);
|
|
25
|
+
var import_viem = require("viem");
|
|
25
26
|
var import_generated = require("../../../abi/310/generated.js");
|
|
26
27
|
var import_iPausable = require("../../../abi/iPausable.js");
|
|
27
28
|
var import_base = require("../../base/index.js");
|
|
@@ -34,6 +35,36 @@ class CreditFacadeV310BaseContract extends import_base.BaseContract {
|
|
|
34
35
|
constructor(options, args) {
|
|
35
36
|
super(options, { ...args, abi });
|
|
36
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Decodes entry-point calldata with the facade ABI and returns the untouched
|
|
40
|
+
* inner multicall structs (targets with still-ABI-encoded `callData`).
|
|
41
|
+
*
|
|
42
|
+
* Unlike {@link ChainContractsRegister.parseMultiCallV2}, the inner calls are
|
|
43
|
+
* not decoded, so callers can re-decode them with a specific contract's ABI.
|
|
44
|
+
*
|
|
45
|
+
* @throws When the calldata cannot be decoded or the function has no inner
|
|
46
|
+
* multicall argument.
|
|
47
|
+
*/
|
|
48
|
+
extractRawInnerCalls(calldata) {
|
|
49
|
+
const decoded = (0, import_viem.decodeFunctionData)({ abi: this.abi, data: calldata });
|
|
50
|
+
switch (decoded.functionName) {
|
|
51
|
+
case "openCreditAccount":
|
|
52
|
+
case "closeCreditAccount":
|
|
53
|
+
case "botMulticall":
|
|
54
|
+
case "multicall": {
|
|
55
|
+
const [, calls] = decoded.args;
|
|
56
|
+
return [...calls];
|
|
57
|
+
}
|
|
58
|
+
case "liquidateCreditAccount": {
|
|
59
|
+
const [, , calls] = decoded.args;
|
|
60
|
+
return [...calls];
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(
|
|
64
|
+
`function ${decoded.functionName} on ${this.name} has no inner multicall`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
37
68
|
parseFunctionParamsV2(params, strict) {
|
|
38
69
|
switch (params.functionName) {
|
|
39
70
|
case "openCreditAccount": {
|
|
@@ -70,6 +70,31 @@ class SecuritizeRWAFactory extends import_base.BaseContract {
|
|
|
70
70
|
operators: [...t.operators]
|
|
71
71
|
}));
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Decodes entry-point calldata with the factory ABI and returns the
|
|
75
|
+
* untouched inner multicall structs (targets with still-ABI-encoded
|
|
76
|
+
* `callData`).
|
|
77
|
+
*
|
|
78
|
+
* Unlike {@link ChainContractsRegister.parseMultiCallV2}, the inner calls are
|
|
79
|
+
* not decoded, so callers can re-decode them with a specific contract's ABI.
|
|
80
|
+
*
|
|
81
|
+
* @throws When the calldata cannot be decoded or the function has no inner
|
|
82
|
+
* multicall argument.
|
|
83
|
+
*/
|
|
84
|
+
extractRawInnerCalls(calldata) {
|
|
85
|
+
const decoded = (0, import_viem.decodeFunctionData)({ abi: this.abi, data: calldata });
|
|
86
|
+
switch (decoded.functionName) {
|
|
87
|
+
case "openCreditAccount":
|
|
88
|
+
case "multicall": {
|
|
89
|
+
const [, calls] = decoded.args;
|
|
90
|
+
return [...calls];
|
|
91
|
+
}
|
|
92
|
+
default:
|
|
93
|
+
throw new Error(
|
|
94
|
+
`function ${decoded.functionName} on ${this.name} has no inner multicall`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
73
98
|
parseFunctionParamsV2(params, strict) {
|
|
74
99
|
switch (params.functionName) {
|
|
75
100
|
case "openCreditAccount": {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const iConvexV1BoosterAdapterAbi = [
|
|
2
|
+
{
|
|
3
|
+
type: "function",
|
|
4
|
+
inputs: [],
|
|
5
|
+
name: "contractType",
|
|
6
|
+
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }],
|
|
7
|
+
stateMutability: "view"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
type: "function",
|
|
11
|
+
inputs: [],
|
|
12
|
+
name: "creditManager",
|
|
13
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
14
|
+
stateMutability: "view"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: "function",
|
|
18
|
+
inputs: [
|
|
19
|
+
{ name: "_pid", internalType: "uint256", type: "uint256" },
|
|
20
|
+
{ name: "", internalType: "uint256", type: "uint256" },
|
|
21
|
+
{ name: "_stake", internalType: "bool", type: "bool" }
|
|
22
|
+
],
|
|
23
|
+
name: "deposit",
|
|
24
|
+
outputs: [{ name: "useSafePrices", internalType: "bool", type: "bool" }],
|
|
25
|
+
stateMutability: "nonpayable"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "function",
|
|
29
|
+
inputs: [
|
|
30
|
+
{ name: "_pid", internalType: "uint256", type: "uint256" },
|
|
31
|
+
{ name: "leftoverAmount", internalType: "uint256", type: "uint256" },
|
|
32
|
+
{ name: "_stake", internalType: "bool", type: "bool" }
|
|
33
|
+
],
|
|
34
|
+
name: "depositDiff",
|
|
35
|
+
outputs: [{ name: "useSafePrices", internalType: "bool", type: "bool" }],
|
|
36
|
+
stateMutability: "nonpayable"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: "function",
|
|
40
|
+
inputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
41
|
+
name: "pidToConvexToken",
|
|
42
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
43
|
+
stateMutability: "view"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "function",
|
|
47
|
+
inputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
48
|
+
name: "pidToCurveToken",
|
|
49
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
50
|
+
stateMutability: "view"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "function",
|
|
54
|
+
inputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
55
|
+
name: "pidToPhantomToken",
|
|
56
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
57
|
+
stateMutability: "view"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: "function",
|
|
61
|
+
inputs: [],
|
|
62
|
+
name: "serialize",
|
|
63
|
+
outputs: [{ name: "serializedData", internalType: "bytes", type: "bytes" }],
|
|
64
|
+
stateMutability: "view"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
type: "function",
|
|
68
|
+
inputs: [],
|
|
69
|
+
name: "targetContract",
|
|
70
|
+
outputs: [{ name: "", internalType: "address", type: "address" }],
|
|
71
|
+
stateMutability: "view"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: "function",
|
|
75
|
+
inputs: [],
|
|
76
|
+
name: "updateSupportedPids",
|
|
77
|
+
outputs: [],
|
|
78
|
+
stateMutability: "nonpayable"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
type: "function",
|
|
82
|
+
inputs: [],
|
|
83
|
+
name: "version",
|
|
84
|
+
outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
|
|
85
|
+
stateMutability: "view"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: "function",
|
|
89
|
+
inputs: [
|
|
90
|
+
{ name: "_pid", internalType: "uint256", type: "uint256" },
|
|
91
|
+
{ name: "", internalType: "uint256", type: "uint256" }
|
|
92
|
+
],
|
|
93
|
+
name: "withdraw",
|
|
94
|
+
outputs: [{ name: "useSafePrices", internalType: "bool", type: "bool" }],
|
|
95
|
+
stateMutability: "nonpayable"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "function",
|
|
99
|
+
inputs: [
|
|
100
|
+
{ name: "_pid", internalType: "uint256", type: "uint256" },
|
|
101
|
+
{ name: "leftoverAmount", internalType: "uint256", type: "uint256" }
|
|
102
|
+
],
|
|
103
|
+
name: "withdrawDiff",
|
|
104
|
+
outputs: [{ name: "useSafePrices", internalType: "bool", type: "bool" }],
|
|
105
|
+
stateMutability: "nonpayable"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "event",
|
|
109
|
+
anonymous: false,
|
|
110
|
+
inputs: [
|
|
111
|
+
{ name: "pid", internalType: "uint256", type: "uint256", indexed: true }
|
|
112
|
+
],
|
|
113
|
+
name: "AddSupportedPid"
|
|
114
|
+
},
|
|
115
|
+
{ type: "error", inputs: [], name: "UnsupportedPidException" }
|
|
116
|
+
];
|
|
117
|
+
export {
|
|
118
|
+
iConvexV1BoosterAdapterAbi
|
|
119
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AddressMap } from "../../sdk/index.js";
|
|
2
|
+
function copyBalances(balances) {
|
|
3
|
+
return new AddressMap(balances.entries());
|
|
4
|
+
}
|
|
5
|
+
function clampToLeftover(balances, tokenIn, leftoverAmount) {
|
|
6
|
+
const next = copyBalances(balances);
|
|
7
|
+
next.upsert(tokenIn, leftoverAmount);
|
|
8
|
+
return next;
|
|
9
|
+
}
|
|
10
|
+
function curveCoin(tokens, i) {
|
|
11
|
+
const token = tokens[Number(i)];
|
|
12
|
+
if (!token) {
|
|
13
|
+
throw new Error(`curve coin index ${i} is out of range`);
|
|
14
|
+
}
|
|
15
|
+
return token;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
clampToLeftover,
|
|
19
|
+
copyBalances,
|
|
20
|
+
curveCoin
|
|
21
|
+
};
|
|
@@ -103,6 +103,41 @@ class AbstractAdapterContract extends BaseContract {
|
|
|
103
103
|
return void 0;
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Applies the balance changes implied by a router-generated diff-style
|
|
108
|
+
* adapter call to a map of credit-account token balances.
|
|
109
|
+
*
|
|
110
|
+
* @param balances - Token balances before the call. Not mutated.
|
|
111
|
+
* @param calldata - Raw ABI-encoded adapter calldata.
|
|
112
|
+
* @returns A new balances map with the call's changes applied.
|
|
113
|
+
* @throws When the calldata cannot be decoded or the adapter (or the
|
|
114
|
+
* specific function) has no balance-changes support.
|
|
115
|
+
*/
|
|
116
|
+
previewBalanceChanges(balances, calldata) {
|
|
117
|
+
let decoded;
|
|
118
|
+
try {
|
|
119
|
+
decoded = decodeFunctionData({ abi: this.abi, data: calldata });
|
|
120
|
+
} catch (e) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`previewBalanceChanges: cannot decode selector ${calldata.slice(0, 10)} on ${this.contractType} adapter at ${this.address}`,
|
|
123
|
+
{ cause: e }
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return this.previewDecodedBalanceChanges(balances, decoded);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Typed hook for {@link previewBalanceChanges}: receives the viem-decoded
|
|
130
|
+
* adapter call, so overrides can switch on `decoded.functionName` and get
|
|
131
|
+
* fully-typed `decoded.args` without casts.
|
|
132
|
+
*
|
|
133
|
+
* @throws When the adapter (or the specific function) has no balance-changes
|
|
134
|
+
* support; protocol-specific subclasses override this method.
|
|
135
|
+
*/
|
|
136
|
+
previewDecodedBalanceChanges(_balances, decoded) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`previewBalanceChanges is not supported for ${decoded.functionName} on ${this.contractType} adapter at ${this.address}`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
106
141
|
/**
|
|
107
142
|
* Classifies an adapter call into a {@link LegacyAdapterOperation} using the
|
|
108
143
|
* parsed call and credit-account transfer deltas.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { iBalancerV3RouterAdapterAbi } from "@gearbox-protocol/integrations-v3";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
decodeAbiParameters
|
|
4
|
+
} from "viem";
|
|
3
5
|
import { MissingSerializedParamsError } from "../../../sdk/index.js";
|
|
4
6
|
import { iBalancerV3RouterAbi } from "../abi/targetContractAbi.js";
|
|
7
|
+
import { clampToLeftover } from "../balanceChanges.js";
|
|
5
8
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
6
9
|
var BalancerV3PoolStatus = /* @__PURE__ */ ((BalancerV3PoolStatus2) => {
|
|
7
10
|
BalancerV3PoolStatus2[BalancerV3PoolStatus2["NOT_ALLOWED"] = 0] = "NOT_ALLOWED";
|
|
@@ -69,6 +72,25 @@ class BalancerV3RouterAdapterContract extends AbstractAdapterContract {
|
|
|
69
72
|
}))
|
|
70
73
|
};
|
|
71
74
|
}
|
|
75
|
+
previewDecodedBalanceChanges(balances, decoded) {
|
|
76
|
+
switch (decoded.functionName) {
|
|
77
|
+
case "swapSingleTokenDiffIn": {
|
|
78
|
+
const [, tokenIn, , leftoverAmount] = decoded.args;
|
|
79
|
+
return clampToLeftover(balances, tokenIn, leftoverAmount);
|
|
80
|
+
}
|
|
81
|
+
// BPT (pool token) is spent down to the leftover
|
|
82
|
+
case "removeLiquiditySingleTokenDiff": {
|
|
83
|
+
const [pool, leftoverAmount] = decoded.args;
|
|
84
|
+
return clampToLeftover(balances, pool, leftoverAmount);
|
|
85
|
+
}
|
|
86
|
+
case "addLiquidityUnbalancedDiff":
|
|
87
|
+
throw new Error(
|
|
88
|
+
`previewBalanceChanges cannot resolve pool tokens for addLiquidityUnbalancedDiff on ${this.contractType} adapter at ${this.address}`
|
|
89
|
+
);
|
|
90
|
+
default:
|
|
91
|
+
return super.previewDecodedBalanceChanges(balances, decoded);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
72
94
|
}
|
|
73
95
|
export {
|
|
74
96
|
BalancerV3PoolStatus,
|