diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..07216f0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,97 @@ +Business Source License 1.1 + +License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. +"Business Source License" is a trademark of MariaDB Corporation Ab. + +----------------------------------------------------------------------------- + +Parameters + +Licensor: Vsevolod Grigorovich + +Licensed Work: Tetu + +Additional Use Grant: None + +Change Date: 2033-01-01 + +Change License: GNU General Public License v2.0 or later + +----------------------------------------------------------------------------- + +Terms + +The Licensor hereby grants you the right to copy, modify, create derivative +works, redistribute, and make non-production use of the Licensed Work. The +Licensor may make an Additional Use Grant, above, permitting limited +production use. + +Effective on the Change Date, or the fourth anniversary of the first publicly +available distribution of a specific version of the Licensed Work under this +License, whichever comes first, the Licensor hereby grants you rights under +the terms of the Change License, and the rights granted in the paragraph +above terminate. + +If your use of the Licensed Work does not comply with the requirements +currently in effect as described in this License, you must purchase a +commercial license from the Licensor, its affiliated entities, or authorized +resellers, or you must refrain from using the Licensed Work. + +All copies of the original and modified Licensed Work, and derivative works +of the Licensed Work, are subject to this License. This License applies +separately for each version of the Licensed Work and the Change Date may vary +for each version of the Licensed Work released by Licensor. + +You must conspicuously display this License on each original or modified copy +of the Licensed Work. If you receive the Licensed Work in original or +modified form from a third party, the terms and conditions set forth in this +License apply to your use of that work. + +Any use of the Licensed Work in violation of this License will automatically +terminate your rights under this License for the current and all other +versions of the Licensed Work. + +This License does not grant you any right in any trademark or logo of +Licensor or its affiliates (provided that you may use a trademark or logo of +Licensor as expressly required by this License). + +TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +TITLE. + +MariaDB hereby grants you permission to use this License’s text to license +your works, and to refer to it using the trademark "Business Source License", +as long as you comply with the Covenants of Licensor below. + +----------------------------------------------------------------------------- + +Covenants of Licensor + +In consideration of the right to use this License’s text and the "Business +Source License" name and trademark, Licensor covenants to MariaDB, and to all +other recipients of the licensed work to be provided by Licensor: + +1. To specify as the Change License the GPL Version 2.0 or any later version, + or a license that is compatible with GPL Version 2.0 or a later version, + where "compatible" means that software provided under the Change License can + be included in a program with software provided under GPL Version 2.0 or a + later version. Licensor may specify additional Change Licenses without + limitation. + +2. To either: (a) specify an additional grant of rights to use that does not + impose any additional restriction on the right granted in this License, as + the Additional Use Grant; or (b) insert the text "None". + +3. To specify a Change Date. + +4. Not to modify this License in any other way. + +----------------------------------------------------------------------------- + +Notice + +The Business Source License (this document, or the "License") is not an Open +Source license. However, the Licensed Work will eventually be made available +under an Open Source License, as stated in this License. diff --git a/contracts/TetuBridgedProcessing.sol b/contracts/TetuBridgedProcessing.sol index 4918c1b..edf5a71 100644 --- a/contracts/TetuBridgedProcessing.sol +++ b/contracts/TetuBridgedProcessing.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/TetuTokenMainnet.sol b/contracts/TetuTokenMainnet.sol index e580493..a8d4ffb 100644 --- a/contracts/TetuTokenMainnet.sol +++ b/contracts/TetuTokenMainnet.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/infrastructure/ControllerV2.sol b/contracts/infrastructure/ControllerV2.sol index 4cc6ff6..dc131f3 100644 --- a/contracts/infrastructure/ControllerV2.sol +++ b/contracts/infrastructure/ControllerV2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/infrastructure/ForwarderV3.sol b/contracts/infrastructure/ForwarderV3.sol index 709d91c..ff09146 100644 --- a/contracts/infrastructure/ForwarderV3.sol +++ b/contracts/infrastructure/ForwarderV3.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/infrastructure/InvestFundV2.sol b/contracts/infrastructure/InvestFundV2.sol index 067443b..da21c3f 100644 --- a/contracts/infrastructure/InvestFundV2.sol +++ b/contracts/infrastructure/InvestFundV2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/infrastructure/PlatformVoter.sol b/contracts/infrastructure/PlatformVoter.sol index 568cb1d..4222a96 100644 --- a/contracts/infrastructure/PlatformVoter.sol +++ b/contracts/infrastructure/PlatformVoter.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/interfaces/ISmartVault.sol b/contracts/interfaces/ISmartVault.sol index a840d21..8510a51 100644 --- a/contracts/interfaces/ISmartVault.sol +++ b/contracts/interfaces/ISmartVault.sol @@ -1,14 +1,4 @@ -// SPDX-License-Identifier: ISC -/** -* By using this software, you understand, acknowledge and accept that Tetu -* and/or the underlying software are provided “as is” and “as available” -* basis and without warranties or representations of any kind either expressed -* or implied. Any use of this open source software released under the ISC -* Internet Systems Consortium license is done at your own risk to the fullest -* extent permissible pursuant to applicable law any and all liability as well -* as all warranties, including any fitness for a particular purpose with respect -* to Tetu and/or the underlying software and the use thereof are disclaimed. -*/ +// SPDX-License-Identifier: MIT pragma solidity 0.8.17; diff --git a/contracts/lib/FixedPointMathLib.sol b/contracts/lib/FixedPointMathLib.sol deleted file mode 100644 index 20fb62a..0000000 --- a/contracts/lib/FixedPointMathLib.sol +++ /dev/null @@ -1,230 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -pragma solidity 0.8.17; - -/// @notice Arithmetic library with operations for fixed-point numbers. -/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol) -/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol) -library FixedPointMathLib { - /*////////////////////////////////////////////////////////////// - //SIMPLIFIED FIXED POINT OPERATIONS - //////////////////////////////////////////////////////////////*/ - - uint internal constant WAD = 1e18; // The scalar of ETH and most ERC20s. - - function mulWadDown(uint x, uint y) internal pure returns (uint) { - return mulDivDown(x, y, WAD); - // Equivalent to (x * y) / WAD rounded down. - } - - function mulWadUp(uint x, uint y) internal pure returns (uint) { - return mulDivUp(x, y, WAD); - // Equivalent to (x * y) / WAD rounded up. - } - - function divWadDown(uint x, uint y) internal pure returns (uint) { - return mulDivDown(x, WAD, y); - // Equivalent to (x * WAD) / y rounded down. - } - - function divWadUp(uint x, uint y) internal pure returns (uint) { - return mulDivUp(x, WAD, y); - // Equivalent to (x * WAD) / y rounded up. - } - - function positiveInt128(int128 value) internal pure returns (int128) { - return value < 0 ? int128(0) : value; - } - - /*////////////////////////////////////////////////////////////// - //LOW LEVEL FIXED POINT OPERATIONS - //////////////////////////////////////////////////////////////*/ - - function mulDivDown( - uint x, - uint y, - uint denominator - ) internal pure returns (uint z) { - assembly { - // Store x * y in z for now. - z := mul(x, y) - - // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) - if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { - revert(0, 0) - } - - // Divide z by the denominator. - z := div(z, denominator) - } - } - - function mulDivUp( - uint x, - uint y, - uint denominator - ) internal pure returns (uint z) { - assembly { - // Store x * y in z for now. - z := mul(x, y) - - // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) - if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { - revert(0, 0) - } - - // First, divide z - 1 by the denominator and add 1. - // We allow z - 1 to underflow if z is 0, because we multiply the - // end result by 0 if z is zero, ensuring we return 0 if z is zero. - z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1)) - } - } - - function rpow( - uint x, - uint n, - uint scalar - ) internal pure returns (uint z) { - assembly { - switch x - case 0 { - switch n - case 0 { - // 0 ** 0 = 1 - z := scalar - } - default { - // 0 ** n = 0 - z := 0 - } - } - default { - switch mod(n, 2) - case 0 { - // If n is even, store scalar in z for now. - z := scalar - } - default { - // If n is odd, store x in z for now. - z := x - } - - // Shifting right by 1 is like dividing by 2. - let half := shr(1, scalar) - - for { - // Shift n right by 1 before looping to halve it. - n := shr(1, n) - } n { - // Shift n right by 1 each iteration to halve it. - n := shr(1, n) - } { - // Revert immediately if x ** 2 would overflow. - // Equivalent to iszero(eq(div(xx, x), x)) here. - if shr(128, x) { - revert(0, 0) - } - - // Store x squared. - let xx := mul(x, x) - - // Round to the nearest number. - let xxRound := add(xx, half) - - // Revert if xx + half overflowed. - if lt(xxRound, xx) { - revert(0, 0) - } - - // Set x to scaled xxRound. - x := div(xxRound, scalar) - - // If n is even: - if mod(n, 2) { - // Compute z * x. - let zx := mul(z, x) - - // If z * x overflowed: - if iszero(eq(div(zx, x), z)) { - // Revert if x is non-zero. - if iszero(iszero(x)) { - revert(0, 0) - } - } - - // Round to the nearest number. - let zxRound := add(zx, half) - - // Revert if zx + half overflowed. - if lt(zxRound, zx) { - revert(0, 0) - } - - // Return properly scaled zxRound. - z := div(zxRound, scalar) - } - } - } - } - } - - /*////////////////////////////////////////////////////////////// - // GENERAL NUMBER UTILITIES - //////////////////////////////////////////////////////////////*/ - - function sqrt(uint x) internal pure returns (uint z) { - assembly { - // Start off with z at 1. - z := 1 - - // Used below to help find a nearby power of 2. - let y := x - - // Find the lowest power of 2 that is at least sqrt(x). - if iszero(lt(y, 0x100000000000000000000000000000000)) { - y := shr(128, y) // Like dividing by 2 ** 128. - z := shl(64, z) // Like multiplying by 2 ** 64. - } - if iszero(lt(y, 0x10000000000000000)) { - y := shr(64, y) // Like dividing by 2 ** 64. - z := shl(32, z) // Like multiplying by 2 ** 32. - } - if iszero(lt(y, 0x100000000)) { - y := shr(32, y) // Like dividing by 2 ** 32. - z := shl(16, z) // Like multiplying by 2 ** 16. - } - if iszero(lt(y, 0x10000)) { - y := shr(16, y) // Like dividing by 2 ** 16. - z := shl(8, z) // Like multiplying by 2 ** 8. - } - if iszero(lt(y, 0x100)) { - y := shr(8, y) // Like dividing by 2 ** 8. - z := shl(4, z) // Like multiplying by 2 ** 4. - } - if iszero(lt(y, 0x10)) { - y := shr(4, y) // Like dividing by 2 ** 4. - z := shl(2, z) // Like multiplying by 2 ** 2. - } - if iszero(lt(y, 0x8)) { - // Equivalent to 2 ** z. - z := shl(1, z) - } - - // Shifting right by 1 is like dividing by 2. - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - z := shr(1, add(z, div(x, z))) - - // Compute a rounded down version of z. - let zRoundDown := div(x, z) - - // If zRoundDown is smaller, use it. - if lt(zRoundDown, z) { - z := zRoundDown - } - } - } -} diff --git a/contracts/lib/InterfaceIds.sol b/contracts/lib/InterfaceIds.sol index 610aea3..423da7e 100644 --- a/contracts/lib/InterfaceIds.sol +++ b/contracts/lib/InterfaceIds.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/lib/SlotsLib.sol b/contracts/lib/SlotsLib.sol index a5be6ab..8cfefc2 100644 --- a/contracts/lib/SlotsLib.sol +++ b/contracts/lib/SlotsLib.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/lib/StringLib.sol b/contracts/lib/StringLib.sol index 2a9bf6e..107ce4a 100644 --- a/contracts/lib/StringLib.sol +++ b/contracts/lib/StringLib.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/proxy/ControllableV3.sol b/contracts/proxy/ControllableV3.sol index d1f3afb..425b56d 100644 --- a/contracts/proxy/ControllableV3.sol +++ b/contracts/proxy/ControllableV3.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/proxy/ProxyControlled.sol b/contracts/proxy/ProxyControlled.sol index 36cfd11..4484cd3 100644 --- a/contracts/proxy/ProxyControlled.sol +++ b/contracts/proxy/ProxyControlled.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/reward/MultiBribe.sol b/contracts/reward/MultiBribe.sol index b64f4d9..6b5deb7 100644 --- a/contracts/reward/MultiBribe.sol +++ b/contracts/reward/MultiBribe.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/reward/MultiGauge.sol b/contracts/reward/MultiGauge.sol index 767246f..797fa00 100644 --- a/contracts/reward/MultiGauge.sol +++ b/contracts/reward/MultiGauge.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/reward/StakelessMultiPoolBase.sol b/contracts/reward/StakelessMultiPoolBase.sol index a46b813..3ebc887 100644 --- a/contracts/reward/StakelessMultiPoolBase.sol +++ b/contracts/reward/StakelessMultiPoolBase.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/strategy/StrategyBaseV2.sol b/contracts/strategy/StrategyBaseV2.sol index 711ef8a..8599fd0 100644 --- a/contracts/strategy/StrategyBaseV2.sol +++ b/contracts/strategy/StrategyBaseV2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../interfaces/IStrategyV2.sol"; diff --git a/contracts/strategy/StrategyBaseV3.sol b/contracts/strategy/StrategyBaseV3.sol index f881e1c..2daef23 100644 --- a/contracts/strategy/StrategyBaseV3.sol +++ b/contracts/strategy/StrategyBaseV3.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../interfaces/IStrategyV3.sol"; diff --git a/contracts/strategy/StrategyLib.sol b/contracts/strategy/StrategyLib.sol index b7809c9..ec616fd 100644 --- a/contracts/strategy/StrategyLib.sol +++ b/contracts/strategy/StrategyLib.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/strategy/StrategyLib2.sol b/contracts/strategy/StrategyLib2.sol index d487835..4a9f37c 100644 --- a/contracts/strategy/StrategyLib2.sol +++ b/contracts/strategy/StrategyLib2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/strategy/StrategyStrictBase.sol b/contracts/strategy/StrategyStrictBase.sol index 86bffe3..e427953 100644 --- a/contracts/strategy/StrategyStrictBase.sol +++ b/contracts/strategy/StrategyStrictBase.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../openzeppelin/SafeERC20.sol"; diff --git a/contracts/test/Base64Test.sol b/contracts/test/Base64Test.sol index a441524..a91e04c 100644 --- a/contracts/test/Base64Test.sol +++ b/contracts/test/Base64Test.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/ControllableTest.sol b/contracts/test/ControllableTest.sol index b00fc08..2954f05 100644 --- a/contracts/test/ControllableTest.sol +++ b/contracts/test/ControllableTest.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/ControllerMinimal.sol b/contracts/test/ControllerMinimal.sol index 66b5c32..efdc783 100644 --- a/contracts/test/ControllerMinimal.sol +++ b/contracts/test/ControllerMinimal.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/FixedPointMathLibTest.sol b/contracts/test/FixedPointMathLibTest.sol deleted file mode 100644 index e653000..0000000 --- a/contracts/test/FixedPointMathLibTest.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.8.17; - -import "../lib/FixedPointMathLib.sol"; - -contract FixedPointMathLibTest { - - function mulWadDown(uint x, uint y) external pure returns (uint) { - return FixedPointMathLib.mulWadDown(x, y); - } - - function mulWadUp(uint x, uint y) external pure returns (uint) { - return FixedPointMathLib.mulWadUp(x, y); - } - - function rpow( - uint x, - uint n, - uint scalar - ) external pure returns (uint) { - return FixedPointMathLib.rpow(x, n, scalar); - } - - function sqrt(uint x) external pure returns (uint) { - return FixedPointMathLib.sqrt(x); - } - -} diff --git a/contracts/test/IMockToken.sol b/contracts/test/IMockToken.sol index 91e26a1..a4fc73d 100644 --- a/contracts/test/IMockToken.sol +++ b/contracts/test/IMockToken.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockBribe.sol b/contracts/test/MockBribe.sol index d618d5d..b6e5bea 100644 --- a/contracts/test/MockBribe.sol +++ b/contracts/test/MockBribe.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockForwarder.sol b/contracts/test/MockForwarder.sol index d7e694e..d345ac8 100644 --- a/contracts/test/MockForwarder.sol +++ b/contracts/test/MockForwarder.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockGauge.sol b/contracts/test/MockGauge.sol index 03344de..03c30b4 100644 --- a/contracts/test/MockGauge.sol +++ b/contracts/test/MockGauge.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockLiquidator.sol b/contracts/test/MockLiquidator.sol index a978ec1..51d4d9e 100644 --- a/contracts/test/MockLiquidator.sol +++ b/contracts/test/MockLiquidator.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockPawnshop.sol b/contracts/test/MockPawnshop.sol index 34e6bc8..1ef1fa9 100644 --- a/contracts/test/MockPawnshop.sol +++ b/contracts/test/MockPawnshop.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockPool.sol b/contracts/test/MockPool.sol index 1a361ec..539b2cf 100644 --- a/contracts/test/MockPool.sol +++ b/contracts/test/MockPool.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockSplitter.sol b/contracts/test/MockSplitter.sol index f91f5b1..71a2009 100644 --- a/contracts/test/MockSplitter.sol +++ b/contracts/test/MockSplitter.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockStakingToken.sol b/contracts/test/MockStakingToken.sol index ca643f3..b9468c4 100644 --- a/contracts/test/MockStakingToken.sol +++ b/contracts/test/MockStakingToken.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockStrategy.sol b/contracts/test/MockStrategy.sol index c6c972a..4aceae4 100644 --- a/contracts/test/MockStrategy.sol +++ b/contracts/test/MockStrategy.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockStrategySimple.sol b/contracts/test/MockStrategySimple.sol index 24e3be6..f3bc54d 100644 --- a/contracts/test/MockStrategySimple.sol +++ b/contracts/test/MockStrategySimple.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockStrategyStrict.sol b/contracts/test/MockStrategyStrict.sol index 0763657..a1495c7 100644 --- a/contracts/test/MockStrategyStrict.sol +++ b/contracts/test/MockStrategyStrict.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockStrategyV3.sol b/contracts/test/MockStrategyV3.sol index 6425df3..6b780a3 100644 --- a/contracts/test/MockStrategyV3.sol +++ b/contracts/test/MockStrategyV3.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockToken.sol b/contracts/test/MockToken.sol index 7c0be5b..28bbfe6 100644 --- a/contracts/test/MockToken.sol +++ b/contracts/test/MockToken.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockVault.sol b/contracts/test/MockVault.sol index bb96c98..8a74048 100644 --- a/contracts/test/MockVault.sol +++ b/contracts/test/MockVault.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; @@ -6,7 +6,7 @@ import "../proxy/ControllableV3.sol"; import "../vault/ERC4626Upgradeable.sol"; contract MockVault is ERC4626Upgradeable, ControllableV3 { - using FixedPointMathLib for uint; + using Math for uint; using SafeERC20 for IERC20; uint constant public FEE_DENOMINATOR = 100; @@ -45,7 +45,7 @@ contract MockVault is ERC4626Upgradeable, ControllableV3 { function previewMint(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); if (supply != 0) { - uint assets = shares.mulDivUp(totalAssets(), supply); + uint assets = shares.mulDiv(totalAssets(), supply, Math.Rounding.Up); return assets * FEE_DENOMINATOR / (FEE_DENOMINATOR - fee); } else { return shares * FEE_DENOMINATOR / (FEE_DENOMINATOR - fee); @@ -58,7 +58,7 @@ contract MockVault is ERC4626Upgradeable, ControllableV3 { if (_totalAssets == 0) { return assets; } - uint shares = assets.mulDivUp(supply, _totalAssets); + uint shares = assets.mulDiv(supply, _totalAssets, Math.Rounding.Up); shares = shares * FEE_DENOMINATOR / (FEE_DENOMINATOR - fee); return supply == 0 ? assets : shares; } diff --git a/contracts/test/MockVaultSimple.sol b/contracts/test/MockVaultSimple.sol index 37face6..8f1c49e 100644 --- a/contracts/test/MockVaultSimple.sol +++ b/contracts/test/MockVaultSimple.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockVeDist.sol b/contracts/test/MockVeDist.sol index 3d55a87..4573d87 100644 --- a/contracts/test/MockVeDist.sol +++ b/contracts/test/MockVeDist.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/MockVoter.sol b/contracts/test/MockVoter.sol index dcbf522..1215f5c 100644 --- a/contracts/test/MockVoter.sol +++ b/contracts/test/MockVoter.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/Multicall.sol b/contracts/test/Multicall.sol index 8a5e6a2..dd1d2d5 100644 --- a/contracts/test/Multicall.sol +++ b/contracts/test/Multicall.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/SlotsTest.sol b/contracts/test/SlotsTest.sol index 3c98250..e036311 100644 --- a/contracts/test/SlotsTest.sol +++ b/contracts/test/SlotsTest.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/StakelessMultiPoolMock.sol b/contracts/test/StakelessMultiPoolMock.sol index 4b814b6..3ef0a03 100644 --- a/contracts/test/StakelessMultiPoolMock.sol +++ b/contracts/test/StakelessMultiPoolMock.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/test/StrategyV2BaseEmpty.sol b/contracts/test/StrategyV2BaseEmpty.sol index e13dd67..4fa4aa8 100644 --- a/contracts/test/StrategyV2BaseEmpty.sol +++ b/contracts/test/StrategyV2BaseEmpty.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../strategy/StrategyBaseV2.sol"; @@ -29,4 +29,4 @@ contract StrategyV2BaseEmpty is StrategyBaseV2 { function isReadyToHardWork() external view returns (bool) {} function investedAssets() public view virtual override returns (uint) {} -} \ No newline at end of file +} diff --git a/contracts/test/StrategyV3BaseEmpty.sol b/contracts/test/StrategyV3BaseEmpty.sol index 3ee5b63..25d745d 100644 --- a/contracts/test/StrategyV3BaseEmpty.sol +++ b/contracts/test/StrategyV3BaseEmpty.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../strategy/StrategyBaseV3.sol"; @@ -29,4 +29,4 @@ contract StrategyV3BaseEmpty is StrategyBaseV3 { function isReadyToHardWork() external view returns (bool) {} function investedAssets() public view virtual override returns (uint) {} -} \ No newline at end of file +} diff --git a/contracts/test/StringLibFacade.sol b/contracts/test/StringLibFacade.sol index 9657765..f12a8af 100644 --- a/contracts/test/StringLibFacade.sol +++ b/contracts/test/StringLibFacade.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../lib/StringLib.sol"; diff --git a/contracts/test/TetuERC165Test.sol b/contracts/test/TetuERC165Test.sol index b371580..a3453b6 100644 --- a/contracts/test/TetuERC165Test.sol +++ b/contracts/test/TetuERC165Test.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../tools/TetuERC165.sol"; diff --git a/contracts/test/WrongNFTReceiver.sol b/contracts/test/WrongNFTReceiver.sol index 3bf3f71..75af6dd 100644 --- a/contracts/test/WrongNFTReceiver.sol +++ b/contracts/test/WrongNFTReceiver.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/BribeDistribution.sol b/contracts/tools/BribeDistribution.sol index ddbc045..e2ca6b3 100644 --- a/contracts/tools/BribeDistribution.sol +++ b/contracts/tools/BribeDistribution.sol @@ -1,9 +1,9 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../interfaces/IERC20.sol"; -import "../interfaces/IBribe.sol"; +import "../interfaces/IVeDistributor.sol"; contract BribeDistribution { @@ -13,14 +13,12 @@ contract BribeDistribution { address public pendingOwner; address public operator; - IBribe public immutable bribe; - address public immutable vault; + IVeDistributor public immutable veDist; address public immutable token; uint public round; - constructor(address bribe_, address _vault, address _token) { - bribe = IBribe(bribe_); - vault = _vault; + constructor(address veDist_, address _token) { + veDist = IVeDistributor(veDist_); token = _token; owner = msg.sender; } @@ -65,22 +63,19 @@ contract BribeDistribution { IERC20(token).transferFrom(msg.sender, address(this), amount); } - uint toBribes = IERC20(token).balanceOf(address(this)); - require(toBribes != 0, "ZERO_BALANCE"); + uint toRewards = IERC20(token).balanceOf(address(this)); + require(toRewards != 0, "ZERO_BALANCE"); // assume we will have bribes once per 2 weeks. Need to use a half of the current balance in case of start of new 2 weeks epoch. if (fresh) { - toBribes = toBribes / 2; + toRewards = toRewards / 2; } - _approveIfNeed(token, address(bribe), toBribes); - bribe.notifyForNextEpoch(vault, token, toBribes); - } + IVeDistributor _veDist = veDist; - function _approveIfNeed(address _token, address dst, uint amount) internal { - if (IERC20(_token).allowance(address(this), dst) < amount) { - IERC20(_token).approve(dst, type(uint).max); - } + IERC20(token).transfer(address(_veDist), toRewards); + _veDist.checkpoint(); + _veDist.checkpointTotalSupply(); } } diff --git a/contracts/tools/DepositHelper.sol b/contracts/tools/DepositHelper.sol index 7897a29..f9fc193 100644 --- a/contracts/tools/DepositHelper.sol +++ b/contracts/tools/DepositHelper.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/ForwarderDistributeResolver.sol b/contracts/tools/ForwarderDistributeResolver.sol index eace5bd..743658b 100644 --- a/contracts/tools/ForwarderDistributeResolver.sol +++ b/contracts/tools/ForwarderDistributeResolver.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/HardWorkResolver.sol b/contracts/tools/HardWorkResolver.sol index be53e60..cf41394 100644 --- a/contracts/tools/HardWorkResolver.sol +++ b/contracts/tools/HardWorkResolver.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/PerfFeeTreasury.sol b/contracts/tools/PerfFeeTreasury.sol index e6e1b2c..c19d997 100644 --- a/contracts/tools/PerfFeeTreasury.sol +++ b/contracts/tools/PerfFeeTreasury.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/RewardsRedirector.sol b/contracts/tools/RewardsRedirector.sol index 95b4569..6cae593 100644 --- a/contracts/tools/RewardsRedirector.sol +++ b/contracts/tools/RewardsRedirector.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/SplitterRebalanceResolver.sol b/contracts/tools/SplitterRebalanceResolver.sol index a99c585..cdea691 100644 --- a/contracts/tools/SplitterRebalanceResolver.sol +++ b/contracts/tools/SplitterRebalanceResolver.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/tools/TetuERC165.sol b/contracts/tools/TetuERC165.sol index 4f28194..0dfd200 100644 --- a/contracts/tools/TetuERC165.sol +++ b/contracts/tools/TetuERC165.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../openzeppelin/ERC165.sol"; diff --git a/contracts/vault/ERC4626.sol b/contracts/vault/ERC4626.sol index 78071f4..584cee1 100644 --- a/contracts/vault/ERC4626.sol +++ b/contracts/vault/ERC4626.sol @@ -1,20 +1,19 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../openzeppelin/ERC20Permit.sol"; import "../openzeppelin/SafeERC20.sol"; import "../openzeppelin/ReentrancyGuard.sol"; +import "../openzeppelin/Math.sol"; import "../interfaces/IERC4626.sol"; -import "../lib/FixedPointMathLib.sol"; /// @notice Minimal ERC4626 tokenized Vault implementation. -/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol) -/// @author belbix - adopted to proxy pattern + added ReentrancyGuard +/// @author belbix /// @author AlehNat - removed upgradeable logic abstract contract ERC4626 is ERC20Permit, ReentrancyGuard, IERC4626 { using SafeERC20 for IERC20; - using FixedPointMathLib for uint; + using Math for uint; /// @dev The address of the underlying token used for the Vault uses for accounting, /// depositing, and withdrawing @@ -143,13 +142,13 @@ abstract contract ERC4626 is ERC20Permit, ReentrancyGuard, IERC4626 { function convertToShares(uint assets) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); + return supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down); } function convertToAssets(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply); + return supply == 0 ? shares : shares.mulDiv(totalAssets(), supply, Math.Rounding.Down); } function previewDeposit(uint assets) public view virtual override returns (uint) { @@ -159,13 +158,13 @@ abstract contract ERC4626 is ERC20Permit, ReentrancyGuard, IERC4626 { function previewMint(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply); + return supply == 0 ? shares : shares.mulDiv(totalAssets(), supply, Math.Rounding.Up); } function previewWithdraw(uint assets) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets()); + return supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Up); } function previewRedeem(uint shares) public view virtual override returns (uint) { diff --git a/contracts/vault/ERC4626Strict.sol b/contracts/vault/ERC4626Strict.sol index 99740b8..e95ca33 100644 --- a/contracts/vault/ERC4626Strict.sol +++ b/contracts/vault/ERC4626Strict.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; @@ -8,7 +8,7 @@ import "../tools/TetuERC165.sol"; contract ERC4626Strict is ERC4626, TetuERC165 { using SafeERC20 for IERC20; - using FixedPointMathLib for uint; + using Math for uint; // ************************************************************* // CONSTANTS diff --git a/contracts/vault/ERC4626Upgradeable.sol b/contracts/vault/ERC4626Upgradeable.sol index c8cec28..0e9cd7d 100644 --- a/contracts/vault/ERC4626Upgradeable.sol +++ b/contracts/vault/ERC4626Upgradeable.sol @@ -1,19 +1,18 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; import "../openzeppelin/ERC20PermitUpgradeable.sol"; import "../openzeppelin/SafeERC20.sol"; import "../openzeppelin/ReentrancyGuard.sol"; +import "../openzeppelin/Math.sol"; import "../interfaces/IERC4626.sol"; -import "../lib/FixedPointMathLib.sol"; /// @notice Minimal ERC4626 tokenized Vault implementation. -/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol) -/// @author belbix - adopted to proxy pattern + added ReentrancyGuard +/// @author belbix abstract contract ERC4626Upgradeable is ERC20PermitUpgradeable, ReentrancyGuard, IERC4626 { using SafeERC20 for IERC20; - using FixedPointMathLib for uint; + using Math for uint; uint internal constant INITIAL_SHARES = 1000; address internal constant DEAD_ADDRESS = 0xdEad000000000000000000000000000000000000; @@ -159,13 +158,13 @@ abstract contract ERC4626Upgradeable is ERC20PermitUpgradeable, ReentrancyGuard, function convertToShares(uint assets) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); + return supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down); } function convertToAssets(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply); + return supply == 0 ? shares : shares.mulDiv(totalAssets(), supply, Math.Rounding.Down); } function previewDeposit(uint assets) public view virtual override returns (uint) { @@ -175,13 +174,13 @@ abstract contract ERC4626Upgradeable is ERC20PermitUpgradeable, ReentrancyGuard, function previewMint(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply); + return supply == 0 ? shares : shares.mulDiv(totalAssets(), supply, Math.Rounding.Up); } function previewWithdraw(uint assets) public view virtual override returns (uint) { uint supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero. - return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets()); + return supply == 0 ? assets : assets.mulDiv(supply, totalAssets(), Math.Rounding.Up); } function previewRedeem(uint shares) public view virtual override returns (uint) { diff --git a/contracts/vault/StrategySplitterV2.sol b/contracts/vault/StrategySplitterV2.sol index e8513a7..3123454 100644 --- a/contracts/vault/StrategySplitterV2.sol +++ b/contracts/vault/StrategySplitterV2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/vault/TetuVaultV2.sol b/contracts/vault/TetuVaultV2.sol index 296a291..4707d24 100644 --- a/contracts/vault/TetuVaultV2.sol +++ b/contracts/vault/TetuVaultV2.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; @@ -13,14 +13,14 @@ import "./ERC4626Upgradeable.sol"; /// @author belbix contract TetuVaultV2 is ERC4626Upgradeable, ControllableV3, ITetuVaultV2 { using SafeERC20 for IERC20; - using FixedPointMathLib for uint; + using Math for uint; // ************************************************************* // CONSTANTS // ************************************************************* /// @dev Version of this contract. Adjust manually on each code modification. - string public constant VAULT_VERSION = "2.1.4"; + string public constant VAULT_VERSION = "2.2.0"; /// @dev Denominator for buffer calculation. 100% of the buffer amount. uint constant public BUFFER_DENOMINATOR = 100_000; /// @dev Denominator for fee calculation. @@ -253,7 +253,7 @@ contract TetuVaultV2 is ERC4626Upgradeable, ControllableV3, ITetuVaultV2 { function previewMint(uint shares) public view virtual override returns (uint) { uint supply = totalSupply(); if (supply != 0) { - uint assets = shares.mulDivUp(totalAssets(), supply); + uint assets = shares.mulDiv(totalAssets(), supply, Math.Rounding.Up); return assets * FEE_DENOMINATOR / (FEE_DENOMINATOR - depositFee); } else { return shares * FEE_DENOMINATOR / (FEE_DENOMINATOR - depositFee); @@ -330,7 +330,7 @@ contract TetuVaultV2 is ERC4626Upgradeable, ControllableV3, ITetuVaultV2 { if (_totalAssets == 0) { return assets; } - uint shares = assets.mulDivUp(supply, _totalAssets); + uint shares = assets.mulDiv(supply, _totalAssets, Math.Rounding.Up); shares = shares * FEE_DENOMINATOR / (FEE_DENOMINATOR - withdrawFee); return supply == 0 ? assets : shares; } @@ -350,7 +350,7 @@ contract TetuVaultV2 is ERC4626Upgradeable, ControllableV3, ITetuVaultV2 { function maxWithdraw(address owner) public view override returns (uint) { uint assets = convertToAssets(balanceOf(owner)); - assets -= assets.mulDivUp(withdrawFee, FEE_DENOMINATOR); + assets -= assets.mulDiv(withdrawFee, FEE_DENOMINATOR, Math.Rounding.Up); return Math.min(maxWithdrawAssets, assets); } diff --git a/contracts/vault/VaultFactory.sol b/contracts/vault/VaultFactory.sol index 05af678..0ead11d 100644 --- a/contracts/vault/VaultFactory.sol +++ b/contracts/vault/VaultFactory.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/vault/VaultInsurance.sol b/contracts/vault/VaultInsurance.sol index ef5f3eb..820c69e 100644 --- a/contracts/vault/VaultInsurance.sol +++ b/contracts/vault/VaultInsurance.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/ve/TetuEmitter.sol b/contracts/ve/TetuEmitter.sol index d40e4b3..d8f9e76 100644 --- a/contracts/ve/TetuEmitter.sol +++ b/contracts/ve/TetuEmitter.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/ve/TetuVoter.sol b/contracts/ve/TetuVoter.sol index b88f019..2cdcadc 100644 --- a/contracts/ve/TetuVoter.sol +++ b/contracts/ve/TetuVoter.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/ve/VeDistributor.sol b/contracts/ve/VeDistributor.sol index a704da5..cdabc83 100644 --- a/contracts/ve/VeDistributor.sol +++ b/contracts/ve/VeDistributor.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; diff --git a/contracts/ve/VeTetu.sol b/contracts/ve/VeTetu.sol index d739288..dab992f 100644 --- a/contracts/ve/VeTetu.sol +++ b/contracts/ve/VeTetu.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; @@ -11,7 +11,6 @@ import "../interfaces/IController.sol"; import "../interfaces/IVoter.sol"; import "../interfaces/IPlatformVoter.sol"; import "../interfaces/ISmartVault.sol"; -import "../lib/FixedPointMathLib.sol"; import "../proxy/ControllableV3.sol"; import "./VeTetuLib.sol"; @@ -20,8 +19,7 @@ import "./VeTetuLib.sol"; /// @author belbix contract VeTetu is ControllableV3, ReentrancyGuard, IVeTetu { using SafeERC20 for IERC20; - using FixedPointMathLib for uint; - using FixedPointMathLib for int128; + using Math for uint; // Only for internal usage struct DepositInfo { @@ -56,7 +54,7 @@ contract VeTetu is ControllableV3, ReentrancyGuard, IVeTetu { // ************************************************************* /// @dev Version of this contract. Adjust manually on each code modification. - string public constant VE_VERSION = "1.2.0"; + string public constant VE_VERSION = "1.3.0"; uint internal constant WEEK = 1 weeks; uint internal constant MAX_TIME = 16 weeks; uint public constant MAX_ATTACHMENTS = 1; diff --git a/contracts/ve/VeTetuLib.sol b/contracts/ve/VeTetuLib.sol index 5389fb8..6aafac8 100644 --- a/contracts/ve/VeTetuLib.sol +++ b/contracts/ve/VeTetuLib.sol @@ -1,17 +1,16 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; +import "../openzeppelin/Math.sol"; import "../interfaces/IVeTetu.sol"; -import "../lib/FixedPointMathLib.sol"; import "../lib/Base64.sol"; import "./../lib/StringLib.sol"; /// @title Library with additional ve functions /// @author belbix library VeTetuLib { - using FixedPointMathLib for uint; - using FixedPointMathLib for int128; + using Math for uint; uint internal constant WEEK = 1 weeks; uint internal constant MULTIPLIER = 1 ether; @@ -46,8 +45,8 @@ library VeTetuLib { // subtract current derived balance // rounded to UP for subtracting closer to 0 value if (oldDerivedAmount != 0 && currentAmount != 0) { - currentAmount = currentAmount.divWadUp(10 ** decimals); - uint currentDerivedAmount = currentAmount.mulDivUp(weight, WEIGHT_DENOMINATOR); + currentAmount = currentAmount.mulDiv(1e18, 10 ** decimals, Math.Rounding.Up); + uint currentDerivedAmount = currentAmount.mulDiv(weight, WEIGHT_DENOMINATOR, Math.Rounding.Up); if (oldDerivedAmount > currentDerivedAmount) { oldDerivedAmount -= currentDerivedAmount; } else { @@ -59,9 +58,9 @@ library VeTetuLib { // recalculate derived amount with new amount // rounded to DOWN // normalize decimals to 18 - newAmount = newAmount.divWadDown(10 ** decimals); + newAmount = newAmount.mulDiv(1e18, 10 ** decimals, Math.Rounding.Down); // calculate the final amount based on the weight - newAmount = newAmount.mulDivDown(weight, WEIGHT_DENOMINATOR); + newAmount = newAmount.mulDiv(weight, WEIGHT_DENOMINATOR, Math.Rounding.Down); return oldDerivedAmount + newAmount; } @@ -138,7 +137,7 @@ library VeTetuLib { } uPoint.bias -= uPoint.slope * int128(int256(blockTime - uPoint.ts)); - return uint(uint128(uPoint.bias.positiveInt128())); + return uint(uint128(_positiveInt128(uPoint.bias))); } /// @notice Calculate total voting power at some point in the past @@ -163,7 +162,7 @@ library VeTetuLib { lastPoint.slope += dSlope; lastPoint.ts = ti; } - return uint(uint128(lastPoint.bias.positiveInt128())); + return uint(uint128(_positiveInt128(lastPoint.bias))); } /// @notice Calculate total voting power at some point in the past @@ -297,8 +296,8 @@ library VeTetuLib { } else { dSlope = slopeChanges[ti]; } - lastPoint.bias = (lastPoint.bias - lastPoint.slope * int128(int256(ti - lastCheckpoint))).positiveInt128(); - lastPoint.slope = (lastPoint.slope + dSlope).positiveInt128(); + lastPoint.bias = _positiveInt128(lastPoint.bias - lastPoint.slope * int128(int256(ti - lastCheckpoint))); + lastPoint.slope = _positiveInt128(lastPoint.slope + dSlope); lastCheckpoint = ti; lastPoint.ts = ti; lastPoint.blk = initialLastPoint.blk + (blockSlope * (ti - initialLastPoint.ts)) / MULTIPLIER; @@ -318,8 +317,8 @@ library VeTetuLib { if (info.tokenId != 0) { // If last point was in this block, the slope change has been applied already // But in such case we have 0 slope(s) - lastPoint.slope = (lastPoint.slope + (info.uNew.slope - info.uOld.slope)).positiveInt128(); - lastPoint.bias = (lastPoint.bias + (info.uNew.bias - info.uOld.bias)).positiveInt128(); + lastPoint.slope = _positiveInt128(lastPoint.slope + (info.uNew.slope - info.uOld.slope)); + lastPoint.bias = _positiveInt128(lastPoint.bias + (info.uNew.bias - info.uOld.bias)); } // Record the changed point into history @@ -357,6 +356,10 @@ library VeTetuLib { } } + function _positiveInt128(int128 value) internal pure returns (int128) { + return value < 0 ? int128(0) : value; + } + /// @dev Return SVG logo of veTETU. function tokenURI(uint _tokenId, uint _balanceOf, uint untilEnd, uint _value) public pure returns (string memory output) { output = ''; diff --git a/scripts/addresses/base.ts b/scripts/addresses/base.ts index bdddd87..89653be 100644 --- a/scripts/addresses/base.ts +++ b/scripts/addresses/base.ts @@ -42,9 +42,23 @@ export class Baseddresses { // Tetu V2 vaults and strategies + public static tUSDbC = "0x68f0a05FDc8773d9a5Fd1304ca411ACc234ce22c".toLowerCase(); + // tokens public static TETU_TOKEN = "0x5E42c17CAEab64527D9d80d506a3FE01179afa02".toLowerCase(); + public static WETH_TOKEN = '0x4200000000000000000000000000000000000006'.toLowerCase(); + + public static USDC_TOKEN = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'.toLowerCase(); + public static USDbC_TOKEN = '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA'.toLowerCase(); + public static axlUSDC_TOKEN = '0xEB466342C4d449BC9f53A865D5Cb90586f405215'.toLowerCase(); + public static crvUSD_TOKEN = '0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93'.toLowerCase(); + public static USDT_TOKEN = ''.toLowerCase(); + + public static WBTC_TOKEN = ''.toLowerCase(); + public static DAI_TOKEN = ''.toLowerCase(); + public static CRV_TOKEN = '0x8Ee73c484A26e0A5df2Ee2a4960B789967dd0415'.toLowerCase(); + } diff --git a/scripts/addresses/polygon.ts b/scripts/addresses/polygon.ts index a697baf..67d8dd7 100644 --- a/scripts/addresses/polygon.ts +++ b/scripts/addresses/polygon.ts @@ -37,7 +37,7 @@ export class PolygonAddresses { public static PERF_FEE_TREASURY = "0x9Cc199D4353b5FB3e6C8EEBC99f5139e0d8eA06b".toLowerCase(); public static TETU_BRIDGED_PROCESSING = "0x1950a09fc28Dd3C36CaC89485357844Af0739C07".toLowerCase(); public static REWARDS_REDIRECTOR = "0xA9947d0815d6EA3077805E2112FB19572DD4dc9E".toLowerCase(); - public static BRIBE_DISTRIBUTION = "0x1b7B8E29176CF89Cd4c04852FCff552721fC1b2e".toLowerCase(); + public static BRIBE_DISTRIBUTION = "0x3220Fa5BD9Be44C2A7BbB137dA6E5Cd3b6bf7124".toLowerCase(); // PROTOCOL ADRS public static DEPOSIT_HELPER_V2 = "0xab2422A4d8Ac985AE98F5Da3713988b420f24165".toLowerCase(); diff --git a/scripts/deploy/DeployBribeDistribution.ts b/scripts/deploy/DeployBribeDistribution.ts index a311ac9..91fd4a1 100644 --- a/scripts/deploy/DeployBribeDistribution.ts +++ b/scripts/deploy/DeployBribeDistribution.ts @@ -1,13 +1,12 @@ import {ethers} from "hardhat"; import {DeployerUtils} from "../utils/DeployerUtils"; -import {PolygonAddresses} from "../addresses/polygon"; import {Addresses} from "../addresses/addresses"; import {BribeDistribution} from "../../typechain"; async function main() { const signer = (await ethers.getSigners())[0]; const core = Addresses.getCore(); - await DeployerUtils.deployContract(signer, "BribeDistribution", core.bribe, PolygonAddresses.tUSDC, core.tetu); + await DeployerUtils.deployContract(signer, "BribeDistribution", core.veDist, core.tetu); } main() diff --git a/scripts/deploy/DeployVault.ts b/scripts/deploy/DeployVault.ts index 28e895c..c765fc0 100644 --- a/scripts/deploy/DeployVault.ts +++ b/scripts/deploy/DeployVault.ts @@ -8,10 +8,10 @@ import { VaultFactory__factory } from "../../typechain"; import {RunHelper} from "../utils/RunHelper"; -import {PolygonAddresses} from "../addresses/polygon"; +import {Baseddresses} from "../addresses/base"; -const ASSET = ''; +const ASSET = Baseddresses.USDbC_TOKEN; const BUFFER = 1000; // 1% const DEPOSIT_FEE = 300; // 0.3% const WITHDRAW_FEE = 300; // 0.3% diff --git a/test/lib/FixedPointMathLibTest.ts b/test/lib/FixedPointMathLibTest.ts deleted file mode 100644 index fbbac9c..0000000 --- a/test/lib/FixedPointMathLibTest.ts +++ /dev/null @@ -1,57 +0,0 @@ -import {ethers, network} from "hardhat"; -import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {expect} from "chai"; -import {DeployerUtils} from "../../scripts/utils/DeployerUtils"; -import { - Base64Test, FixedPointMathLibTest, - SlotsTest, - SlotsTest2, - SlotsTest2__factory, - SlotsTest__factory -} from "../../typechain"; -import {TimeUtils} from "../TimeUtils"; - -describe("FixedPointMathLib Tests", function () { - let snapshotBefore: string; - let snapshot: string; - let signer: SignerWithAddress; - - let helper: FixedPointMathLibTest; - - before(async function () { - snapshotBefore = await TimeUtils.snapshot(); - [signer] = await ethers.getSigners(); - helper = await DeployerUtils.deployContract(signer, 'FixedPointMathLibTest') as FixedPointMathLibTest; - }); - - after(async function () { - await TimeUtils.rollback(snapshotBefore); - }); - - - beforeEach(async function () { - snapshot = await TimeUtils.snapshot(); - }); - - afterEach(async function () { - await TimeUtils.rollback(snapshot); - }); - - - it("mulWadDown test", async () => { - expect(await helper.mulWadDown(3, 2)).eq(0); - }); - - it("mulWadUp test", async () => { - expect(await helper.mulWadUp(3, 2)).eq(1); - }); - - it("rpow test", async () => { - expect(await helper.rpow(3, 2, 1)).eq(9); - }); - - it("sqrt test", async () => { - expect(await helper.sqrt(9)).eq(3); - }); - -}) diff --git a/test/tools/BribeDistributorTest.ts b/test/tools/BribeDistributorTest.ts index b29a6c8..6fc296b 100644 --- a/test/tools/BribeDistributorTest.ts +++ b/test/tools/BribeDistributorTest.ts @@ -1,7 +1,7 @@ import chai from "chai"; import chaiAsPromised from "chai-as-promised"; import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers"; -import {BribeDistribution, MockBribe__factory, MockGauge__factory, MockToken,} from "../../typechain"; +import {BribeDistribution, MockToken,} from "../../typechain"; import {TimeUtils} from "../TimeUtils"; import {ethers} from "hardhat"; import {DeployerUtils} from "../../scripts/utils/DeployerUtils"; @@ -24,25 +24,18 @@ describe("BribeDistributorTest", function () { snapshotBefore = await TimeUtils.snapshot(); [signer, signer2] = await ethers.getSigners(); + token = await DeployerUtils.deployMockToken(signer, 'TETU', 18); const controller = await DeployerUtils.deployMockController(signer); - const mockBribe = MockBribe__factory.connect(await DeployerUtils.deployProxy(signer, 'MockBribe'), signer); - await mockBribe.init(controller.address); - const mockGauge = MockGauge__factory.connect(await DeployerUtils.deployProxy(signer, 'MockGauge'), signer); - await mockGauge.init(controller.address) + const ve = await DeployerUtils.deployVeTetu(signer, token.address, controller.address); - token = await DeployerUtils.deployMockToken(signer); - - const vault = await DeployerUtils.deployTetuVaultV2( + const veDist = await DeployerUtils.deployVeDistributor( signer, controller.address, + ve.address, token.address, - 'TETU', - 'TETU', - mockGauge.address, - 0 ); - distr = await DeployerUtils.deployContract(signer, "BribeDistribution", mockBribe.address, vault.address, token.address) as BribeDistribution; + distr = await DeployerUtils.deployContract(signer, "BribeDistribution", veDist.address, token.address) as BribeDistribution; }) after(async function () { @@ -68,24 +61,24 @@ describe("BribeDistributorTest", function () { it("manualNotify test", async () => { await token.approve(distr.address, 1000) - const bribe = await distr.bribe(); + const veDist = await distr.veDist(); await distr.manualNotify(1000, true) - expect(await token.balanceOf(bribe)).eq(500); + expect(await token.balanceOf(veDist)).eq(500); await distr.manualNotify(0, false) - expect(await token.balanceOf(bribe)).eq(1000); + expect(await token.balanceOf(veDist)).eq(1000); }) it("autoNotify test", async () => { const bal = await token.balanceOf(signer.address); await token.approve(distr.address, bal) - const bribe = await distr.bribe(); + const veDist = await distr.veDist(); await distr.autoNotify() - expect(await token.balanceOf(bribe)).eq(bal.div(2)); + expect(await token.balanceOf(veDist)).eq(bal.div(2)); await distr.autoNotify() - expect(await token.balanceOf(bribe)).eq(bal); + expect(await token.balanceOf(veDist)).eq(bal); }) })