@gearbox-protocol/sdk 14.12.0-next.8 → 14.12.0-next.9
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/dev/AccountOpener.js +7 -13
- package/dist/cjs/history/classifyMulticallOperations.js +2 -0
- package/dist/cjs/history/mapOperations.js +7 -0
- package/dist/cjs/plugins/adapters/contracts/AbstractAdapter.js +10 -9
- package/dist/cjs/plugins/adapters/contracts/AbstractCurveAdapter.js +66 -0
- package/dist/cjs/plugins/adapters/contracts/BalancerV3RouterAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.js +4 -9
- package/dist/cjs/plugins/adapters/contracts/CamelotV3AdapterContract.js +9 -5
- package/dist/cjs/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.js +5 -10
- package/dist/cjs/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/Curve2AssetsAdapterContract.js +2 -34
- package/dist/cjs/plugins/adapters/contracts/Curve3AssetsAdapterContract.js +2 -34
- package/dist/cjs/plugins/adapters/contracts/Curve4AssetsAdapterContract.js +2 -34
- package/dist/cjs/plugins/adapters/contracts/CurveV1AdapterDeposit.js +2 -29
- package/dist/cjs/plugins/adapters/contracts/CurveV1AdapterStETHContract.js +2 -34
- package/dist/cjs/plugins/adapters/contracts/CurveV1StableNGAdapterContract.js +2 -34
- package/dist/cjs/plugins/adapters/contracts/DaiUsdsAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/ERC4626AdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/ERC4626ReferralAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/FluidDexAdapterContract.js +8 -8
- package/dist/cjs/plugins/adapters/contracts/InfinifiGatewayAdapterContract.js +5 -6
- package/dist/cjs/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/LidoV1AdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/MellowDVVAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/MellowWrapperAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/PendleRouterAdapterContract.js +16 -11
- package/dist/cjs/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/SecuritizeSwapAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/StakingRewardsAdapterContract.js +5 -10
- package/dist/cjs/plugins/adapters/contracts/TraderJoeRouterAdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/UniswapV2AdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/UniswapV3AdapterContract.js +9 -5
- package/dist/cjs/plugins/adapters/contracts/UniswapV4AdapterContract.js +8 -8
- package/dist/cjs/plugins/adapters/contracts/UpshiftVaultAdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/contracts/VelodromeV2AdapterContract.js +3 -4
- package/dist/cjs/plugins/adapters/contracts/WstETHV1AdapterContract.js +4 -5
- package/dist/cjs/plugins/adapters/index.js +0 -2
- package/dist/cjs/preview/parse/classifyInnerOperations.js +14 -1
- package/dist/cjs/preview/prerequisites/buildPrerequisites.js +3 -8
- package/dist/cjs/preview/preview/previewOpenCreditAccount.js +51 -59
- package/dist/cjs/preview/preview/unwrapNativeCollateral.js +10 -24
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +3 -4
- package/dist/cjs/sdk/base/BaseContract.js +4 -2
- package/dist/cjs/sdk/base/ChainContractsRegister.js +1 -0
- package/dist/cjs/sdk/market/credit/CreditFacadeV310BaseContract.js +0 -31
- package/dist/cjs/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +0 -25
- package/dist/cjs/sdk/router/AbstractRouterContract.js +21 -27
- package/dist/cjs/sdk/router/RouterV310Contract.js +11 -12
- package/dist/cjs/sdk/router/helpers.js +0 -5
- package/dist/cjs/sdk/utils/AddressMap.js +6 -0
- package/dist/cjs/sdk/utils/AssetsMap.js +61 -0
- package/dist/cjs/sdk/utils/index.js +2 -0
- package/dist/esm/dev/AccountOpener.js +8 -13
- package/dist/esm/history/classifyMulticallOperations.js +2 -0
- package/dist/esm/history/mapOperations.js +7 -0
- package/dist/esm/plugins/adapters/contracts/AbstractAdapter.js +10 -9
- package/dist/esm/plugins/adapters/contracts/AbstractCurveAdapter.js +42 -0
- package/dist/esm/plugins/adapters/contracts/BalancerV3RouterAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.js +4 -9
- package/dist/esm/plugins/adapters/contracts/CamelotV3AdapterContract.js +9 -5
- package/dist/esm/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.js +5 -10
- package/dist/esm/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/Curve2AssetsAdapterContract.js +3 -37
- package/dist/esm/plugins/adapters/contracts/Curve3AssetsAdapterContract.js +3 -37
- package/dist/esm/plugins/adapters/contracts/Curve4AssetsAdapterContract.js +3 -37
- package/dist/esm/plugins/adapters/contracts/CurveV1AdapterDeposit.js +3 -32
- package/dist/esm/plugins/adapters/contracts/CurveV1AdapterStETHContract.js +3 -37
- package/dist/esm/plugins/adapters/contracts/CurveV1StableNGAdapterContract.js +3 -37
- package/dist/esm/plugins/adapters/contracts/DaiUsdsAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/ERC4626AdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/ERC4626ReferralAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/FluidDexAdapterContract.js +8 -8
- package/dist/esm/plugins/adapters/contracts/InfinifiGatewayAdapterContract.js +5 -6
- package/dist/esm/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/LidoV1AdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/MellowDVVAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/MellowWrapperAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/PendleRouterAdapterContract.js +16 -11
- package/dist/esm/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/SecuritizeSwapAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/StakingRewardsAdapterContract.js +5 -10
- package/dist/esm/plugins/adapters/contracts/TraderJoeRouterAdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/UniswapV2AdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/UniswapV3AdapterContract.js +9 -5
- package/dist/esm/plugins/adapters/contracts/UniswapV4AdapterContract.js +8 -8
- package/dist/esm/plugins/adapters/contracts/UpshiftVaultAdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/contracts/VelodromeV2AdapterContract.js +3 -4
- package/dist/esm/plugins/adapters/contracts/WstETHV1AdapterContract.js +4 -5
- package/dist/esm/plugins/adapters/index.js +0 -1
- package/dist/esm/preview/parse/classifyInnerOperations.js +14 -1
- package/dist/esm/preview/prerequisites/buildPrerequisites.js +4 -8
- package/dist/esm/preview/preview/previewOpenCreditAccount.js +54 -67
- package/dist/esm/preview/preview/unwrapNativeCollateral.js +11 -25
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +4 -5
- package/dist/esm/sdk/base/BaseContract.js +4 -2
- package/dist/esm/sdk/base/ChainContractsRegister.js +1 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV310BaseContract.js +0 -33
- package/dist/esm/sdk/market/rwa/securitize/SecuritizeRWAFactory.js +1 -27
- package/dist/esm/sdk/router/AbstractRouterContract.js +25 -29
- package/dist/esm/sdk/router/RouterV310Contract.js +11 -12
- package/dist/esm/sdk/router/helpers.js +0 -4
- package/dist/esm/sdk/utils/AddressMap.js +6 -0
- package/dist/esm/sdk/utils/AssetsMap.js +37 -0
- package/dist/esm/sdk/utils/index.js +1 -0
- package/dist/types/common-utils/utils/strategies/assets/assets.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/credit-managers/get-wallet-balances-allowed-on-cm.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-apy.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/strategy-info/calculate-total-points.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/add-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/tokens/get-list-with-amount-in-target.d.ts +1 -1
- package/dist/types/common-utils/utils/strategies/types/strategy-earnings.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-balances.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-open-account.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-quota.d.ts +1 -1
- package/dist/types/common-utils/utils/validation/validate-token-to-obtain.d.ts +1 -1
- package/dist/types/plugins/adapters/contracts/AbstractAdapter.d.ts +9 -11
- package/dist/types/plugins/adapters/contracts/AbstractCurveAdapter.d.ts +18 -0
- package/dist/types/plugins/adapters/contracts/BalancerV3RouterAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/BalancerV3WrapperAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/CamelotV3AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BaseRewardPoolAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/ConvexV1BoosterAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/Curve2AssetsAdapterContract.d.ts +4 -8
- package/dist/types/plugins/adapters/contracts/Curve3AssetsAdapterContract.d.ts +4 -9
- package/dist/types/plugins/adapters/contracts/Curve4AssetsAdapterContract.d.ts +4 -8
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterDeposit.d.ts +4 -5
- package/dist/types/plugins/adapters/contracts/CurveV1AdapterStETHContract.d.ts +4 -8
- package/dist/types/plugins/adapters/contracts/CurveV1StableNGAdapterContract.d.ts +4 -8
- package/dist/types/plugins/adapters/contracts/DaiUsdsAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/ERC4626AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/ERC4626ReferralAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/FluidDexAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/InfinifiGatewayAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/KelpLRTDepositPoolAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/LidoV1AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/MellowDVVAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/MellowERC4626VaultAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/MellowWrapperAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/MidasIssuanceVaultAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/MidasRedemptionVaultAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/PendleRouterAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/SecuritizeOnRampAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/SecuritizeSwapAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/StakingRewardsAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/TraderJoeRouterAdapterContract.d.ts +2 -1
- 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 +2 -1
- package/dist/types/plugins/adapters/contracts/UpshiftVaultAdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/VelodromeV2AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/contracts/WstETHV1AdapterContract.d.ts +2 -1
- package/dist/types/plugins/adapters/index.d.ts +0 -1
- package/dist/types/plugins/adapters/types.d.ts +10 -0
- package/dist/types/preview/parse/types-adapters.d.ts +5 -1
- package/dist/types/preview/parse/types-facades.d.ts +23 -1
- package/dist/types/preview/preview/types.d.ts +4 -0
- package/dist/types/preview/preview/unwrapNativeCollateral.d.ts +2 -2
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +1 -1
- package/dist/types/sdk/accounts/types.d.ts +2 -2
- package/dist/types/sdk/base/BaseContract.d.ts +1 -1
- package/dist/types/sdk/base/TokensMeta.d.ts +1 -1
- package/dist/types/sdk/base/types.d.ts +18 -0
- package/dist/types/sdk/market/credit/CreditFacadeV310BaseContract.d.ts +1 -13
- package/dist/types/sdk/market/rwa/securitize/SecuritizeRWAFactory.d.ts +1 -13
- package/dist/types/sdk/pools/types.d.ts +1 -1
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +5 -5
- package/dist/types/sdk/router/helpers.d.ts +1 -2
- package/dist/types/sdk/router/types.d.ts +1 -15
- package/dist/types/sdk/utils/AddressMap.d.ts +4 -0
- package/dist/types/sdk/utils/AssetsMap.d.ts +26 -0
- package/dist/types/sdk/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/dist/cjs/plugins/adapters/balanceChanges.js +0 -47
- package/dist/cjs/preview/preview/extractExpectedBalanceChanges.js +0 -70
- package/dist/esm/plugins/adapters/balanceChanges.js +0 -21
- package/dist/esm/preview/preview/extractExpectedBalanceChanges.js +0 -46
- package/dist/types/plugins/adapters/balanceChanges.d.ts +0 -21
- package/dist/types/preview/preview/extractExpectedBalanceChanges.d.ts +0 -33
|
@@ -41,15 +41,15 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
41
41
|
options.debtOnly
|
|
42
42
|
);
|
|
43
43
|
const { leftoverBalances, expectedBalances, tokensToClaim } = b;
|
|
44
|
-
const expected = new import_utils.
|
|
45
|
-
const leftover = new import_utils.
|
|
44
|
+
const expected = new import_utils.AssetsMap();
|
|
45
|
+
const leftover = new import_utils.AssetsMap();
|
|
46
46
|
for (const token of cm.collateralTokens) {
|
|
47
|
-
const actual = expectedBalances.get(token)
|
|
48
|
-
expected.upsert(token,
|
|
49
|
-
leftover.upsert(
|
|
47
|
+
const actual = expectedBalances.get(token) || 0n;
|
|
48
|
+
expected.upsert(token, actual > 10n ? actual : 0n);
|
|
49
|
+
leftover.upsert(
|
|
50
50
|
token,
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
(0, import_helpers.limitLeftover)(leftoverBalances.get(token) || 1n, token) ?? 1n
|
|
52
|
+
);
|
|
53
53
|
}
|
|
54
54
|
return {
|
|
55
55
|
expectedBalances: expected,
|
|
@@ -58,8 +58,8 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
60
|
getDefaultExpectedAndLeftover(ca, keepAssets, debtOnly) {
|
|
61
|
-
const expectedBalances = new import_utils.
|
|
62
|
-
const leftoverBalances = new import_utils.
|
|
61
|
+
const expectedBalances = new import_utils.AssetsMap();
|
|
62
|
+
const leftoverBalances = new import_utils.AssetsMap();
|
|
63
63
|
const keepAssetsSet = new import_utils.AddressSet(keepAssets);
|
|
64
64
|
if (debtOnly) {
|
|
65
65
|
const result = this.getLeftoversAfterBuyingDebt(ca, keepAssetsSet);
|
|
@@ -71,23 +71,23 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
71
71
|
}
|
|
72
72
|
for (const { token, balance, mask } of ca.tokens) {
|
|
73
73
|
const isEnabled = (mask & ca.enabledTokensMask) !== 0n;
|
|
74
|
-
expectedBalances.upsert(token,
|
|
74
|
+
expectedBalances.upsert(token, balance);
|
|
75
75
|
if (keepAssetsSet.has(token) || !isEnabled || (0, import_utils.isDust)({
|
|
76
76
|
sdk: this.sdk,
|
|
77
77
|
token,
|
|
78
78
|
balance,
|
|
79
79
|
creditManager: ca.creditManager
|
|
80
80
|
})) {
|
|
81
|
-
leftoverBalances.upsert(
|
|
81
|
+
leftoverBalances.upsert(
|
|
82
82
|
token,
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
(0, import_helpers.limitLeftover)(balance, token) ?? balance
|
|
84
|
+
);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
return {
|
|
88
88
|
expectedBalances,
|
|
89
89
|
leftoverBalances,
|
|
90
|
-
tokensToClaim: new import_utils.
|
|
90
|
+
tokensToClaim: new import_utils.AssetsMap()
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
@@ -100,16 +100,13 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
100
100
|
const { priceOracle } = this.sdk.marketRegister.findByCreditManager(
|
|
101
101
|
ca.creditManager
|
|
102
102
|
);
|
|
103
|
-
const expectedBalances = new import_utils.
|
|
104
|
-
const leftoverBalances = new import_utils.
|
|
103
|
+
const expectedBalances = new import_utils.AssetsMap();
|
|
104
|
+
const leftoverBalances = new import_utils.AssetsMap();
|
|
105
105
|
const usdBalances = [];
|
|
106
106
|
for (const { token, balance, mask } of ca.tokens) {
|
|
107
107
|
const isEnabled = (mask & ca.enabledTokensMask) !== 0n;
|
|
108
|
-
expectedBalances.upsert(token,
|
|
109
|
-
leftoverBalances.upsert(token,
|
|
110
|
-
token,
|
|
111
|
-
balance: (0, import_helpers.limitLeftover)(balance, token) ?? balance
|
|
112
|
-
});
|
|
108
|
+
expectedBalances.upsert(token, balance);
|
|
109
|
+
leftoverBalances.upsert(token, (0, import_helpers.limitLeftover)(balance, token) ?? balance);
|
|
113
110
|
if (isEnabled && !keepAssets.has(token)) {
|
|
114
111
|
usdBalances.push({
|
|
115
112
|
token,
|
|
@@ -139,15 +136,12 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
139
136
|
if (tokenAmount === 0n) {
|
|
140
137
|
return void 0;
|
|
141
138
|
}
|
|
142
|
-
let leftoverBalance = leftoverBalances.get(highestToken.token)
|
|
139
|
+
let leftoverBalance = leftoverBalances.get(highestToken.token) ?? 0n;
|
|
143
140
|
leftoverBalance -= tokenAmount;
|
|
144
141
|
if (leftoverBalance < 0n) {
|
|
145
142
|
return void 0;
|
|
146
143
|
}
|
|
147
|
-
leftoverBalances.upsert(highestToken.token,
|
|
148
|
-
token: highestToken.token,
|
|
149
|
-
balance: leftoverBalance
|
|
150
|
-
});
|
|
144
|
+
leftoverBalances.upsert(highestToken.token, leftoverBalance);
|
|
151
145
|
const tokenAmountStr = this.sdk.tokensMeta.formatBN(
|
|
152
146
|
highestToken.token,
|
|
153
147
|
tokenAmount,
|
|
@@ -160,7 +154,7 @@ class AbstractRouterContract extends import_base.BaseContract {
|
|
|
160
154
|
return {
|
|
161
155
|
expectedBalances,
|
|
162
156
|
leftoverBalances,
|
|
163
|
-
tokensToClaim: new import_utils.
|
|
157
|
+
tokensToClaim: new import_utils.AssetsMap()
|
|
164
158
|
};
|
|
165
159
|
}
|
|
166
160
|
safeConvertToUSD(priceOracle, token, balance) {
|
|
@@ -23,14 +23,13 @@ __export(RouterV310Contract_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(RouterV310Contract_exports);
|
|
24
24
|
var import_viem = require("viem");
|
|
25
25
|
var import_gearboxRouter = require("../../abi/router/gearboxRouter.js");
|
|
26
|
-
var import_AddressMap = require("../utils/AddressMap.js");
|
|
27
26
|
var import_formatter = require("../utils/formatter.js");
|
|
28
27
|
var import_utils = require("../utils/index.js");
|
|
29
28
|
var import_AbstractRouterContract = require("./AbstractRouterContract.js");
|
|
30
29
|
var import_helpers = require("./helpers.js");
|
|
31
30
|
const abi = import_gearboxRouter.gearboxRouterAbi;
|
|
32
31
|
class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterContract {
|
|
33
|
-
#numSplits = new
|
|
32
|
+
#numSplits = new import_utils.AddressMap();
|
|
34
33
|
#defaultNumSplits = 4n;
|
|
35
34
|
constructor(sdk, address, version) {
|
|
36
35
|
super(sdk, {
|
|
@@ -94,8 +93,8 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
94
93
|
slippage
|
|
95
94
|
} = props;
|
|
96
95
|
const [expectedMap, leftoverMap] = [
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
new import_utils.AssetsMap(expectedBalances),
|
|
97
|
+
new import_utils.AssetsMap(leftoverBalances)
|
|
99
98
|
];
|
|
100
99
|
const getNumSplits = this.#numSplitsGetter(cm, expectedBalances);
|
|
101
100
|
const tData = cm.collateralTokens.map(
|
|
@@ -180,22 +179,22 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
180
179
|
} = props;
|
|
181
180
|
const { expectedBalances, leftoverBalances, tokensToClaim } = this.getExpectedAndLeftover(ca, cm, {
|
|
182
181
|
balances: balances ? {
|
|
183
|
-
expectedBalances:
|
|
184
|
-
leftoverBalances:
|
|
185
|
-
tokensToClaim:
|
|
182
|
+
expectedBalances: new import_utils.AssetsMap(balances.expectedBalances),
|
|
183
|
+
leftoverBalances: new import_utils.AssetsMap(balances.leftoverBalances),
|
|
184
|
+
tokensToClaim: new import_utils.AssetsMap(balances.tokensToClaim || [])
|
|
186
185
|
} : void 0,
|
|
187
186
|
keepAssets: balances ? void 0 : keepAssets,
|
|
188
187
|
debtOnly
|
|
189
188
|
});
|
|
190
|
-
const getNumSplits = this.#numSplitsGetter(cm, expectedBalances.
|
|
189
|
+
const getNumSplits = this.#numSplitsGetter(cm, expectedBalances.toAssets());
|
|
191
190
|
const tData = [];
|
|
192
191
|
for (const token of cm.collateralTokens) {
|
|
193
192
|
tData.push({
|
|
194
193
|
token,
|
|
195
|
-
balance: expectedBalances.get(token)
|
|
196
|
-
leftoverBalance: (0, import_helpers.limitLeftover)(leftoverBalances.get(token)
|
|
194
|
+
balance: expectedBalances.get(token) || 0n,
|
|
195
|
+
leftoverBalance: (0, import_helpers.limitLeftover)(leftoverBalances.get(token), token) ?? 0n,
|
|
197
196
|
numSplits: getNumSplits(token),
|
|
198
|
-
claimRewards:
|
|
197
|
+
claimRewards: tokensToClaim.has(token)
|
|
199
198
|
});
|
|
200
199
|
}
|
|
201
200
|
this.logger?.debug(
|
|
@@ -278,7 +277,7 @@ class RouterV310Contract extends import_AbstractRouterContract.AbstractRouterCon
|
|
|
278
277
|
})),
|
|
279
278
|
"balances in usd"
|
|
280
279
|
);
|
|
281
|
-
const map = new
|
|
280
|
+
const map = new import_utils.AddressMap(
|
|
282
281
|
inUSD.map(({ token }, i) => [
|
|
283
282
|
token,
|
|
284
283
|
i === 0 ? this.#defaultNumSplits : 1n
|
|
@@ -19,14 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var helpers_exports = {};
|
|
20
20
|
__export(helpers_exports, {
|
|
21
21
|
assetsMap: () => assetsMap,
|
|
22
|
-
balancesMap: () => balancesMap,
|
|
23
22
|
limitLeftover: () => limitLeftover
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(helpers_exports);
|
|
26
25
|
var import_utils = require("../utils/index.js");
|
|
27
|
-
function balancesMap(assets) {
|
|
28
|
-
return new import_utils.AddressMap(assets.map(({ token, balance }) => [token, balance]));
|
|
29
|
-
}
|
|
30
26
|
function assetsMap(assets) {
|
|
31
27
|
return new import_utils.AddressMap(assets.map((a) => [a.token, a]));
|
|
32
28
|
}
|
|
@@ -42,6 +38,5 @@ function limitLeftover(balance, token) {
|
|
|
42
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43
39
|
0 && (module.exports = {
|
|
44
40
|
assetsMap,
|
|
45
|
-
balancesMap,
|
|
46
41
|
limitLeftover
|
|
47
42
|
});
|
|
@@ -136,6 +136,12 @@ class AddressMap {
|
|
|
136
136
|
keys() {
|
|
137
137
|
return Array.from(this.#map.keys());
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns an unfrozen shallow copy of the map.
|
|
141
|
+
**/
|
|
142
|
+
clone() {
|
|
143
|
+
return new AddressMap(this.entries(), this.name);
|
|
144
|
+
}
|
|
139
145
|
/**
|
|
140
146
|
* Converts the map to a plain `Record<Address, T>` object.
|
|
141
147
|
**/
|
|
@@ -0,0 +1,61 @@
|
|
|
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 AssetsMap_exports = {};
|
|
20
|
+
__export(AssetsMap_exports, {
|
|
21
|
+
AssetsMap: () => AssetsMap
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(AssetsMap_exports);
|
|
24
|
+
var import_AddressMap = require("./AddressMap.js");
|
|
25
|
+
class AssetsMap extends import_AddressMap.AddressMap {
|
|
26
|
+
/**
|
|
27
|
+
* @param entries - Optional initial entries as `[address, balance]` tuples or {@link Asset} objects.
|
|
28
|
+
* @param name - Optional label used in error messages when a lookup fails.
|
|
29
|
+
*/
|
|
30
|
+
constructor(entries, name) {
|
|
31
|
+
super(
|
|
32
|
+
entries?.map((e) => Array.isArray(e) ? e : [e.token, e.balance]),
|
|
33
|
+
name
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Adds `amount` to the token balance, treating a missing key as `0n`.
|
|
38
|
+
*/
|
|
39
|
+
inc(address, amount) {
|
|
40
|
+
this.upsert(address, (this.get(address) ?? 0n) + amount);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Subtracts `amount` from the token balance, treating a missing key as `0n`.
|
|
44
|
+
*/
|
|
45
|
+
dec(address, amount) {
|
|
46
|
+
this.inc(address, -amount);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Converts the map to an array of {@link Asset} objects.
|
|
50
|
+
*/
|
|
51
|
+
toAssets() {
|
|
52
|
+
return this.entries().map(([token, balance]) => ({ token, balance }));
|
|
53
|
+
}
|
|
54
|
+
clone() {
|
|
55
|
+
return new AssetsMap(this.entries(), this.name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
AssetsMap
|
|
61
|
+
});
|
|
@@ -17,6 +17,7 @@ var utils_exports = {};
|
|
|
17
17
|
module.exports = __toCommonJS(utils_exports);
|
|
18
18
|
__reExport(utils_exports, require("./AddressMap.js"), module.exports);
|
|
19
19
|
__reExport(utils_exports, require("./AddressSet.js"), module.exports);
|
|
20
|
+
__reExport(utils_exports, require("./AssetsMap.js"), module.exports);
|
|
20
21
|
__reExport(utils_exports, require("./abi-decode.js"), module.exports);
|
|
21
22
|
__reExport(utils_exports, require("./bytes32ToString.js"), module.exports);
|
|
22
23
|
__reExport(utils_exports, require("./childLogger.js"), module.exports);
|
|
@@ -36,6 +37,7 @@ __reExport(utils_exports, require("./zod.js"), module.exports);
|
|
|
36
37
|
0 && (module.exports = {
|
|
37
38
|
...require("./AddressMap.js"),
|
|
38
39
|
...require("./AddressSet.js"),
|
|
40
|
+
...require("./AssetsMap.js"),
|
|
39
41
|
...require("./abi-decode.js"),
|
|
40
42
|
...require("./bytes32ToString.js"),
|
|
41
43
|
...require("./childLogger.js"),
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ADDRESS_0X0,
|
|
13
13
|
AddressMap,
|
|
14
14
|
AddressSet,
|
|
15
|
+
AssetsMap,
|
|
15
16
|
childLogger,
|
|
16
17
|
MAX_UINT256,
|
|
17
18
|
PERCENTAGE_FACTOR,
|
|
@@ -373,7 +374,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
373
374
|
}
|
|
374
375
|
async #depositIntoPools(targets) {
|
|
375
376
|
this.#logger?.debug("checking and topping up pools if necessary");
|
|
376
|
-
const minAvailableByPool =
|
|
377
|
+
const minAvailableByPool = new AssetsMap();
|
|
377
378
|
for (let i = 0; i < targets.length; i++) {
|
|
378
379
|
const t = targets[i];
|
|
379
380
|
const leverage = this.#getLeverage(t);
|
|
@@ -381,14 +382,14 @@ class AccountOpener extends SDKConstruct {
|
|
|
381
382
|
const minDebt = this.#minDebtMultiplier * cm.creditFacade.minDebt / PERCENTAGE_FACTOR;
|
|
382
383
|
let amount = minDebt * (leverage - PERCENTAGE_FACTOR) / PERCENTAGE_FACTOR * this.#poolDepositMultiplier / PERCENTAGE_FACTOR;
|
|
383
384
|
amount = amount > cm.creditFacade.maxDebt ? cm.creditFacade.maxDebt : amount;
|
|
384
|
-
minAvailableByPool
|
|
385
|
+
minAvailableByPool.inc(cm.pool, amount);
|
|
385
386
|
this.#logger?.debug(
|
|
386
387
|
`target #${i + 1} (${this.labelAddress(t.target)}) needs ${this.sdk.tokensMeta.formatBN(cm.underlying, amount, { symbol: true })} in pool (leverage: ${Number(leverage / PERCENTAGE_FACTOR)}%)`
|
|
387
388
|
);
|
|
388
389
|
}
|
|
389
390
|
const deposits = [];
|
|
390
|
-
const claims = new
|
|
391
|
-
for (const [p, minAvailable] of
|
|
391
|
+
const claims = new AssetsMap();
|
|
392
|
+
for (const [p, minAvailable] of minAvailableByPool.entries()) {
|
|
392
393
|
const market = this.sdk.marketRegister.findByPool(p);
|
|
393
394
|
const pool = market.pool.pool;
|
|
394
395
|
let diff = minAvailable - pool.availableLiquidity;
|
|
@@ -405,9 +406,7 @@ class AccountOpener extends SDKConstruct {
|
|
|
405
406
|
);
|
|
406
407
|
if (diff > 0n) {
|
|
407
408
|
deposits.push([pool, diff]);
|
|
408
|
-
|
|
409
|
-
claim += diff * PERCENTAGE_FACTOR / 8950n;
|
|
410
|
-
claims.upsert(pool.underlying, claim);
|
|
409
|
+
claims.inc(pool.underlying, diff * PERCENTAGE_FACTOR / 8950n);
|
|
411
410
|
}
|
|
412
411
|
}
|
|
413
412
|
const depositor = await this.#getDepositor();
|
|
@@ -564,18 +563,14 @@ class AccountOpener extends SDKConstruct {
|
|
|
564
563
|
async #prepareBorrower(targets) {
|
|
565
564
|
const borrower = await this.#getBorrower();
|
|
566
565
|
const degenNFTS = {};
|
|
567
|
-
const claims = new
|
|
566
|
+
const claims = new AssetsMap();
|
|
568
567
|
for (const target of targets) {
|
|
569
568
|
const cm = this.sdk.marketRegister.findCreditManager(
|
|
570
569
|
target.creditManager
|
|
571
570
|
);
|
|
572
|
-
const market = this.sdk.marketRegister.findByCreditManager(
|
|
573
|
-
target.creditManager
|
|
574
|
-
);
|
|
575
571
|
const { degenNFT } = cm.creditFacade;
|
|
576
572
|
const minDebt = this.#minDebtMultiplier * cm.creditFacade.minDebt / PERCENTAGE_FACTOR;
|
|
577
|
-
|
|
578
|
-
claims.upsert(cm.underlying, claim + minDebt * 11n / 10n);
|
|
573
|
+
claims.inc(cm.underlying, minDebt * 11n / 10n);
|
|
579
574
|
if (isAddress(degenNFT) && degenNFT !== ADDRESS_0X0) {
|
|
580
575
|
degenNFTS[degenNFT] = (degenNFTS[degenNFT] ?? 0) + 1;
|
|
581
576
|
}
|
|
@@ -45,6 +45,7 @@ function classifyMulticallOperations(input) {
|
|
|
45
45
|
label: call.label,
|
|
46
46
|
adapterFunctionName: call.functionName,
|
|
47
47
|
adapterArgs: call.rawArgs,
|
|
48
|
+
calldata: call.calldata,
|
|
48
49
|
protocol,
|
|
49
50
|
transfers: transfers2,
|
|
50
51
|
legacy
|
|
@@ -80,6 +81,7 @@ function classifyMulticallOperations(input) {
|
|
|
80
81
|
label: call.label,
|
|
81
82
|
adapterFunctionName: call.functionName,
|
|
82
83
|
adapterArgs: call.rawArgs,
|
|
84
|
+
calldata: call.calldata,
|
|
83
85
|
// Unknown adapter (non-strict): we have no ABI to decode the protocol
|
|
84
86
|
// call, so `protocol` is left absent rather than filled with placeholders.
|
|
85
87
|
protocol: void 0,
|
|
@@ -12,6 +12,13 @@ function mapInnerOperation(op, visitor, ctx) {
|
|
|
12
12
|
return visitor.WithdrawCollateral(op, ctx);
|
|
13
13
|
case "UpdateQuota":
|
|
14
14
|
return visitor.UpdateQuota(op, ctx);
|
|
15
|
+
// The history classifier never emits other InnerOperation variants
|
|
16
|
+
// (e.g. StoreExpectedBalances/CompareBalances, which it drops), so this
|
|
17
|
+
// guards against silently returning undefined if that ever changes.
|
|
18
|
+
default:
|
|
19
|
+
throw new Error(
|
|
20
|
+
`unexpected inner operation: ${op.operation}`
|
|
21
|
+
);
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
24
|
function mapOuterOperation(op, visitor) {
|
|
@@ -107,9 +107,8 @@ class AbstractAdapterContract extends BaseContract {
|
|
|
107
107
|
* Applies the balance changes implied by a router-generated diff-style
|
|
108
108
|
* adapter call to a map of credit-account token balances.
|
|
109
109
|
*
|
|
110
|
-
* @param balances - Token balances before the call.
|
|
110
|
+
* @param balances - Token balances before the call. Mutated in place.
|
|
111
111
|
* @param calldata - Raw ABI-encoded adapter calldata.
|
|
112
|
-
* @returns A new balances map with the call's changes applied.
|
|
113
112
|
* @throws When the calldata cannot be decoded or the adapter (or the
|
|
114
113
|
* specific function) has no balance-changes support.
|
|
115
114
|
*/
|
|
@@ -123,17 +122,19 @@ class AbstractAdapterContract extends BaseContract {
|
|
|
123
122
|
{ cause: e }
|
|
124
123
|
);
|
|
125
124
|
}
|
|
126
|
-
|
|
125
|
+
const leftovers = this.decodeDiffLeftovers(decoded, balances);
|
|
126
|
+
for (const { tokenIn, leftoverAmount } of leftovers) {
|
|
127
|
+
balances.upsert(tokenIn, leftoverAmount);
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
130
|
/**
|
|
129
|
-
*
|
|
130
|
-
* adapter call, so overrides can switch on `decoded.functionName` and get
|
|
131
|
-
* fully-typed `decoded.args` without casts.
|
|
131
|
+
* Resolves which tokens the diff-style call spends down to which leftovers.
|
|
132
132
|
*
|
|
133
|
-
* @
|
|
134
|
-
*
|
|
133
|
+
* @param decoded - The viem-decoded adapter call
|
|
134
|
+
* @param _balances - Token balances before the call
|
|
135
|
+
* @throws When the adapter (or the specific function) has no balance-changes support
|
|
135
136
|
*/
|
|
136
|
-
|
|
137
|
+
decodeDiffLeftovers(decoded, _balances) {
|
|
137
138
|
throw new Error(
|
|
138
139
|
`previewBalanceChanges is not supported for ${decoded.functionName} on ${this.contractType} adapter at ${this.address}`
|
|
139
140
|
);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { classifyCurveOperation } from "../transferHelpers.js";
|
|
2
|
+
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
3
|
+
class AbstractCurveAdapterContract extends AbstractAdapterContract {
|
|
4
|
+
/** @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type.go#L132-L164 */
|
|
5
|
+
classifyLegacyOperation(parsed, transfers) {
|
|
6
|
+
return classifyCurveOperation(parsed.functionName, transfers) ?? super.classifyLegacyOperation(parsed, transfers);
|
|
7
|
+
}
|
|
8
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
9
|
+
const { functionName, args } = decoded;
|
|
10
|
+
switch (functionName) {
|
|
11
|
+
case "exchange_diff": {
|
|
12
|
+
const [i, , leftoverAmount] = args;
|
|
13
|
+
return [{ tokenIn: this.curveCoin(i), leftoverAmount }];
|
|
14
|
+
}
|
|
15
|
+
case "add_diff_liquidity_one_coin": {
|
|
16
|
+
const [leftoverAmount, i] = args;
|
|
17
|
+
return [{ tokenIn: this.curveCoin(i), leftoverAmount }];
|
|
18
|
+
}
|
|
19
|
+
case "remove_diff_liquidity_one_coin": {
|
|
20
|
+
const [leftoverAmount] = args;
|
|
21
|
+
return [{ tokenIn: this.lpToken, leftoverAmount }];
|
|
22
|
+
}
|
|
23
|
+
default:
|
|
24
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolves a Curve pool coin index to its token address.
|
|
29
|
+
*
|
|
30
|
+
* @throws When the index is out of range for the pool.
|
|
31
|
+
*/
|
|
32
|
+
curveCoin(i) {
|
|
33
|
+
const token = this.tokens[Number(i)];
|
|
34
|
+
if (!token) {
|
|
35
|
+
throw new Error(`curve coin index ${i} is out of range`);
|
|
36
|
+
}
|
|
37
|
+
return token;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
AbstractCurveAdapterContract
|
|
42
|
+
};
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "viem";
|
|
5
5
|
import { MissingSerializedParamsError } from "../../../sdk/index.js";
|
|
6
6
|
import { iBalancerV3RouterAbi } from "../abi/targetContractAbi.js";
|
|
7
|
-
import { clampToLeftover } from "../balanceChanges.js";
|
|
8
7
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
9
8
|
var BalancerV3PoolStatus = /* @__PURE__ */ ((BalancerV3PoolStatus2) => {
|
|
10
9
|
BalancerV3PoolStatus2[BalancerV3PoolStatus2["NOT_ALLOWED"] = 0] = "NOT_ALLOWED";
|
|
@@ -72,23 +71,23 @@ class BalancerV3RouterAdapterContract extends AbstractAdapterContract {
|
|
|
72
71
|
}))
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
|
-
|
|
74
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
76
75
|
switch (decoded.functionName) {
|
|
77
76
|
case "swapSingleTokenDiffIn": {
|
|
78
77
|
const [, tokenIn, , leftoverAmount] = decoded.args;
|
|
79
|
-
return
|
|
78
|
+
return [{ tokenIn, leftoverAmount }];
|
|
80
79
|
}
|
|
81
80
|
// BPT (pool token) is spent down to the leftover
|
|
82
81
|
case "removeLiquiditySingleTokenDiff": {
|
|
83
82
|
const [pool, leftoverAmount] = decoded.args;
|
|
84
|
-
return
|
|
83
|
+
return [{ tokenIn: pool, leftoverAmount }];
|
|
85
84
|
}
|
|
86
85
|
case "addLiquidityUnbalancedDiff":
|
|
87
86
|
throw new Error(
|
|
88
87
|
`previewBalanceChanges cannot resolve pool tokens for addLiquidityUnbalancedDiff on ${this.contractType} adapter at ${this.address}`
|
|
89
88
|
);
|
|
90
89
|
default:
|
|
91
|
-
return super.
|
|
90
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "viem";
|
|
5
5
|
import { MissingSerializedParamsError } from "../../../sdk/index.js";
|
|
6
6
|
import { iBalancerV3WrapperAbi } from "../abi/targetContractAbi.js";
|
|
7
|
-
import { clampToLeftover } from "../balanceChanges.js";
|
|
8
7
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
9
8
|
const abi = iBalancerV3WrapperAdapterAbi;
|
|
10
9
|
const protocolAbi = iBalancerV3WrapperAbi;
|
|
@@ -35,23 +34,19 @@ class BalancerV3WrapperAdapterContract extends AbstractAdapterContract {
|
|
|
35
34
|
balancerPoolToken: this.#balancerPoolToken ? this.labelAddress(this.#balancerPoolToken) : void 0
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
|
|
37
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
39
38
|
switch (decoded.functionName) {
|
|
40
39
|
// mint spends the pool token, burn spends the wrapper (target contract)
|
|
41
40
|
case "mintDiff": {
|
|
42
41
|
const [leftoverAmount] = decoded.args;
|
|
43
|
-
return
|
|
44
|
-
balances,
|
|
45
|
-
this.balancerPoolToken,
|
|
46
|
-
leftoverAmount
|
|
47
|
-
);
|
|
42
|
+
return [{ tokenIn: this.balancerPoolToken, leftoverAmount }];
|
|
48
43
|
}
|
|
49
44
|
case "burnDiff": {
|
|
50
45
|
const [leftoverAmount] = decoded.args;
|
|
51
|
-
return
|
|
46
|
+
return [{ tokenIn: this.targetContract, leftoverAmount }];
|
|
52
47
|
}
|
|
53
48
|
default:
|
|
54
|
-
return super.
|
|
49
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
}
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
} from "viem";
|
|
5
5
|
import { MissingSerializedParamsError } from "../../../sdk/index.js";
|
|
6
6
|
import { iCamelotV3RouterAbi } from "../abi/targetContractAbi.js";
|
|
7
|
-
import { clampToLeftover } from "../balanceChanges.js";
|
|
8
7
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
9
8
|
const abi = iCamelotV3AdapterAbi;
|
|
10
9
|
const protocolAbi = iCamelotV3RouterAbi;
|
|
@@ -48,19 +47,24 @@ class CamelotV3AdapterContract extends AbstractAdapterContract {
|
|
|
48
47
|
}))
|
|
49
48
|
};
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
52
51
|
switch (decoded.functionName) {
|
|
53
52
|
case "exactDiffInputSingle": {
|
|
54
53
|
const [params] = decoded.args;
|
|
55
|
-
return
|
|
54
|
+
return [
|
|
55
|
+
{
|
|
56
|
+
tokenIn: params.tokenIn,
|
|
57
|
+
leftoverAmount: params.leftoverAmount
|
|
58
|
+
}
|
|
59
|
+
];
|
|
56
60
|
}
|
|
57
61
|
case "exactDiffInput": {
|
|
58
62
|
const [params] = decoded.args;
|
|
59
63
|
const tokenIn = `0x${params.path.replace("0x", "").slice(0, 40)}`;
|
|
60
|
-
return
|
|
64
|
+
return [{ tokenIn, leftoverAmount: params.leftoverAmount }];
|
|
61
65
|
}
|
|
62
66
|
default:
|
|
63
|
-
return super.
|
|
67
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
MissingSerializedParamsError
|
|
8
8
|
} from "../../../sdk/index.js";
|
|
9
9
|
import { iBaseRewardPoolAbi } from "../abi/targetContractAbi.js";
|
|
10
|
-
import { clampToLeftover, copyBalances } from "../balanceChanges.js";
|
|
11
10
|
import {
|
|
12
11
|
allTransfersAsTokenAmounts,
|
|
13
12
|
fnSigToName,
|
|
@@ -117,26 +116,22 @@ class ConvexV1BaseRewardPoolAdapterContract extends AbstractAdapterContract {
|
|
|
117
116
|
withdrawAmount: swap.toAmount
|
|
118
117
|
};
|
|
119
118
|
}
|
|
120
|
-
|
|
119
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
121
120
|
switch (decoded.functionName) {
|
|
122
121
|
case "stakeDiff": {
|
|
123
122
|
const [leftoverAmount] = decoded.args;
|
|
124
|
-
return
|
|
123
|
+
return [{ tokenIn: this.stakingToken, leftoverAmount }];
|
|
125
124
|
}
|
|
126
125
|
case "withdrawDiff":
|
|
127
126
|
case "withdrawDiffAndUnwrap": {
|
|
128
127
|
const [leftoverAmount] = decoded.args;
|
|
129
|
-
return
|
|
130
|
-
balances,
|
|
131
|
-
this.stakedPhantomToken,
|
|
132
|
-
leftoverAmount
|
|
133
|
-
);
|
|
128
|
+
return [{ tokenIn: this.stakedPhantomToken, leftoverAmount }];
|
|
134
129
|
}
|
|
135
130
|
// no accrued rewards on a freshly opened account
|
|
136
131
|
case "getReward":
|
|
137
|
-
return
|
|
132
|
+
return [];
|
|
138
133
|
default:
|
|
139
|
-
return super.
|
|
134
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
140
135
|
}
|
|
141
136
|
}
|
|
142
137
|
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from "../../../sdk/index.js";
|
|
7
7
|
import { iConvexV1BoosterAdapterAbi } from "../abi/iConvexV1BoosterAdapter.js";
|
|
8
8
|
import { iBoosterAbi } from "../abi/targetContractAbi.js";
|
|
9
|
-
import { clampToLeftover } from "../balanceChanges.js";
|
|
10
9
|
import { fnSigToName, swapFromTransfers } from "../transferHelpers.js";
|
|
11
10
|
import { AbstractAdapterContract } from "./AbstractAdapter.js";
|
|
12
11
|
const abi = iConvexV1BoosterAdapterAbi;
|
|
@@ -84,21 +83,21 @@ class ConvexV1BoosterAdapterContract extends AbstractAdapterContract {
|
|
|
84
83
|
}
|
|
85
84
|
return super.classifyLegacyOperation(parsed, transfers);
|
|
86
85
|
}
|
|
87
|
-
|
|
86
|
+
decodeDiffLeftovers(decoded, balances) {
|
|
88
87
|
switch (decoded.functionName) {
|
|
89
88
|
// deposit spends the curve LP token, withdraw spends the convex token
|
|
90
89
|
case "depositDiff": {
|
|
91
90
|
const [pid, leftoverAmount] = decoded.args;
|
|
92
91
|
const pool = this.#mustFindPool(Number(pid));
|
|
93
|
-
return
|
|
92
|
+
return [{ tokenIn: pool.curveToken, leftoverAmount }];
|
|
94
93
|
}
|
|
95
94
|
case "withdrawDiff": {
|
|
96
95
|
const [pid, leftoverAmount] = decoded.args;
|
|
97
96
|
const pool = this.#mustFindPool(Number(pid));
|
|
98
|
-
return
|
|
97
|
+
return [{ tokenIn: pool.convexToken, leftoverAmount }];
|
|
99
98
|
}
|
|
100
99
|
default:
|
|
101
|
-
return super.
|
|
100
|
+
return super.decodeDiffLeftovers(decoded, balances);
|
|
102
101
|
}
|
|
103
102
|
}
|
|
104
103
|
#mustFindPool(pid) {
|