Diff
checker
Text
Text
Bilder
Dokumente
Excel
Ordner
Legal
Enterprise
Desktop-App
Preise
Einloggen
Diffchecker Desktop herunterladen
Texte vergleichen
Finde den Unterschied zwischen zwei Textdateien
Werkzeuge
Verlauf
Live-Editor
Gleiches ausblenden
Zeilenumbruch aus
Ansicht
Zweispaltig
Einspaltig
Vergleichsgenauigkeit
Intelligent
Wort
Zeichen
Syntaxhervorhebung
Syntax auswählen
Ignorieren
Text umwandeln
Zur ersten Änderung
Eingabe bearbeiten
Diffchecker Desktop
Der sicherste Weg, Diffchecker zu nutzen. Hol dir die Desktop-App: Deine Diffs verlassen nie deinen Computer!
Desktop holen
GHogRewardPool
Erstellt
letztes Jahr
Diff läuft nie ab
Löschen
Exportieren
Teilen
Erklären
74 Entfernungen
Zeilen
Gesamt
Entfernt
Zeichen
Gesamt
Entfernt
Um diese Funktion weiterhin zu nutzen, aktualisiere auf
Diff
checker
Pro
Preise anzeigen
264 Zeilen
Kopieren
320 Hinzufügungen
Zeilen
Gesamt
Hinzugefügt
Zeichen
Gesamt
Hinzugefügt
Um diese Funktion weiterhin zu nutzen, aktualisiere auf
Diff
checker
Pro
Preise anzeigen
455 Zeilen
Kopieren
Kopieren
Kopiert
Kopieren
Kopiert
contract G
Scarab
RewardPool
{
contract G
Hog
RewardPool
is ReentrancyGuard
{
using SafeMath for uint256;
using SafeMath for uint256;
using SafeERC20 for IERC20;
using SafeERC20 for IERC20;
// governance
// governance
address public operator;
address public operator;
// Info of each user.
// Info of each user.
struct UserInfo {
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amount; // How many LP tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 rewardDebt; // Reward debt. See explanation below.
}
}
// Info of each pool.
// Info of each pool.
struct PoolInfo {
struct PoolInfo {
IERC20 token; // Address of LP token contract.
IERC20 token; // Address of LP token contract.
Kopieren
Kopiert
Kopieren
Kopiert
uint256 allocPoint; // How many allocation points assigned to this pool.
tSHAREs
to distribute per block.
uint256 withFee; // withdraw fee that is applied to created pool.
uint256 lastRewardTime; // Last time that
tSHAREs
distribution occurs.
uint256 allocPoint; // How many allocation points assigned to this pool.
GHOGs
to distribute per block.
uint256 acc
TShare
PerShare; // Accumulated
tSHAREs
per share, times 1e18. See below.
uint256 lastRewardTime; // Last time that
GHOGs
distribution occurs.
uint256 acc
Ghog
PerShare; // Accumulated
GHOGs
per share, times 1e18. See below.
bool isStarted; // if lastRewardTime has passed
bool isStarted; // if lastRewardTime has passed
Kopieren
Kopiert
Kopieren
Kopiert
address gauge;
}
}
Kopieren
Kopiert
Kopieren
Kopiert
IERC20 public
tshare
;
IERC20 public
ghog;
address public devFund
;
// Info of each pool.
// Info of each pool.
PoolInfo[] public poolInfo;
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens.
// Info of each user that stakes LP tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
// Total allocation points. Must be the sum of all allocation points in all pools.
// Total allocation points. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
uint256 public totalAllocPoint = 0;
Kopieren
Kopiert
Kopieren
Kopiert
// The time when
tSHARE
mining starts.
// The time when
GHOG
mining starts.
uint256 public poolStartTime;
uint256 public poolStartTime;
Kopieren
Kopiert
Kopieren
Kopiert
// The time when
tSHARE
mining ends.
// The time when
GHOG
mining ends.
uint256 public poolEndTime;
uint256 public poolEndTime;
Kopieren
Kopiert
Kopieren
Kopiert
uint256 public sharePerSecond = 0.00186122 ether;
uint256 public runningTime = 370 days;
Kopieren
Kopiert
Kopieren
Kopiert
uint256 public tSharePerSecond = 0.00186122 ether; // 59500 tshare / (370 days * 24h * 60min * 60s)
address public swapxToken = 0xA04BC7140c26fc9BB1F36B1A604C7A5a88fb0E70;
uint256 public runningTime = 370 days; // 370 days
uint256 public constant TOTAL_REWARDS = 59500 ether;
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
Kopieren
Kopiert
Kopieren
Kopiert
event EmergencyWithdraw(
address indexed user,
uint256 indexed pid,
uint256 amount
);
event EmergencyWithdraw(
address indexed user,
uint256 indexed pid,
uint256 amount
);
event RewardPaid(address indexed user, uint256 amount);
event RewardPaid(address indexed user, uint256 amount);
Kopieren
Kopiert
Kopieren
Kopiert
event DevFundUpdated(address devFund);
event SharePerSecondUpdated(uint256 oldRate, uint256 newRate, uint256 timestamp);
constructor(
constructor(
Kopieren
Kopiert
Kopieren
Kopiert
address _
tshare
,
address _
ghog,
address _hogS,
address _ghogS2,
address _devFund
,
uint256 _poolStartTime
uint256 _poolStartTime
Kopieren
Kopiert
Kopieren
Kopiert
)
public
{
)
{
require(
block.timestamp < _poolStartTime,
"late"
);
require(
if (_
tshare
!= address(0))
tshare
= IERC20(_
tshare);
block.timestamp < _poolStartTime,
"pool cant be started in the past"
);
if (_
ghog
!= address(0))
ghog
= IERC20(_
ghog);
if (_devFund != address(0)) devFund = _devFund;
poolStartTime = _poolStartTime;
poolStartTime = _poolStartTime;
Kopieren
Kopiert
Kopieren
Kopiert
poolEndTime =
poolStartTime + runningTime;
poolEndTime =
_
poolStartTime + runningTime;
operator = msg.sender;
operator = msg.sender;
Kopieren
Kopiert
Kopieren
Kopiert
devFund = _devFund;
// create all the pools
add(0, 0, IERC20(_hogS), false, 0, address(0)); // Hog-S
add(0, 0, IERC20(_ghogS2), false, 0, address(0)); // GHog-S
}
}
modifier onlyOperator() {
modifier onlyOperator() {
Kopieren
Kopiert
Kopieren
Kopiert
require(
operator == msg.sender,
"TShare
RewardPool: caller is not the operator"
);
require(
operator == msg.sender,
"GHog
RewardPool: caller is not the operator"
);
_;
_;
}
}
Kopieren
Kopiert
Kopieren
Kopiert
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
function checkPoolDuplicate(IERC20 _token) internal view {
function checkPoolDuplicate(IERC20 _token) internal view {
uint256 length = poolInfo.length;
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
for (uint256 pid = 0; pid < length; ++pid) {
Kopieren
Kopiert
Kopieren
Kopiert
require(
poolInfo[pid].token != _token,
"TShare
RewardPool: existing pool?"
);
require(
poolInfo[pid].token != _token,
"GHog
RewardPool: existing pool?"
);
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Add
a
new lp to the pool. Can only be called by
the owner
.
// Add
new lp to the pool. Can only be called by
operator
.
function add(
function add(
uint256 _allocPoint,
uint256 _allocPoint,
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _withFee,
IERC20 _token,
IERC20 _token,
bool _withUpdate,
bool _withUpdate,
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _lastRewardTime
uint256 _lastRewardTime
,
address _gauge
) public onlyOperator {
) public onlyOperator {
checkPoolDuplicate(_token);
checkPoolDuplicate(_token);
if (_withUpdate) {
if (_withUpdate) {
massUpdatePools();
massUpdatePools();
}
}
if (block.timestamp < poolStartTime) {
if (block.timestamp < poolStartTime) {
// chef is sleeping
// chef is sleeping
if (_lastRewardTime == 0) {
if (_lastRewardTime == 0) {
_lastRewardTime = poolStartTime;
_lastRewardTime = poolStartTime;
} else {
} else {
if (_lastRewardTime < poolStartTime) {
if (_lastRewardTime < poolStartTime) {
_lastRewardTime = poolStartTime;
_lastRewardTime = poolStartTime;
}
}
}
}
} else {
} else {
// chef is cooking
// chef is cooking
if (_lastRewardTime == 0 || _lastRewardTime < block.timestamp) {
if (_lastRewardTime == 0 || _lastRewardTime < block.timestamp) {
_lastRewardTime = block.timestamp;
_lastRewardTime = block.timestamp;
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
bool _isStarted =
bool _isStarted =
(_lastRewardTime <= poolStartTime) ||
(_lastRewardTime <= poolStartTime) ||
(_lastRewardTime <= block.timestamp);
(_lastRewardTime <= block.timestamp);
poolInfo.push(
poolInfo.push(
PoolInfo({
PoolInfo({
token
: _token,
token
: _token,
allocPoint
: _allocPoint,
withFee: _withFee,
lastRewardTime
: _lastRewardTime,
allocPoint
: _allocPoint,
acc
TShare
PerShare
: 0,
lastRewardTime
: _lastRewardTime,
isStarted
: _isStarted
acc
Ghog
PerShare
: 0,
})
);
isStarted
: _isStarted
,
gauge: _gauge
})
);
if (_isStarted) {
if (_isStarted) {
totalAllocPoint = totalAllocPoint.add(_allocPoint);
totalAllocPoint = totalAllocPoint.add(_allocPoint);
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Update the given pool's
tSHARE
allocation point. Can only be called by the
owner
.
// Update the given pool's
GHOG
allocation point. Can only be called by the
operator
.
function set(
uint256 _pid,
uint256 _allocPoint
) public onlyOperator {
function set(
uint256 _pid,
uint256 _allocPoint
,
uint256 _withFee,
address _gauge
) public onlyOperator {
massUpdatePools();
massUpdatePools();
Kopieren
Kopiert
Kopieren
Kopiert
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
Kopieren
Kopiert
Kopieren
Kopiert
require(_withFee < 200); // withdraw fee cant be more than 2%;
pool.withFee = _withFee;
if (pool.isStarted) {
if (pool.isStarted) {
totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add(
totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add(
_allocPoint
_allocPoint
);
);
}
}
pool.allocPoint = _allocPoint;
pool.allocPoint = _allocPoint;
Kopieren
Kopiert
Kopieren
Kopiert
pool.gauge = _gauge;
updatePool(_pid);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Return accumulate rewards over the given _from to _to block.
// AI-CONTROLLED: Updates the emission rate every 7 days based on protocol conditions
function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) {
// This function allows the AI to adjust the reward distribution rate
function setSharePerSecond(uint256 _sharePerSecond) external onlyOperator {
uint256 oldSharePerSecond = sharePerSecond;
// Update to new rate
sharePerSecond = _sharePerSecond;
// Emit event for rate change
emit SharePerSecondUpdated(oldSharePerSecond, _sharePerSecond, block.timestamp);
massUpdatePools();
}
function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) {
if (_fromTime >= _toTime) return 0;
if (_fromTime >= _toTime) return 0;
Kopieren
Kopiert
Kopieren
Kopiert
if (_toTime >= poolEndTime) {
if (_toTime >= poolEndTime) {
Kopieren
Kopiert
Kopieren
Kopiert
if (_fromTime >= poolEndTime) return 0;
if (_fromTime >= poolEndTime) return 0;
Kopieren
Kopiert
Kopieren
Kopiert
if (_fromTime <= poolStartTime) return poolEndTime.sub(poolStartTime).mul(
tS
harePerSecond);
return poolEndTime.sub(_fromTime).mul(
tS
harePerSecond);
if (_fromTime <= poolStartTime) return poolEndTime.sub(poolStartTime).mul(
s
harePerSecond);
return poolEndTime.sub(_fromTime).mul(
s
harePerSecond);
} else {
} else {
Kopieren
Kopiert
Kopieren
Kopiert
if (_toTime <= poolStartTime) return 0;
if (_toTime <= poolStartTime) return 0;
Kopieren
Kopiert
Kopieren
Kopiert
if (_fromTime <= poolStartTime) return _toTime.sub(poolStartTime).mul(
tS
harePerSecond);
return _toTime.sub(_fromTime).mul(
tS
harePerSecond);
if (_fromTime <= poolStartTime) return _toTime.sub(poolStartTime).mul(
s
harePerSecond);
return _toTime.sub(_fromTime).mul(
s
harePerSecond);
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
//
View function to see
pending
tSHAREs on frontend.
//
Modified
pending
Share to use new getGeneratedReward
function pendingShare(uint256 _pid, address _user)
external
view returns (uint256) {
function pendingShare(uint256 _pid, address _user)
public
view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
UserInfo storage user = userInfo[_pid][_user];
Kopieren
Kopiert
Kopieren
Kopiert
uint256 acc
TShare
PerShare = pool.acc
TShare
PerShare;
uint256 acc
Ghog
PerShare = pool.acc
Ghog
PerShare;
uint256 tokenSupply = pool.
token.balanceOf(address(this));
uint256 tokenSupply = pool.
gauge != address(0) ? ISwapxGauge(pool.gauge).balanceOf(address(this)) : pool.
token.balanceOf(address(this));
if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) {
if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) {
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _generatedReward = getGeneratedReward(
pool.lastRewardTime,
block.timestamp
);
uint256 _generatedReward = getGeneratedReward(
uint256 _
tshareReward
= _generatedReward.mul(pool.allocPoint).div(totalAllocPoint);
pool.lastRewardTime,
acc
TShare
PerShare = acc
TShare
PerShare.add(_
tshareReward
.mul(1e18).div(tokenSupply));
block.timestamp
);
uint256 _
ghogReward
= _generatedReward.mul(pool.allocPoint).div(totalAllocPoint);
acc
Ghog
PerShare = acc
Ghog
PerShare.add(_
ghogReward
.mul(1e18).div(tokenSupply));
}
}
Kopieren
Kopiert
Kopieren
Kopiert
return user.amount.mul(acc
TShare
PerShare).div(1e18).sub(user.rewardDebt);
return user.amount.mul(acc
Ghog
PerShare).div(1e18).sub(user.rewardDebt);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Update reward variables for all pools. Be careful of gas spending!
function massUpdatePools() public {
function massUpdatePools() public {
uint256 length = poolInfo.length;
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
updatePool(pid);
}
}
}
}
// Update reward variables of the given pool to be up-to-date.
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
function updatePool(uint256 _pid) public {
Kopieren
Kopiert
Kopieren
Kopiert
depositToGauge(_pid);
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
if (block.timestamp <= pool.lastRewardTime) {
if (block.timestamp <= pool.lastRewardTime) {
return;
return;
}
}
Kopieren
Kopiert
Kopieren
Kopiert
uint256 tokenSupply = pool.
token.balanceOf(address(this));
uint256 tokenSupply = pool.
gauge != address(0) ? ISwapxGauge(pool.gauge).balanceOf(address(this)) : pool.
token.balanceOf(address(this));
if (tokenSupply == 0) {
if (tokenSupply == 0) {
pool.lastRewardTime = block.timestamp;
pool.lastRewardTime = block.timestamp;
return;
return;
}
}
if (!pool.isStarted) {
if (!pool.isStarted) {
pool.isStarted = true;
pool.isStarted = true;
totalAllocPoint = totalAllocPoint.add(pool.allocPoint);
totalAllocPoint = totalAllocPoint.add(pool.allocPoint);
}
}
if (totalAllocPoint > 0) {
if (totalAllocPoint > 0) {
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _generatedReward = getGeneratedReward(
pool.lastRewardTime,
block.timestamp
);
// This now correctly accounts for all emission rate changes
uint256 _
tshareReward
= _generatedReward.mul(pool.allocPoint).div(
totalAllocPoint
);
uint256 _generatedReward = getGeneratedReward(
pool.acc
TShare
PerShare = pool.acc
TShare
PerShare.add(
_tshareReward
.mul(1e18).div(tokenSupply)
);
pool.lastRewardTime,
block.timestamp
);
uint256 _
ghogReward
= _generatedReward.mul(pool.allocPoint).div(
totalAllocPoint
);
pool.acc
Ghog
PerShare = pool.acc
Ghog
PerShare.add(
_ghogReward
.mul(1e18).div(tokenSupply)
);
}
}
pool.lastRewardTime = block.timestamp;
pool.lastRewardTime = block.timestamp;
}
}
// Deposit LP tokens.
// Deposit LP tokens.
Kopieren
Kopiert
Kopieren
Kopiert
function deposit(uint256 _pid, uint256 _amount) public
{
function deposit(uint256 _pid, uint256 _amount) public
nonReentrant
{
address _sender = msg.sender;
address _sender = msg.sender;
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_sender];
UserInfo storage user = userInfo[_pid][_sender];
updatePool(_pid);
updatePool(_pid);
if (user.amount > 0) {
if (user.amount > 0) {
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _pending = user
.amount
.mul(pool.acc
TShare
PerShare)
.div(1e18)
.sub(user.rewardDebt);
uint256 _pending = user
.amount
.mul(pool.acc
Ghog
PerShare)
.div(1e18)
.sub(user.rewardDebt);
if (_pending > 0) {
if (_pending > 0) {
Kopieren
Kopiert
Kopieren
Kopiert
safe
TShare
Transfer(_sender, _pending);
safe
Ghog
Transfer(_sender, _pending);
emit RewardPaid(_sender, _pending);
emit RewardPaid(_sender, _pending);
}
}
}
}
if (_amount > 0) {
if (_amount > 0) {
pool.token.safeTransferFrom(_sender, address(this), _amount);
pool.token.safeTransferFrom(_sender, address(this), _amount);
user.amount = user.amount.add(_amount);
user.amount = user.amount.add(_amount);
Kopieren
Kopiert
Kopieren
Kopiert
depositToGauge(_pid);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
user.rewardDebt = user.amount.mul(pool.acc
TShare
PerShare).div(1e18);
user.rewardDebt = user.amount.mul(pool.acc
Ghog
PerShare).div(1e18);
emit Deposit(_sender, _pid, _amount);
emit Deposit(_sender, _pid, _amount);
}
}
// Withdraw LP tokens.
// Withdraw LP tokens.
Kopieren
Kopiert
Kopieren
Kopiert
function withdraw(uint256 _pid, uint256 _amount) public
{
function withdraw(uint256 _pid, uint256 _amount) public
nonReentrant
{
address _sender = msg.sender;
address _sender = msg.sender;
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_sender];
UserInfo storage user = userInfo[_pid][_sender];
require(user.amount >= _amount, "withdraw: not good");
require(user.amount >= _amount, "withdraw: not good");
updatePool(_pid);
updatePool(_pid);
Kopieren
Kopiert
Kopieren
Kopiert
uint256 _pending = user.amount.mul(pool.acc
TShare
PerShare).div(1e18).sub(
user.rewardDebt
);
uint256 _pending = user.amount.mul(pool.acc
Ghog
PerShare).div(1e18).sub(
user.rewardDebt
);
if (_pending > 0) {
if (_pending > 0) {
Kopieren
Kopiert
Kopieren
Kopiert
safe
TShare
Transfer(_sender, _pending);
safe
Ghog
Transfer(_sender, _pending);
emit RewardPaid(_sender, _pending);
emit RewardPaid(_sender, _pending);
}
}
if (_amount > 0) {
if (_amount > 0) {
user.amount = user.amount.sub(_amount);
user.amount = user.amount.sub(_amount);
Kopieren
Kopiert
Kopieren
Kopiert
pool.token.safeTransfer(_sender,
_amount
);
withdrawFromGauge(_pid, _amount);
// Calculate the fee and transfer it to the devFund
uint256 fee = _amount.mul(pool.withFee).div(10000); // Assuming withFee is in basis points (e.g., 100 = 1%)
uint256 amountAfterFee = _amount.sub(fee);
if (fee > 0) {
pool.token.safeTransfer(devFund, fee);
}
pool.token.safeTransfer(_sender,
amountAfterFee
);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
user.rewardDebt = user.amount.mul(pool.acc
TShare
PerShare).div(1e18);
user.rewardDebt = user.amount.mul(pool.acc
Ghog
PerShare).div(1e18);
emit Withdraw(_sender, _pid, _amount);
emit Withdraw(_sender, _pid, _amount);
}
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
// Withdraw without caring about rewards. EMERGENCY ONLY.
Kopieren
Kopiert
Kopieren
Kopiert
function emergencyWithdraw(uint256 _pid) public
{
function emergencyWithdraw(uint256 _pid) public
nonReentrant
{
PoolInfo storage pool = poolInfo[_pid];
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
UserInfo storage user = userInfo[_pid][msg.sender];
uint256 _amount = user.amount;
uint256 _amount = user.amount;
user.amount = 0;
user.amount = 0;
user.rewardDebt = 0;
user.rewardDebt = 0;
Kopieren
Kopiert
Kopieren
Kopiert
pool.token.safeTransfer(msg.sender,
_amount);
withdrawFromGauge(_pid, _amount);
uint256 fee = _amount.mul(pool.withFee).div(10000); // Assuming withFee is in basis points (e.g., 100 = 1%)
uint256 amountAfterFee = _amount.sub(fee);
if (fee > 0) {
pool.token.safeTransfer(devFund, fee);
}
pool.token.safeTransfer(msg.sender,
amountAfterFee);
emit EmergencyWithdraw(msg.sender, _pid, _amount);
emit EmergencyWithdraw(msg.sender, _pid, _amount);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Safe
tshare
transfer function, just in case if rounding error causes pool to not have enough
tSHAREs
.
// Safe
ghog
transfer function, just in case if rounding error causes pool to not have enough
Ghog
.
function safe
TShare
Transfer(address _to, uint256 _amount) internal {
function safe
Ghog
Transfer(address _to, uint256 _amount) internal {
uint256 _
tshareBal
=
tshare
.balanceOf(address(this));
uint256 _
ghogBal
=
ghog
.balanceOf(address(this));
if (_
tshareBal
> 0) {
if (_amount > _
tshareBal
) {
if (_
ghogBal
> 0) {
tshare
.safeTransfer(_to, _
tshareBal
);
if (_amount > _
ghogBal
) {
ghog
.safeTransfer(_to, _
ghogBal
);
} else {
} else {
Kopieren
Kopiert
Kopieren
Kopiert
tshare
.safeTransfer(_to, _amount);
ghog
.safeTransfer(_to, _amount);
}
}
}
}
}
}
function setOperator(address _operator) external onlyOperator {
function setOperator(address _operator) external onlyOperator {
operator = _operator;
operator = _operator;
}
}
Kopieren
Kopiert
Kopieren
Kopiert
function governanceRecoverUnsupported(
IERC20 _token,
uint256 amount,
address to
) external onlyOperator {
function setDevFund(address _devFund) external onlyOperator {
if (block.timestamp < poolEndTime +
90
days) {
require(_devFund != address(0), "Cannot set devFund to zero address");
devFund = _devFund;
emit DevFundUpdated(_devFund);
}
function governanceRecoverUnsupported(
IERC20 _token,
uint256 amount,
address to
) external onlyOperator {
if (block.timestamp < poolEndTime +
10
days) {
// do not allow to drain core token (tSHARE or lps) if less than 90 days after pool ends
// do not allow to drain core token (tSHARE or lps) if less than 90 days after pool ends
Kopieren
Kopiert
Kopieren
Kopiert
require(_token !=
tshare
, "
tshare
");
require(_token !=
ghog
, "
ghog
");
uint256 length = poolInfo.length;
uint256 length = poolInfo.length;
Kopieren
Kopiert
Kopieren
Kopiert
for (uint256 pid = 0; pid < length; ++pid) {
for (uint256 pid = 0; pid < length; ++pid) {
PoolInfo storage pool = poolInfo[pid];
PoolInfo storage pool = poolInfo[pid];
Kopieren
Kopiert
Kopieren
Kopiert
require(_token != pool.token, "pool.token");
require(_token != pool.token, "pool.token");
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
_token.safeTransfer(to, amount);
_token.safeTransfer(to, amount);
}
}
Kopieren
Kopiert
Kopieren
Kopiert
// Calculate total GHOG emitted from pool start until now
function getTotalEmittedShares() public view returns (uint256) {
if (block.timestamp <= poolStartTime) return 0;
uint256 endTime = block.timestamp;
if (endTime > poolEndTime) {
endTime = poolEndTime;
}
return getGeneratedReward(poolStartTime, endTime);
}
// Calculate total GHOG emitted between any two timestamps
function getTotalEmittedSharesBetween(uint256 _fromTime, uint256 _toTime) public view returns (uint256) {
require(_fromTime <= _toTime, "Invalid time range");
// Bound times within pool's active period
if (_fromTime < poolStartTime) {
_fromTime = poolStartTime;
}
if (_toTime > poolEndTime) {
_toTime = poolEndTime;
}
return getGeneratedReward(_fromTime, _toTime);
}
function depositToGauge(uint256 _pid) internal {
PoolInfo storage pool = poolInfo[_pid];
address gauge = pool.gauge;
uint256 balance = pool.token.balanceOf(address(this));
// Do nothing if this pool doesn't have a gauge
if (pool.gauge != address(0)) {
// Do nothing if the LP token in the MC is empty
if (balance > 0) {
// Approve to the gauge
if (pool.token.allowance(address(this), gauge) < balance ){
pool.token.approve(gauge, type(uint256).max);
}
ISwapxGauge(pool.gauge).deposit(balance);
}
}
}
function claimSwapxRewards(uint256 _pid) public onlyOperator {
PoolInfo storage pool = poolInfo[_pid];
ISwapxGauge(pool.gauge).getReward(); // claim the swapx rewards
IERC20 rewardToken = IERC20(swapxToken);
uint256 rewardAmount = rewardToken.balanceOf(address(this));
if (rewardAmount > 0) {
rewardToken.safeTransfer(devFund, rewardAmount);
}
}
function withdrawFromGauge(uint256 _pid, uint256 _amount) internal {
PoolInfo storage pool = poolInfo[_pid];
// Do nothing if this pool doesn't have a gauge
if (pool.gauge != address(0)) {
// Withdraw from the gauge
ISwapxGauge(pool.gauge).withdraw(_amount);
}
}
}
}
Kopieren
Kopiert
Kopieren
Kopiert
Gespeicherte Diffs
Originaltext
Datei öffnen
contract GScarabRewardPool { using SafeMath for uint256; using SafeERC20 for IERC20; // governance address public operator; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. } // Info of each pool. struct PoolInfo { IERC20 token; // Address of LP token contract. uint256 allocPoint; // How many allocation points assigned to this pool. tSHAREs to distribute per block. uint256 lastRewardTime; // Last time that tSHAREs distribution occurs. uint256 accTSharePerShare; // Accumulated tSHAREs per share, times 1e18. See below. bool isStarted; // if lastRewardTime has passed } IERC20 public tshare; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping(uint256 => mapping(address => UserInfo)) public userInfo; // Total allocation points. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The time when tSHARE mining starts. uint256 public poolStartTime; // The time when tSHARE mining ends. uint256 public poolEndTime; uint256 public tSharePerSecond = 0.00186122 ether; // 59500 tshare / (370 days * 24h * 60min * 60s) uint256 public runningTime = 370 days; // 370 days uint256 public constant TOTAL_REWARDS = 59500 ether; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount); event RewardPaid(address indexed user, uint256 amount); constructor( address _tshare, uint256 _poolStartTime ) public { require(block.timestamp < _poolStartTime, "late"); if (_tshare != address(0)) tshare = IERC20(_tshare); poolStartTime = _poolStartTime; poolEndTime = poolStartTime + runningTime; operator = msg.sender; } modifier onlyOperator() { require(operator == msg.sender, "TShareRewardPool: caller is not the operator"); _; } function checkPoolDuplicate(IERC20 _token) internal view { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { require(poolInfo[pid].token != _token, "TShareRewardPool: existing pool?"); } } // Add a new lp to the pool. Can only be called by the owner. function add( uint256 _allocPoint, IERC20 _token, bool _withUpdate, uint256 _lastRewardTime ) public onlyOperator { checkPoolDuplicate(_token); if (_withUpdate) { massUpdatePools(); } if (block.timestamp < poolStartTime) { // chef is sleeping if (_lastRewardTime == 0) { _lastRewardTime = poolStartTime; } else { if (_lastRewardTime < poolStartTime) { _lastRewardTime = poolStartTime; } } } else { // chef is cooking if (_lastRewardTime == 0 || _lastRewardTime < block.timestamp) { _lastRewardTime = block.timestamp; } } bool _isStarted = (_lastRewardTime <= poolStartTime) || (_lastRewardTime <= block.timestamp); poolInfo.push(PoolInfo({ token : _token, allocPoint : _allocPoint, lastRewardTime : _lastRewardTime, accTSharePerShare : 0, isStarted : _isStarted })); if (_isStarted) { totalAllocPoint = totalAllocPoint.add(_allocPoint); } } // Update the given pool's tSHARE allocation point. Can only be called by the owner. function set(uint256 _pid, uint256 _allocPoint) public onlyOperator { massUpdatePools(); PoolInfo storage pool = poolInfo[_pid]; if (pool.isStarted) { totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add( _allocPoint ); } pool.allocPoint = _allocPoint; } // Return accumulate rewards over the given _from to _to block. function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) { if (_fromTime >= _toTime) return 0; if (_toTime >= poolEndTime) { if (_fromTime >= poolEndTime) return 0; if (_fromTime <= poolStartTime) return poolEndTime.sub(poolStartTime).mul(tSharePerSecond); return poolEndTime.sub(_fromTime).mul(tSharePerSecond); } else { if (_toTime <= poolStartTime) return 0; if (_fromTime <= poolStartTime) return _toTime.sub(poolStartTime).mul(tSharePerSecond); return _toTime.sub(_fromTime).mul(tSharePerSecond); } } // View function to see pending tSHAREs on frontend. function pendingShare(uint256 _pid, address _user) external view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accTSharePerShare = pool.accTSharePerShare; uint256 tokenSupply = pool.token.balanceOf(address(this)); if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) { uint256 _generatedReward = getGeneratedReward(pool.lastRewardTime, block.timestamp); uint256 _tshareReward = _generatedReward.mul(pool.allocPoint).div(totalAllocPoint); accTSharePerShare = accTSharePerShare.add(_tshareReward.mul(1e18).div(tokenSupply)); } return user.amount.mul(accTSharePerShare).div(1e18).sub(user.rewardDebt); } // Update reward variables for all pools. Be careful of gas spending! function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; if (block.timestamp <= pool.lastRewardTime) { return; } uint256 tokenSupply = pool.token.balanceOf(address(this)); if (tokenSupply == 0) { pool.lastRewardTime = block.timestamp; return; } if (!pool.isStarted) { pool.isStarted = true; totalAllocPoint = totalAllocPoint.add(pool.allocPoint); } if (totalAllocPoint > 0) { uint256 _generatedReward = getGeneratedReward(pool.lastRewardTime, block.timestamp); uint256 _tshareReward = _generatedReward.mul(pool.allocPoint).div(totalAllocPoint); pool.accTSharePerShare = pool.accTSharePerShare.add(_tshareReward.mul(1e18).div(tokenSupply)); } pool.lastRewardTime = block.timestamp; } // Deposit LP tokens. function deposit(uint256 _pid, uint256 _amount) public { address _sender = msg.sender; PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_sender]; updatePool(_pid); if (user.amount > 0) { uint256 _pending = user.amount.mul(pool.accTSharePerShare).div(1e18).sub(user.rewardDebt); if (_pending > 0) { safeTShareTransfer(_sender, _pending); emit RewardPaid(_sender, _pending); } } if (_amount > 0) { pool.token.safeTransferFrom(_sender, address(this), _amount); user.amount = user.amount.add(_amount); } user.rewardDebt = user.amount.mul(pool.accTSharePerShare).div(1e18); emit Deposit(_sender, _pid, _amount); } // Withdraw LP tokens. function withdraw(uint256 _pid, uint256 _amount) public { address _sender = msg.sender; PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 _pending = user.amount.mul(pool.accTSharePerShare).div(1e18).sub(user.rewardDebt); if (_pending > 0) { safeTShareTransfer(_sender, _pending); emit RewardPaid(_sender, _pending); } if (_amount > 0) { user.amount = user.amount.sub(_amount); pool.token.safeTransfer(_sender, _amount); } user.rewardDebt = user.amount.mul(pool.accTSharePerShare).div(1e18); emit Withdraw(_sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 _amount = user.amount; user.amount = 0; user.rewardDebt = 0; pool.token.safeTransfer(msg.sender, _amount); emit EmergencyWithdraw(msg.sender, _pid, _amount); } // Safe tshare transfer function, just in case if rounding error causes pool to not have enough tSHAREs. function safeTShareTransfer(address _to, uint256 _amount) internal { uint256 _tshareBal = tshare.balanceOf(address(this)); if (_tshareBal > 0) { if (_amount > _tshareBal) { tshare.safeTransfer(_to, _tshareBal); } else { tshare.safeTransfer(_to, _amount); } } } function setOperator(address _operator) external onlyOperator { operator = _operator; } function governanceRecoverUnsupported(IERC20 _token, uint256 amount, address to) external onlyOperator { if (block.timestamp < poolEndTime + 90 days) { // do not allow to drain core token (tSHARE or lps) if less than 90 days after pool ends require(_token != tshare, "tshare"); uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { PoolInfo storage pool = poolInfo[pid]; require(_token != pool.token, "pool.token"); } } _token.safeTransfer(to, amount); } }
Bearbeitung
Datei öffnen
contract GHogRewardPool is ReentrancyGuard { using SafeMath for uint256; using SafeERC20 for IERC20; // governance address public operator; // Info of each user. struct UserInfo { uint256 amount; // How many LP tokens the user has provided. uint256 rewardDebt; // Reward debt. See explanation below. } // Info of each pool. struct PoolInfo { IERC20 token; // Address of LP token contract. uint256 withFee; // withdraw fee that is applied to created pool. uint256 allocPoint; // How many allocation points assigned to this pool. GHOGs to distribute per block. uint256 lastRewardTime; // Last time that GHOGs distribution occurs. uint256 accGhogPerShare; // Accumulated GHOGs per share, times 1e18. See below. bool isStarted; // if lastRewardTime has passed address gauge; } IERC20 public ghog; address public devFund; // Info of each pool. PoolInfo[] public poolInfo; // Info of each user that stakes LP tokens. mapping(uint256 => mapping(address => UserInfo)) public userInfo; // Total allocation points. Must be the sum of all allocation points in all pools. uint256 public totalAllocPoint = 0; // The time when GHOG mining starts. uint256 public poolStartTime; // The time when GHOG mining ends. uint256 public poolEndTime; uint256 public sharePerSecond = 0.00186122 ether; uint256 public runningTime = 370 days; address public swapxToken = 0xA04BC7140c26fc9BB1F36B1A604C7A5a88fb0E70; event Deposit(address indexed user, uint256 indexed pid, uint256 amount); event Withdraw(address indexed user, uint256 indexed pid, uint256 amount); event EmergencyWithdraw( address indexed user, uint256 indexed pid, uint256 amount ); event RewardPaid(address indexed user, uint256 amount); event DevFundUpdated(address devFund); event SharePerSecondUpdated(uint256 oldRate, uint256 newRate, uint256 timestamp); constructor( address _ghog, address _hogS, address _ghogS2, address _devFund, uint256 _poolStartTime ) { require( block.timestamp < _poolStartTime, "pool cant be started in the past" ); if (_ghog != address(0)) ghog = IERC20(_ghog); if (_devFund != address(0)) devFund = _devFund; poolStartTime = _poolStartTime; poolEndTime = _poolStartTime + runningTime; operator = msg.sender; devFund = _devFund; // create all the pools add(0, 0, IERC20(_hogS), false, 0, address(0)); // Hog-S add(0, 0, IERC20(_ghogS2), false, 0, address(0)); // GHog-S } modifier onlyOperator() { require( operator == msg.sender, "GHogRewardPool: caller is not the operator" ); _; } function poolLength() external view returns (uint256) { return poolInfo.length; } function checkPoolDuplicate(IERC20 _token) internal view { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { require( poolInfo[pid].token != _token, "GHogRewardPool: existing pool?" ); } } // Add new lp to the pool. Can only be called by operator. function add( uint256 _allocPoint, uint256 _withFee, IERC20 _token, bool _withUpdate, uint256 _lastRewardTime, address _gauge ) public onlyOperator { checkPoolDuplicate(_token); if (_withUpdate) { massUpdatePools(); } if (block.timestamp < poolStartTime) { // chef is sleeping if (_lastRewardTime == 0) { _lastRewardTime = poolStartTime; } else { if (_lastRewardTime < poolStartTime) { _lastRewardTime = poolStartTime; } } } else { // chef is cooking if (_lastRewardTime == 0 || _lastRewardTime < block.timestamp) { _lastRewardTime = block.timestamp; } } bool _isStarted = (_lastRewardTime <= poolStartTime) || (_lastRewardTime <= block.timestamp); poolInfo.push( PoolInfo({ token: _token, withFee: _withFee, allocPoint: _allocPoint, lastRewardTime: _lastRewardTime, accGhogPerShare: 0, isStarted: _isStarted, gauge: _gauge }) ); if (_isStarted) { totalAllocPoint = totalAllocPoint.add(_allocPoint); } } // Update the given pool's GHOG allocation point. Can only be called by the operator. function set( uint256 _pid, uint256 _allocPoint, uint256 _withFee, address _gauge ) public onlyOperator { massUpdatePools(); PoolInfo storage pool = poolInfo[_pid]; require(_withFee < 200); // withdraw fee cant be more than 2%; pool.withFee = _withFee; if (pool.isStarted) { totalAllocPoint = totalAllocPoint.sub(pool.allocPoint).add( _allocPoint ); } pool.allocPoint = _allocPoint; pool.gauge = _gauge; updatePool(_pid); } // AI-CONTROLLED: Updates the emission rate every 7 days based on protocol conditions // This function allows the AI to adjust the reward distribution rate function setSharePerSecond(uint256 _sharePerSecond) external onlyOperator { uint256 oldSharePerSecond = sharePerSecond; // Update to new rate sharePerSecond = _sharePerSecond; // Emit event for rate change emit SharePerSecondUpdated(oldSharePerSecond, _sharePerSecond, block.timestamp); massUpdatePools(); } function getGeneratedReward(uint256 _fromTime, uint256 _toTime) public view returns (uint256) { if (_fromTime >= _toTime) return 0; if (_toTime >= poolEndTime) { if (_fromTime >= poolEndTime) return 0; if (_fromTime <= poolStartTime) return poolEndTime.sub(poolStartTime).mul(sharePerSecond); return poolEndTime.sub(_fromTime).mul(sharePerSecond); } else { if (_toTime <= poolStartTime) return 0; if (_fromTime <= poolStartTime) return _toTime.sub(poolStartTime).mul(sharePerSecond); return _toTime.sub(_fromTime).mul(sharePerSecond); } } // Modified pendingShare to use new getGeneratedReward function pendingShare(uint256 _pid, address _user) public view returns (uint256) { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_user]; uint256 accGhogPerShare = pool.accGhogPerShare; uint256 tokenSupply = pool.gauge != address(0) ? ISwapxGauge(pool.gauge).balanceOf(address(this)) : pool.token.balanceOf(address(this)); if (block.timestamp > pool.lastRewardTime && tokenSupply != 0) { uint256 _generatedReward = getGeneratedReward( pool.lastRewardTime, block.timestamp ); uint256 _ghogReward = _generatedReward.mul(pool.allocPoint).div(totalAllocPoint); accGhogPerShare = accGhogPerShare.add(_ghogReward.mul(1e18).div(tokenSupply)); } return user.amount.mul(accGhogPerShare).div(1e18).sub(user.rewardDebt); } function massUpdatePools() public { uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { updatePool(pid); } } // Update reward variables of the given pool to be up-to-date. function updatePool(uint256 _pid) public { depositToGauge(_pid); PoolInfo storage pool = poolInfo[_pid]; if (block.timestamp <= pool.lastRewardTime) { return; } uint256 tokenSupply = pool.gauge != address(0) ? ISwapxGauge(pool.gauge).balanceOf(address(this)) : pool.token.balanceOf(address(this)); if (tokenSupply == 0) { pool.lastRewardTime = block.timestamp; return; } if (!pool.isStarted) { pool.isStarted = true; totalAllocPoint = totalAllocPoint.add(pool.allocPoint); } if (totalAllocPoint > 0) { // This now correctly accounts for all emission rate changes uint256 _generatedReward = getGeneratedReward( pool.lastRewardTime, block.timestamp ); uint256 _ghogReward = _generatedReward.mul(pool.allocPoint).div( totalAllocPoint ); pool.accGhogPerShare = pool.accGhogPerShare.add( _ghogReward.mul(1e18).div(tokenSupply) ); } pool.lastRewardTime = block.timestamp; } // Deposit LP tokens. function deposit(uint256 _pid, uint256 _amount) public nonReentrant { address _sender = msg.sender; PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_sender]; updatePool(_pid); if (user.amount > 0) { uint256 _pending = user .amount .mul(pool.accGhogPerShare) .div(1e18) .sub(user.rewardDebt); if (_pending > 0) { safeGhogTransfer(_sender, _pending); emit RewardPaid(_sender, _pending); } } if (_amount > 0) { pool.token.safeTransferFrom(_sender, address(this), _amount); user.amount = user.amount.add(_amount); depositToGauge(_pid); } user.rewardDebt = user.amount.mul(pool.accGhogPerShare).div(1e18); emit Deposit(_sender, _pid, _amount); } // Withdraw LP tokens. function withdraw(uint256 _pid, uint256 _amount) public nonReentrant { address _sender = msg.sender; PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][_sender]; require(user.amount >= _amount, "withdraw: not good"); updatePool(_pid); uint256 _pending = user.amount.mul(pool.accGhogPerShare).div(1e18).sub( user.rewardDebt ); if (_pending > 0) { safeGhogTransfer(_sender, _pending); emit RewardPaid(_sender, _pending); } if (_amount > 0) { user.amount = user.amount.sub(_amount); withdrawFromGauge(_pid, _amount); // Calculate the fee and transfer it to the devFund uint256 fee = _amount.mul(pool.withFee).div(10000); // Assuming withFee is in basis points (e.g., 100 = 1%) uint256 amountAfterFee = _amount.sub(fee); if (fee > 0) { pool.token.safeTransfer(devFund, fee); } pool.token.safeTransfer(_sender, amountAfterFee); } user.rewardDebt = user.amount.mul(pool.accGhogPerShare).div(1e18); emit Withdraw(_sender, _pid, _amount); } // Withdraw without caring about rewards. EMERGENCY ONLY. function emergencyWithdraw(uint256 _pid) public nonReentrant { PoolInfo storage pool = poolInfo[_pid]; UserInfo storage user = userInfo[_pid][msg.sender]; uint256 _amount = user.amount; user.amount = 0; user.rewardDebt = 0; withdrawFromGauge(_pid, _amount); uint256 fee = _amount.mul(pool.withFee).div(10000); // Assuming withFee is in basis points (e.g., 100 = 1%) uint256 amountAfterFee = _amount.sub(fee); if (fee > 0) { pool.token.safeTransfer(devFund, fee); } pool.token.safeTransfer(msg.sender, amountAfterFee); emit EmergencyWithdraw(msg.sender, _pid, _amount); } // Safe ghog transfer function, just in case if rounding error causes pool to not have enough Ghog. function safeGhogTransfer(address _to, uint256 _amount) internal { uint256 _ghogBal = ghog.balanceOf(address(this)); if (_ghogBal > 0) { if (_amount > _ghogBal) { ghog.safeTransfer(_to, _ghogBal); } else { ghog.safeTransfer(_to, _amount); } } } function setOperator(address _operator) external onlyOperator { operator = _operator; } function setDevFund(address _devFund) external onlyOperator { require(_devFund != address(0), "Cannot set devFund to zero address"); devFund = _devFund; emit DevFundUpdated(_devFund); } function governanceRecoverUnsupported( IERC20 _token, uint256 amount, address to ) external onlyOperator { if (block.timestamp < poolEndTime + 10 days) { // do not allow to drain core token (tSHARE or lps) if less than 90 days after pool ends require(_token != ghog, "ghog"); uint256 length = poolInfo.length; for (uint256 pid = 0; pid < length; ++pid) { PoolInfo storage pool = poolInfo[pid]; require(_token != pool.token, "pool.token"); } } _token.safeTransfer(to, amount); } // Calculate total GHOG emitted from pool start until now function getTotalEmittedShares() public view returns (uint256) { if (block.timestamp <= poolStartTime) return 0; uint256 endTime = block.timestamp; if (endTime > poolEndTime) { endTime = poolEndTime; } return getGeneratedReward(poolStartTime, endTime); } // Calculate total GHOG emitted between any two timestamps function getTotalEmittedSharesBetween(uint256 _fromTime, uint256 _toTime) public view returns (uint256) { require(_fromTime <= _toTime, "Invalid time range"); // Bound times within pool's active period if (_fromTime < poolStartTime) { _fromTime = poolStartTime; } if (_toTime > poolEndTime) { _toTime = poolEndTime; } return getGeneratedReward(_fromTime, _toTime); } function depositToGauge(uint256 _pid) internal { PoolInfo storage pool = poolInfo[_pid]; address gauge = pool.gauge; uint256 balance = pool.token.balanceOf(address(this)); // Do nothing if this pool doesn't have a gauge if (pool.gauge != address(0)) { // Do nothing if the LP token in the MC is empty if (balance > 0) { // Approve to the gauge if (pool.token.allowance(address(this), gauge) < balance ){ pool.token.approve(gauge, type(uint256).max); } ISwapxGauge(pool.gauge).deposit(balance); } } } function claimSwapxRewards(uint256 _pid) public onlyOperator { PoolInfo storage pool = poolInfo[_pid]; ISwapxGauge(pool.gauge).getReward(); // claim the swapx rewards IERC20 rewardToken = IERC20(swapxToken); uint256 rewardAmount = rewardToken.balanceOf(address(this)); if (rewardAmount > 0) { rewardToken.safeTransfer(devFund, rewardAmount); } } function withdrawFromGauge(uint256 _pid, uint256 _amount) internal { PoolInfo storage pool = poolInfo[_pid]; // Do nothing if this pool doesn't have a gauge if (pool.gauge != address(0)) { // Withdraw from the gauge ISwapxGauge(pool.gauge).withdraw(_amount); } } }
Unterschied finden