Skip to content

Commit cfd4eec

Browse files
committed
periodic pre-merge
2 parents 833b8d4 + 7e1b1e9 commit cfd4eec

28 files changed

+5569
-1393
lines changed

README_TESTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ If you need to fork mainnet, single test contract
2424
Verbosely test a single contract while forking mainnet
2525
or ```source .env.forge && forge test --fork-url $MAINNET_RPC_URL -m veFPISProxy.t.sol -vvvvv``` for single test verbosity level 5
2626

27+
2728
## Hardhat
2829
**------Testing------**
30+
tsc
2931
cd ./src/hardhat
3032
npx hardhat compile
3133

3234
ARBITRUM
3335
npx hardhat test ./test/__ARBITRUM/CrossChainBridgeBacker_ARBI_AnySwap-Tests.js
3436
npx hardhat test ./test/__ARBITRUM/FraxCrossChainFarmV2-Tests.js
37+
npx hardhat test ./test/__ARBITRUM/FraxCrossChainFarmV3-Tests.js
3538
npx hardhat test ./test/__ARBITRUM/CurveAMO-ARBI-Tests.js
3639

3740
AURORA
@@ -91,6 +94,7 @@ npx hardhat test ./test/UniV3LiquidityAMO_V2-Tests.js
9194
npx hardhat test ./test/UniV3TWAPOracle-Tests.js
9295
npx hardhat test ./test/openzeppelin/ERC20.test.js
9396
npx hardhat test ./test/veFPIS-Tests.js
97+
npx hardhat test ./test/veFPISYieldDistributorV5-Tests.js
9498
npx hardhat test ./test/veFXSYieldDistributorV4-Tests.js
9599

96100
FANTOM

package-lock.json

Lines changed: 1076 additions & 1353 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hardhat/contracts/Curve/FraxFamilialPitchGauge.sol

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ pragma solidity ^0.8.17;
1111
// ====================================================================
1212
// ======================== FraxMiddlemanGauge ========================
1313
// ====================================================================
14-
// Looks at the gauge controller contract and pushes out FXS rewards once
15-
// a week to the gauges (farms).
16-
// This contract is what gets added to the gauge as a 'slice'
17-
18-
// Frax Finance: https://github.com/FraxFinance
19-
20-
// Primary Author(s)
21-
// Travis Moore: https://github.com/FortisFortuna
22-
23-
// Reviewer(s) / Contributor(s)
24-
// Jason Huan: https://github.com/jasonhuan
25-
// Sam Kazemian: https://github.com/samkazemian
14+
/**
15+
* @title FraxFamilialPitchGauge
16+
* @notice Redistributes gauge rewards to multiple gauges (FraxFarms) based on each "child" gauge's `total_combined_weight`.
17+
* @author Modified version of the FraxMiddlemanGauge - by ZrowGz @ Pitch Foundation
18+
* @dev To use this:
19+
* - Add to GaugeController as a gauge
20+
* - Add to FXS Rewards Distributor as a gauge
21+
* * BUT do not set as a middleman gauge on the FXS Rewards Distributor
22+
* - Set as the `gaugeController` & `rewardsDistributor` on all children FraxFarms
23+
* - Disable rewards for pre-existing gauges on the FXS Rewards Distributor
24+
*/
2625

2726
// import "../Math/Math.sol";
2827
// import "../Math/SafeMath.sol";
@@ -32,7 +31,7 @@ import "./IFraxGaugeFXSRewardsDistributor.sol";
3231
import '../Uniswap/TransferHelper.sol';
3332
import "../Staking/Owned.sol";
3433
// import "../Utils/ReentrancyGuard.sol";
35-
import "./IFraxFarm.sol";
34+
import "../Staking/IFraxFarm.sol";
3635
import "./IFraxGaugeControllerV2.sol";
3736

