forked from balancer/balancer-v2-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockManagedPoolSettings.sol
157 lines (128 loc) · 5.21 KB
/
MockManagedPoolSettings.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
import "@balancer-labs/v2-pool-utils/contracts/RecoveryModeHelper.sol";
import "../managed/ManagedPoolSettings.sol";
import "../ExternalWeightedMath.sol";
contract MockManagedPoolSettings is ManagedPoolSettings {
using WeightedPoolUserData for bytes;
ExternalWeightedMath private immutable _weightedMath;
RecoveryModeHelper private immutable _recoveryModeHelper;
constructor(
ManagedPoolSettingsParams memory settingsParams,
IVault vault,
IProtocolFeePercentagesProvider protocolFeeProvider,
ExternalWeightedMath weightedMath,
RecoveryModeHelper recoveryModeHelper,
address[] memory assetManagers,
address owner
)
NewBasePool(
vault,
PoolRegistrationLib.registerPoolWithAssetManagers(
vault,
IVault.PoolSpecialization.MINIMAL_SWAP_INFO,
settingsParams.tokens,
assetManagers
),
"MockManagedPoolName",
"MockManagedPoolSymbol",
90 days,
30 days,
owner
)
ManagedPoolSettings(settingsParams, protocolFeeProvider)
{
_weightedMath = weightedMath;
_recoveryModeHelper = recoveryModeHelper;
}
function getVirtualSupply() external view returns (uint256) {
return _getVirtualSupply();
}
function _onInitializePool(
address,
address,
bytes memory userData
) internal override returns (uint256, uint256[] memory) {
WeightedPoolUserData.JoinKind kind = userData.joinKind();
_require(kind == WeightedPoolUserData.JoinKind.INIT, Errors.UNINITIALIZED);
(IERC20[] memory tokens, ) = _getPoolTokens();
uint256[] memory amountsIn = userData.initialAmountsIn();
InputHelpers.ensureInputLengthMatch(amountsIn.length, tokens.length);
uint256[] memory scalingFactors = _scalingFactors(tokens);
_upscaleArray(amountsIn, scalingFactors);
uint256 invariantAfterJoin = _weightedMath.calculateInvariant(_getNormalizedWeights(tokens), amountsIn);
// Set the initial BPT to the value of the invariant times the number of tokens. This makes BPT supply more
// consistent in Pools with similar compositions but different number of tokens.
uint256 bptAmountOut = Math.mul(invariantAfterJoin, amountsIn.length);
// We want to start collecting AUM fees from this point onwards. Prior to initialization the Pool holds no funds
// so naturally charges no AUM fees.
_updateAumFeeCollectionTimestamp();
// amountsIn are amounts entering the Pool, so we round up.
_downscaleUpArray(amountsIn, scalingFactors);
return (bptAmountOut, amountsIn);
}
function isOwnerOnlyAction(bytes32 actionId) external view returns (bool) {
return _isOwnerOnlyAction(actionId);
}
function validateSwapFeePercentage(uint256 swapFeePercentage) external pure {
_validateSwapFeePercentage(swapFeePercentage);
}
function isAllowedAddress(address member) external view returns (bool) {
return _isAllowedAddress(_getPoolState(), member);
}
// Pure virtual functions
function _getVirtualSupply() internal view override returns (uint256) {
return totalSupply();
}
function _getPoolTokens() internal view override returns (IERC20[] memory tokens, uint256[] memory balances) {
(tokens, balances, ) = getVault().getPoolTokens(getPoolId());
}
// Unimplemented
function _doRecoveryModeExit(
uint256[] memory,
uint256,
bytes memory
) internal pure override returns (uint256, uint256[] memory) {
_revert(Errors.UNIMPLEMENTED);
}
function _onSwapMinimal(
SwapRequest memory,
uint256,
uint256
) internal pure override returns (uint256) {
_revert(Errors.UNIMPLEMENTED);
}
function _onJoinPool(
address,
uint256[] memory,
bytes memory
) internal virtual override returns (uint256, uint256[] memory) {
_revert(Errors.UNIMPLEMENTED);
}
function _onExitPool(
address,
uint256[] memory,
bytes memory
) internal virtual override returns (uint256, uint256[] memory) {
_revert(Errors.UNIMPLEMENTED);
}
function _onSwapGeneral(
SwapRequest memory,
uint256[] memory,
uint256,
uint256
) internal pure override returns (uint256) {
_revert(Errors.UNIMPLEMENTED);
}
}