3837
/**

src/hardhat/contracts/Curve/FraxGaugeControllerV2.vy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @version 0.3.7
1+
# @version 0.3.4
22

33
"""
44
@title Gauge Controller
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >=0.6.11;
3+
4+
// ====================================================================
5+
// | ______ _______ |
6+
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
7+
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
8+
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
9+
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
10+
// | |
11+
// ====================================================================
12+
// ======================= FraxMiddlemanGaugeV2 =======================
13+
// ====================================================================
14+
// Looks at the gauge controller contract and pushes out FXS rewards once
15+
// a week to the gauges (farms).
16+
// This contract is what gets added to the gauge as a 'slice'
17+
// V2: Uses Fraxferry instead of miscellaneous 3rd-party bridges
18+
19+
// Frax Finance: https://github.com/FraxFinance
20+
21+
// Primary Author(s)
22+
// Travis Moore: https://github.com/FortisFortuna
23+
24+
// Reviewer(s) / Contributor(s)
25+
// Sam Kazemian: https://github.com/samkazemian
26+
27+
import "../Math/Math.sol";
28+
import "../Math/SafeMath.sol";
29+
import "../ERC20/ERC20.sol";
30+
import "../ERC20/SafeERC20.sol";
31+
import "./IFraxGaugeFXSRewardsDistributor.sol";
32+
import "../Fraxferry/IFraxferry.sol";
33+
import '../Uniswap/TransferHelper.sol';
34+
import "../Staking/Owned.sol";
35+
import "../Utils/ReentrancyGuard.sol";
36+
37+
contract FraxMiddlemanGaugeV2 is Owned, ReentrancyGuard {
38+
using SafeMath for uint256;
39+
using SafeERC20 for ERC20;
40+
41+
/* ========== STATE VARIABLES ========== */
42+
43+
// Instances and addresses
44+
address public reward_token_address = 0x3432B6A60D23Ca0dFCa7761B7ab56459D9C964D0; // FXS
45+
address public rewards_distributor_address;
46+
47+
// Informational
48+
string public name;
49+
50+
// Admin addresses
51+
address public timelock_address;
52+
53+
// Gauge-related
54+
IFraxferry public ferry;
55+
address public destination_address;
56+
57+
58+
/* ========== MODIFIERS ========== */
59+
60+
modifier onlyByOwnGov() {
61+
require(msg.sender == owner || msg.sender == timelock_address, "Not owner or timelock");
62+
_;
63+
}
64+
65+
modifier onlyRewardsDistributor() {
66+
require(msg.sender == rewards_distributor_address, "Not rewards distributor");
67+
_;
68+
}
69+
70+
/* ========== CONSTRUCTOR ========== */
71+
72+
constructor (
73+
address _owner,
74+
address _timelock_address,
75+
address _rewards_distributor_address,
76+
address _ferry_address,
77+
address _destination_address,
78+
string memory _name
79+
) Owned(_owner) {
80+
timelock_address = _timelock_address;
81+
82+
rewards_distributor_address = _rewards_distributor_address;
83+
84+
ferry = IFraxferry(_ferry_address);
85+
destination_address = _destination_address;
86+
87+
name = _name;
88+
}
89+
90+
/* ========== MUTATIVE FUNCTIONS ========== */
91+
92+
// Callable only by the rewards distributor
93+
function pullAndBridge(uint256 reward_amount) external onlyRewardsDistributor nonReentrant {
94+
require(address(ferry) != address(0), "Invalid bridge address");
95+
96+
// Pull in the rewards from the rewards distributor
97+
TransferHelper.safeTransferFrom(reward_token_address, rewards_distributor_address, address(this), reward_amount);
98+
99+
// Logic here
100+
ERC20(reward_token_address).approve(address(ferry), reward_amount);
101+
ferry.embarkWithRecipient(reward_amount, destination_address);
102+
103+
}
104+
105+
/* ========== RESTRICTED FUNCTIONS - Owner or timelock only ========== */
106+
107+
// Added to support recovering LP Rewards and other mistaken tokens from other systems to be distributed to holders
108+
function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyByOwnGov {
109+
// Only the owner address can ever receive the recovery withdrawal
110+
TransferHelper.safeTransfer(tokenAddress, owner, tokenAmount);
111+
emit RecoveredERC20(tokenAddress, tokenAmount);
112+
}
113+
114+
// Generic proxy
115+
function execute(
116+
address _to,
117+
uint256 _value,
118+
bytes calldata _data
119+
) external onlyByOwnGov returns (bool, bytes memory) {
120+
(bool success, bytes memory result) = _to.call{value:_value}(_data);
121+
return (success, result);
122+
}
123+
124+
function setTimelock(address _new_timelock) external onlyByOwnGov {
125+
timelock_address = _new_timelock;
126+
}
127+
128+
function setBridgeInfo(address _ferry_address, address _destination_address) external onlyByOwnGov {
129+
ferry = IFraxferry(_ferry_address);
130+
131+
// Overridden cross-chain destination address
132+
destination_address = _destination_address;
133+
134+
135+
emit BridgeInfoChanged(_ferry_address, _destination_address);
136+
}
137+
138+
function setRewardsDistributor(address _rewards_distributor_address) external onlyByOwnGov {
139+
rewards_distributor_address = _rewards_distributor_address;
140+
}
141+
142+
/* ========== EVENTS ========== */
143+
144+
event RecoveredERC20(address token, uint256 amount);
145+
event BridgeInfoChanged(address ferry_address, address destination_address);
146+
}

src/hardhat/contracts/Fraxferry/Fraxferry.sol

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ contract Fraxferry {
5353
address public captain;
5454
address public firstOfficer;
5555
mapping(address => bool) public crewmembers;
56+
mapping(address => bool) public fee_exempt_addrs;
5657

5758
bool public paused;
5859

@@ -118,7 +119,9 @@ contract Fraxferry {
118119
event SetCrewmember(address indexed crewmember,bool set);
119120
event SetFee(uint previousFeeRate, uint feeRate,uint previousFeeMin, uint feeMin,uint previousFeeMax, uint feeMax);
120121
event SetMinWaitPeriods(uint previousMinWaitAdd,uint previousMinWaitExecute,uint minWaitAdd,uint minWaitExecute);
122+
event FeeExemptToggled(address addr,bool is_fee_exempt);
121123

124+
122125
// ############## Modifiers ##############
123126

124127
modifier isOwner() {
@@ -150,7 +153,11 @@ contract Fraxferry {
150153

151154
function embarkWithRecipient(uint amount, address recipient) public notPaused {
152155
amount = (amount/REDUCED_DECIMALS)*REDUCED_DECIMALS; // Round amount to fit in data structure
153-
uint fee = Math.min(Math.max(FEE_MIN,amount*FEE_RATE/10000),FEE_MAX);
156+
uint fee;
157+
if(fee_exempt_addrs[msg.sender]) fee = 0;
158+
else {
159+
fee = Math.min(Math.max(FEE_MIN,amount*FEE_RATE/10000),FEE_MAX);
160+
}
154161
require (amount>fee,"Amount too low");
155162
require (amount/REDUCED_DECIMALS<=type(uint64).max,"Amount too high");
156163
TransferHelper.safeTransferFrom(address(token),msg.sender,address(this),amount);
@@ -293,6 +300,11 @@ contract Fraxferry {
293300
crewmembers[crewmember]=set;
294301
emit SetCrewmember(crewmember,set);
295302
}
303+
304+
function toggleFeeExemptAddr(address addr) external isOwner {
305+
fee_exempt_addrs[addr] = !fee_exempt_addrs[addr];
306+
emit FeeExemptToggled(addr,fee_exempt_addrs[addr]);
307+
}
296308

297309

298310
// ############## Token management ##############
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity >=0.8.0;
3+
4+
interface IFraxferry {
5+
struct Transaction {
6+
address user;
7+
uint64 amount;
8+
uint32 timestamp;
9+
}
10+
11+
struct Batch {
12+
uint64 start;
13+
uint64 end;
14+
uint64 departureTime;
15+
uint64 status;
16+
bytes32 hash;
17+
}
18+
19+
struct BatchData {
20+
uint startTransactionNo;
21+
Transaction[] transactions;
22+
}
23+
24+
function FEE () external view returns (uint256);
25+
function MIN_WAIT_PERIOD_ADD () external view returns (uint256);
26+
function MIN_WAIT_PERIOD_EXECUTE () external view returns (uint256);
27+
function REDUCED_DECIMALS () external view returns (uint256);
28+
function acceptOwnership () external;
29+
function batches (uint256) external view returns (uint64 start, uint64 end, uint64 departureTime, uint64 status, bytes32 hash);
30+
function cancelled (uint256) external view returns (bool);
31+
function captain () external view returns (address);
32+
function chainid () external view returns (uint256);
33+
function crewmembers (address) external view returns (bool);
34+
function depart (uint256 start, uint256 end, bytes32 hash) external;
35+
function disembark (BatchData memory batchData) external;
36+
function disputeBatch (uint256 batchNo, bytes32 hash) external;
37+
function embark (uint256 amount) external;
38+
function embarkWithRecipient (uint256 amount, address recipient) external;
39+
function embarkWithSignature (uint256 _amount, address recipient, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s) external;
40+
function execute (address _to, uint256 _value, bytes memory _data) external returns (bool, bytes memory);
41+
function executeIndex () external view returns (uint256);
42+
function firstOfficer () external view returns (address);
43+
function getBatchAmount (uint256 start, uint256 end) external view returns (uint256 totalAmount);
44+
function getBatchData (uint256 start, uint256 end) external view returns (BatchData memory data);
45+
function getNextBatch (uint256 _start, uint256 max) external view returns (uint256 start, uint256 end, bytes32 hash);
46+
function getTransactionsHash (uint256 start, uint256 end) external view returns (bytes32);
47+
function jettison (uint256 index, bool cancel) external;
48+
function jettisonGroup (uint256[] memory indexes, bool cancel) external;
49+
function noBatches () external view returns (uint256);
50+
function noTransactions () external view returns (uint256);
51+
function nominateNewOwner (address newOwner) external;
52+
function nominatedOwner () external view returns (address);
53+
function owner () external view returns (address);
54+
function pause () external;
55+
function paused () external view returns (bool);
56+
function removeBatches (uint256 batchNo) external;
57+
function sendTokens (address receiver, uint256 amount) external;
58+
function setCaptain (address newCaptain) external;
59+
function setCrewmember (address crewmember, bool set) external;
60+
function setFee (uint256 _FEE) external;
61+
function setFirstOfficer (address newFirstOfficer) external;
62+
function setMinWaitPeriods (uint256 _MIN_WAIT_PERIOD_ADD, uint256 _MIN_WAIT_PERIOD_EXECUTE) external;
63+
function targetChain () external view returns (uint256);
64+
function targetToken () external view returns (address);
65+
function token () external view returns (address);
66+
function transactions (uint256) external view returns (address user, uint64 amount, uint32 timestamp);
67+
function unPause () external;
68+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//SPDX-License-Identifier: Unlicense
2+
pragma solidity ^0.8.0;
3+
4+
5+
6+
interface IFraxlendAMOV3 {
7+
function FRAX () external view returns (address);
8+
function PRICE_PRECISION () external view returns (uint256);
9+
function accrueInterestAllFraxlendPair () external;
10+
function accrueInterestFraxlendPair (address _pairAddress) external;
11+
function addCollateralToPair (address _pairAddress, uint256 _fraxAmount) external;
12+
function amoMinter () external view returns (address);
13+
function borrowPairsArray (uint256) external view returns (address);
14+
function borrowPairsCollateralFrax (address) external view returns (uint256);
15+
function borrowPairsInitialized (address) external view returns (bool);
16+
function borrowPairsMaxCollateral (address) external view returns (uint256);
17+
function borrowPairsMaxLTV (address) external view returns (uint256);
18+
function burnFRAX (uint256 _fraxAmount) external;
19+
function depositToPair (address _pairAddress, uint256 _fraxAmount) external;
20+
function dollarBalances () external view returns (uint256 fraxValE18, uint256 collatValE18);
21+
function execute (address _to, uint256 _value, bytes memory _data) external returns (bool, bytes memory);
22+
function fraxlendPairDeployer () external view returns (address);
23+
function mintedBalance () external view returns (int256);
24+
function name () external pure returns (string memory _name);
25+
function openBorrowPosition (address _pairAddress, uint256 _fraxAmount, uint256 _borrowAmount) external;
26+
function operatorAddress () external view returns (address);
27+
function owner () external view returns (address);
28+
function pairsArray (uint256) external view returns (address);
29+
function pairsInitialized (address) external view returns (bool);
30+
function pairsMaxAllocation (address) external view returns (uint256);
31+
function pairsMintedFrax (address) external view returns (uint256);
32+
function pairsProfitTaken (address) external view returns (uint256);
33+
function previewUpdateExchangeRate (address _pairAddress) external view returns (uint256 _exchangeRate);
34+
function recoverERC20 (address _tokenAddress, uint256 _tokenAmount) external;
35+
function removeCollateralFromPair (address _pairAddress, uint256 _fraxAmount) external;
36+
function renounceOwnership () external;
37+
function repayBorrowPosition (address _pairAddress, uint256 _shares) external;
38+
function repayBorrowPositionWithCollateral (address _pairAddress, address _swapperAddress, uint256 _collateralToSwap, uint256 _amountAssetOutMin, address[] memory _path) external returns (uint256 _amountAssetOut);
39+
function setAMOMinter (address _newAmoMinterAddress) external;
40+
function setBorrowPair (address _pairAddress, uint256 _maxCollateral, uint256 _maxLTV) external;
41+
function setFraxlendPairDeployer (address _newFraxlendPairDeployerAddress) external;
42+
function setOperatorAddress (address _newOperatorAddress) external;
43+
function setPair (address _pairAddress, uint256 _maxAllocation) external;
44+
function showAllocations () external view returns (uint256[4] memory _allocations);
45+
function showBorrowPairAccounting (address _pairAddress) external view returns (uint256[4] memory _allocations);
46+
function showPairAccounting (address _pairAddress) external view returns (uint256[5] memory _allocations);
47+
function transferOwnership (address newOwner) external;
48+
function version () external pure returns (uint256 _major, uint256 _minor, uint256 _patch);
49+
function withdrawFromPair (address _pairAddress, uint256 _shares) external returns (uint256 _amountWithdrawn);
50+
function withdrawMaxFromAllPairs () external;
51+
function withdrawMaxFromPair (address _pairAddress) external returns (uint256 _amountWithdrawn);
52+
}

0 commit comments

Comments
 (0)