Contract Overview
Balance:
0 ETH
My Name Tag:
Not Available
Txn Hash | Method |
Block
|
From
|
To
|
Value | ||||
---|---|---|---|---|---|---|---|---|---|
0xff22410be69c0491f7966eaecbfe0971b5ed1e44e94a267c0f7650337f21aab8 | 0x60806040 | 8587227 | 152 days 19 hrs ago | 0x9841484a4a6c0b61c4eea71376d76453fd05ec9c | IN | Create: StakingData | 0 ETH | 0.01958736015 |
[ Download CSV Export ]
Latest 3 internal transactions
Parent Txn Hash | Block | From | To | Value | |||
---|---|---|---|---|---|---|---|
0x0fed01dd328407166cc632f072ed731afe0c88d5e59500cce8832666e76750d0 | 8587246 | 152 days 19 hrs ago | 0x87005978e76c7356d1e0a8118dc82eaf52d49fb1 | 0x836dbb0251fba7c2651ed2b353c9d4795c73225c | 0 ETH | ||
0x8ce97b990a0b620bf5fdde33ea35d47d7236829afcad89c9327d51d2eef8a998 | 8587240 | 152 days 19 hrs ago | 0x87005978e76c7356d1e0a8118dc82eaf52d49fb1 | 0x836dbb0251fba7c2651ed2b353c9d4795c73225c | 0 ETH | ||
0x4a2862ddc5c3becd3ada7d48f90a7fc350a3aa8ef1bd89714b37218ed80e53f9 | 8587231 | 152 days 19 hrs ago | 0x87005978e76c7356d1e0a8118dc82eaf52d49fb1 | 0x836dbb0251fba7c2651ed2b353c9d4795c73225c | 0 ETH |
[ Download CSV Export ]
Contract Name:
StakingData
Compiler Version
v0.5.16+commit.9c3226ce
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; pragma experimental ABIEncoderV2; // Inheritance import "./StakingThales.sol"; import "./EscrowThales.sol"; import "../utils/proxy/ProxyOwned.sol"; import "../utils/proxy/ProxyPausable.sol"; import "@openzeppelin/upgrades-core/contracts/Initializable.sol"; contract StakingData is Initializable, ProxyOwned, ProxyPausable { struct StakingData { bool paused; uint periodsOfStaking; uint lastPeriodTimeStamp; uint durationPeriod; uint unstakeDurationPeriod; uint baseRewardsPool; uint bonusRewardsPool; uint totalStakedAmount; uint maxSNXRewardsPercentage; uint maxAMMVolumeRewardsPercentage; uint maxThalesRoyaleRewardsPercentage; uint SNXVolumeRewardsMultiplier; uint AMMVolumeRewardsMultiplier; bool canClosePeriod; bool mergeAccountEnabled; uint totalEscrowBalanceNotIncludedInStaking; uint totalEscrowedRewards; } struct UserStakingData { uint thalesStaked; bool unstaking; uint lastUnstakeTime; uint unstakingAmount; address delegatedVolume; uint rewards; uint baseRewards; uint totalBonus; uint snxBonus; uint ammBonus; uint snxStaked; uint ammVolume; uint thalesAmmVolume; uint rangedAmmVolume; uint sportsAmmVolume; uint lastPeriodOfClaimedRewards; uint escrowedBalance; uint claimable; } struct UserVestingData { uint numberOfPeriods; uint currentVestingPeriod; uint lastPeriodTimeStamp; uint claimable; EscrowThales.VestingEntry[] vestingEntries; } address public stakingThales; address public escrowThales; function initialize(address _owner) external initializer { setOwner(_owner); } /// @notice getStakingData returns Thales staking data /// @return StakingData function getStakingData() external view returns (StakingData memory) { StakingThales staking = StakingThales(stakingThales); EscrowThales escrow = EscrowThales(escrowThales); return StakingData( staking.paused(), staking.periodsOfStaking(), staking.lastPeriodTimeStamp(), staking.durationPeriod(), staking.unstakeDurationPeriod(), staking.fixedPeriodReward(), staking.periodExtraReward(), staking.totalStakedAmount(), staking.maxSNXRewardsPercentage(), staking.maxAMMVolumeRewardsPercentage(), staking.maxThalesRoyaleRewardsPercentage(), staking.SNXVolumeRewardsMultiplier(), staking.AMMVolumeRewardsMultiplier(), staking.canClosePeriod(), staking.mergeAccountEnabled(), escrow.totalEscrowBalanceNotIncludedInStaking(), escrow.totalEscrowedRewards() ); } /// @notice getUserStakingData returns user Thales staking data /// @param user address of the user /// @return UserStakingData function getUserStakingData(address user) external view returns (UserStakingData memory) { StakingThales staking = StakingThales(stakingThales); EscrowThales escrow = EscrowThales(escrowThales); return UserStakingData( staking.stakedBalanceOf(user), staking.unstaking(user), staking.lastUnstakeTime(user), staking.unstakingAmount(user), staking.delegatedVolume(user), staking.getRewardsAvailable(user), staking.getBaseReward(user), staking.getTotalBonus(user), staking.getSNXBonus(user), staking.getAMMBonus(user), staking.getSNXStaked(user), staking.getAMMVolume(user), staking.getThalesAMMVolume(user), staking.getThalesRangedAMMVolume(user), staking.getSportsAMMVolume(user), staking.getLastPeriodOfClaimedRewards(user), escrow.totalAccountEscrowedAmount(user), escrow.claimable(user) ); } /// @notice getUserVestingData returns user Thales vesting data /// @param user address of the user /// @return UserVestingData function getUserVestingData(address user) external view returns (UserVestingData memory) { StakingThales staking = StakingThales(stakingThales); EscrowThales escrow = EscrowThales(escrowThales); uint numberOfPeriods = escrow.NUM_PERIODS(); EscrowThales.VestingEntry[] memory vestingEntries = new EscrowThales.VestingEntry[](numberOfPeriods); for (uint i = 0; i < numberOfPeriods; i++) { (uint amount, uint vesting_period) = escrow.vestingEntries(user, i); vestingEntries[i].amount = amount; vestingEntries[i].vesting_period = vesting_period; } return UserVestingData( escrow.NUM_PERIODS(), escrow.currentVestingPeriod(), staking.lastPeriodTimeStamp(), escrow.claimable(user), vestingEntries ); } function setStakingThales(address _stakingThales) external onlyOwner { stakingThales = _stakingThales; emit StakingThalesChnaged(_stakingThales); } function setEscrowThales(address _escrowThales) external onlyOwner { escrowThales = _escrowThales; emit EscrowThalesChnaged(_escrowThales); } event StakingThalesChnaged(address _stakingThales); event EscrowThalesChnaged(address _escrowThales); }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; import "openzeppelin-solidity-2.3.0/contracts/token/ERC20/SafeERC20.sol"; import "openzeppelin-solidity-2.3.0/contracts/math/SafeMath.sol"; import "../utils/proxy/ProxyReentrancyGuard.sol"; import "../utils/proxy/ProxyOwned.sol"; import "../utils/proxy/ProxyPausable.sol"; import "@openzeppelin/upgrades-core/contracts/Initializable.sol"; import "../interfaces/IEscrowThales.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/ISNXRewards.sol"; import "../interfaces/IThalesRoyale.sol"; import "../interfaces/IPriceFeed.sol"; import "../interfaces/IThalesStakingRewardsPool.sol"; import "../interfaces/IAddressResolver.sol"; import "../interfaces/ISportsAMMLiquidityPool.sol"; import "../interfaces/IThalesAMM.sol"; import "../interfaces/IPositionalMarketManager.sol"; /// @title A Staking contract that provides logic for staking and claiming rewards contract StakingThales is IStakingThales, Initializable, ProxyOwned, ProxyReentrancyGuard, ProxyPausable { /* ========== LIBRARIES ========== */ using SafeMath for uint; using SafeERC20 for IERC20; /* ========== STATE VARIABLES ========== */ IEscrowThales public iEscrowThales; IERC20 public stakingToken; IERC20 public feeToken; ISNXRewards public SNXRewards; IThalesRoyale public thalesRoyale; IPriceFeed public priceFeed; uint public periodsOfStaking; uint public lastPeriodTimeStamp; uint public durationPeriod; uint public unstakeDurationPeriod; uint public startTimeStamp; uint public currentPeriodRewards; uint public currentPeriodFees; bool public distributeFeesEnabled; uint public fixedPeriodReward; uint public periodExtraReward; uint public totalSNXRewardsInPeriod; uint public totalSNXFeesInPeriod; bool public claimEnabled; mapping(address => uint) public stakerLifetimeRewardsClaimed; mapping(address => uint) public stakerFeesClaimed; uint private _totalStakedAmount; uint private _totalEscrowedAmount; uint private _totalPendingStakeAmount; uint private _totalUnclaimedRewards; uint private _totalRewardsClaimed; uint private _totalRewardFeesClaimed; mapping(address => uint) public lastUnstakeTime; mapping(address => bool) public unstaking; mapping(address => uint) public unstakingAmount; mapping(address => uint) private _stakedBalances; mapping(address => uint) private _lastRewardsClaimedPeriod; address public thalesAMM; uint constant HUNDRED = 1e18; uint constant AMM_EXTRA_REWARD_PERIODS = 4; struct AMMVolumeEntry { uint amount; uint period; } mapping(address => uint) private lastAMMUpdatePeriod; mapping(address => AMMVolumeEntry[AMM_EXTRA_REWARD_PERIODS]) private stakerAMMVolume; bool public extraRewardsActive; IThalesStakingRewardsPool public ThalesStakingRewardsPool; uint public maxSNXRewardsPercentage; uint public maxAMMVolumeRewardsPercentage; uint public AMMVolumeRewardsMultiplier; uint public maxThalesRoyaleRewardsPercentage; uint constant ONE = 1e18; uint constant ONE_PERCENT = 1e16; uint public SNXVolumeRewardsMultiplier; mapping(address => uint) private _lastStakingPeriod; uint public totalStakedLastPeriodEnd; uint public totalEscrowedLastPeriodEnd; address public exoticBonds; IAddressResolver public addressResolver; address public thalesRangedAMM; address public sportsAMM; mapping(address => uint) private lastThalesAMMUpdatePeriod; mapping(address => AMMVolumeEntry[AMM_EXTRA_REWARD_PERIODS]) private thalesAMMVolume; mapping(address => uint) private lastThalesRangedAMMUpdatePeriod; mapping(address => AMMVolumeEntry[AMM_EXTRA_REWARD_PERIODS]) private thalesRangedAMMVolume; mapping(address => uint) private lastExoticMarketsUpdatePeriod; mapping(address => AMMVolumeEntry[AMM_EXTRA_REWARD_PERIODS]) private exoticMarketsVolume; mapping(address => uint) private lastSportsAMMUpdatePeriod; mapping(address => AMMVolumeEntry[AMM_EXTRA_REWARD_PERIODS]) private sportsAMMVolume; mapping(address => mapping(address => bool)) public canClaimOnBehalf; bool public mergeAccountEnabled; mapping(address => address) public delegatedVolume; mapping(address => bool) public supportedSportVault; mapping(address => bool) public supportedAMMVault; ISportsAMMLiquidityPool public sportsAMMLiquidityPool; /* ========== CONSTRUCTOR ========== */ function initialize( address _owner, address _iEscrowThales, //THALES address _stakingToken, //THALES address _feeToken, //sUSD uint _durationPeriod, uint _unstakeDurationPeriod, address _ISNXRewards ) public initializer { setOwner(_owner); initNonReentrant(); iEscrowThales = IEscrowThales(_iEscrowThales); stakingToken = IERC20(_stakingToken); feeToken = IERC20(_feeToken); stakingToken.approve(_iEscrowThales, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); durationPeriod = _durationPeriod; unstakeDurationPeriod = _unstakeDurationPeriod; fixedPeriodReward = 70000 * 1e18; periodExtraReward = 21000 * 1e18; SNXRewards = ISNXRewards(_ISNXRewards); } /* ========== VIEWS ========== */ /// @notice Get the total staked amount on the contract /// @return total staked amount function totalStakedAmount() external view returns (uint) { return _totalStakedAmount; } /// @notice Get the staked balance for the account /// @param account to get the staked balance for /// @return the staked balance for the account function stakedBalanceOf(address account) external view returns (uint) { return _stakedBalances[account]; } /// @notice Get the last period of claimed rewards for the account /// @param account to get the last period of claimed rewards for /// @return the last period of claimed rewards for the account function getLastPeriodOfClaimedRewards(address account) external view returns (uint) { return _lastRewardsClaimedPeriod[account]; } /// @notice Get the rewards available for the claim for the account /// @param account to get the rewards available for the claim for /// @return the rewards available for the claim for the account function getRewardsAvailable(address account) external view returns (uint) { return _calculateAvailableRewardsToClaim(account); } /// @notice Get the reward fees available for the claim for the account /// @param account to get the reward fees available for the claim for /// @return the rewards fees available for the claim for the account function getRewardFeesAvailable(address account) external view returns (uint) { return _calculateAvailableFeesToClaim(account); } /// @notice Get the total rewards claimed for the account until now /// @param account to get the total rewards claimed for /// @return the total rewards claimed for the account until now function getAlreadyClaimedRewards(address account) external view returns (uint) { return stakerLifetimeRewardsClaimed[account]; } /// @notice Get the rewards funds available on the rewards pool /// @return the rewards funds available on the rewards pool function getContractRewardFunds() external view returns (uint) { return stakingToken.balanceOf(address(ThalesStakingRewardsPool)); } /// @notice Get the fee funds available on the staking contract /// @return the fee funds available on the staking contract function getContractFeeFunds() external view returns (uint) { return feeToken.balanceOf(address(this)); } /// @notice Set staking parametars /// @param _claimEnabled enable/disable claim rewards /// @param _distributeFeesEnabled enable/disable fees distribution /// @param _durationPeriod duration of the staking period /// @param _unstakeDurationPeriod duration of the unstaking cooldown period /// @param _mergeAccountEnabled enable/disable account merging function setStakingParameters( bool _claimEnabled, bool _distributeFeesEnabled, uint _durationPeriod, uint _unstakeDurationPeriod, bool _mergeAccountEnabled ) external onlyOwner { claimEnabled = _claimEnabled; distributeFeesEnabled = _distributeFeesEnabled; durationPeriod = _durationPeriod; unstakeDurationPeriod = _unstakeDurationPeriod; mergeAccountEnabled = _mergeAccountEnabled; emit StakingParametersChanged( _claimEnabled, _distributeFeesEnabled, _durationPeriod, _unstakeDurationPeriod, _mergeAccountEnabled ); } /// @notice Set staking rewards parameters /// @param _fixedReward amount for weekly base rewards pool /// @param _extraReward amount for weekly bonus rewards pool /// @param _extraRewardsActive enable/disable bonus rewards /// @param _maxSNXRewardsPercentage maximum percentage for SNX rewards /// @param _maxAMMVolumeRewardsPercentage maximum percentage for protocol volume rewards /// @param _maxThalesRoyaleRewardsPercentage maximum percentage for rewards for participation in Thales Royale /// @param _SNXVolumeRewardsMultiplier multiplier for SNX rewards /// @param _AMMVolumeRewardsMultiplier multiplier for protocol volume rewards function setStakingRewardsParameters( uint _fixedReward, uint _extraReward, bool _extraRewardsActive, uint _maxSNXRewardsPercentage, uint _maxAMMVolumeRewardsPercentage, uint _maxThalesRoyaleRewardsPercentage, uint _SNXVolumeRewardsMultiplier, uint _AMMVolumeRewardsMultiplier ) public onlyOwner { fixedPeriodReward = _fixedReward; periodExtraReward = _extraReward; extraRewardsActive = _extraRewardsActive; maxSNXRewardsPercentage = _maxSNXRewardsPercentage; maxAMMVolumeRewardsPercentage = _maxAMMVolumeRewardsPercentage; maxThalesRoyaleRewardsPercentage = _maxThalesRoyaleRewardsPercentage; SNXVolumeRewardsMultiplier = _SNXVolumeRewardsMultiplier; AMMVolumeRewardsMultiplier = _AMMVolumeRewardsMultiplier; emit StakingRewardsParametersChanged( _fixedReward, _extraReward, _extraRewardsActive, _maxSNXRewardsPercentage, _maxAMMVolumeRewardsPercentage, _AMMVolumeRewardsMultiplier, _maxThalesRoyaleRewardsPercentage, _SNXVolumeRewardsMultiplier ); } /// @notice Set contract addresses /// @param _snxRewards address of SNX rewards contract /// @param _royale address of Thales Royale contract /// @param _thalesAMM address of Thales AMM contract /// @param _thalesRangedAMM address of Thales ranged AMM contract /// @param _exoticBonds address of exotic markets bonds contract /// @param _sportsAMM address of sport markets AMM contract /// @param _priceFeed address of price feed contract /// @param _thalesStakingRewardsPool address of Thales staking rewards pool /// @param _addressResolver address of address resolver contract function setAddresses( address _snxRewards, address _royale, address _thalesAMM, address _thalesRangedAMM, address _exoticBonds, address _sportsAMM, address _priceFeed, address _thalesStakingRewardsPool, address _addressResolver, address _sportsAMMLiquidityPool ) external onlyOwner { SNXRewards = ISNXRewards(_snxRewards); thalesRoyale = IThalesRoyale(_royale); thalesAMM = _thalesAMM; thalesRangedAMM = _thalesRangedAMM; exoticBonds = _exoticBonds; sportsAMM = _sportsAMM; priceFeed = IPriceFeed(_priceFeed); ThalesStakingRewardsPool = IThalesStakingRewardsPool(_thalesStakingRewardsPool); addressResolver = IAddressResolver(_addressResolver); sportsAMMLiquidityPool = ISportsAMMLiquidityPool(_sportsAMMLiquidityPool); emit AddressesChanged( _snxRewards, _royale, _thalesAMM, _thalesRangedAMM, _exoticBonds, _sportsAMM, _priceFeed, _thalesStakingRewardsPool, _addressResolver, _sportsAMMLiquidityPool ); } /// @notice Set address of Escrow Thales contract /// @param _escrowThalesContract address of Escrow Thales contract function setEscrow(address _escrowThalesContract) external onlyOwner { if (address(iEscrowThales) != address(0)) { stakingToken.approve(address(iEscrowThales), 0); } iEscrowThales = IEscrowThales(_escrowThalesContract); stakingToken.approve(_escrowThalesContract, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); emit EscrowChanged(_escrowThalesContract); } /// @notice add a sport vault address to count towards gamified staking volume /// @param _sportVault address to set /// @param value to set function setSupportedSportVault(address _sportVault, bool value) external onlyOwner { supportedSportVault[_sportVault] = value; emit SupportedSportVaultSet(_sportVault, value); } /// @notice add a amm vault address to count towards gamified staking volume /// @param _ammVault address to set /// @param value to set function setSupportedAMMVault(address _ammVault, bool value) external onlyOwner { supportedAMMVault[_ammVault] = value; emit SupportedAMMVaultSet(_ammVault, value); } /// @notice Get the address of the SNX rewards contract /// @return the address of the SNX rewards contract function getSNXRewardsAddress() public view returns (address) { if (address(addressResolver) == address(0)) { return address(0); } else { return addressResolver.getAddress("Issuer"); } } /// @notice Get the amount of SNX staked for the account /// @param account to get the amount of SNX staked for /// @return the amount of SNX staked for the account function getSNXStaked(address account) external view returns (uint) { return _getSNXStakedForAccount(account); } /// @notice Get the base reward amount available for the claim for the account /// @param account to get the base reward amount available for the claim for /// @return the base reward amount available for the claim for the account function getBaseReward(address account) public view returns (uint _baseRewards) { if ( !((_lastStakingPeriod[account] == periodsOfStaking) || (_stakedBalances[account] == 0) || (_lastRewardsClaimedPeriod[account] == periodsOfStaking) || (totalStakedLastPeriodEnd == 0)) ) { _baseRewards = _stakedBalances[account] .add(iEscrowThales.getStakedEscrowedBalanceForRewards(account)) .mul(currentPeriodRewards) .div(totalStakedLastPeriodEnd.add(totalEscrowedLastPeriodEnd)); } } /// @notice Get the total protocol volume for the account /// @param account to get the total protocol volume for /// @return the total protocol volume for the account function getAMMVolume(address account) external view returns (uint) { return _getTotalAMMVolume(account); } /// @notice Get the AMM volume for the account /// @param account to get the AMM volume for /// @return the AMM volume for the account function getThalesAMMVolume(address account) external view returns (uint volumeforAccount) { for (uint i = 0; i < AMM_EXTRA_REWARD_PERIODS; i++) { if (periodsOfStaking < thalesAMMVolume[account][i].period.add(AMM_EXTRA_REWARD_PERIODS)) volumeforAccount = volumeforAccount.add(thalesAMMVolume[account][i].amount); } } /// @notice Get the ranged AMM volume for the account /// @param account to get the ranged AMM volume for /// @return the ranged AMM volume for the account function getThalesRangedAMMVolume(address account) external view returns (uint volumeforAccount) { for (uint i = 0; i < AMM_EXTRA_REWARD_PERIODS; i++) { if (periodsOfStaking < thalesRangedAMMVolume[account][i].period.add(AMM_EXTRA_REWARD_PERIODS)) volumeforAccount = volumeforAccount.add(thalesRangedAMMVolume[account][i].amount); } } /// @notice Get the exotic markets volume for the account /// @param account to get exotic markets volume for /// @return the exotic markets volume for the account function getExoticMarketsVolume(address account) external view returns (uint volumeforAccount) { for (uint i = 0; i < AMM_EXTRA_REWARD_PERIODS; i++) { if (periodsOfStaking < exoticMarketsVolume[account][i].period.add(AMM_EXTRA_REWARD_PERIODS)) volumeforAccount = volumeforAccount.add(exoticMarketsVolume[account][i].amount); } } /// @notice Get the sport markets AMM volume for the account /// @param account to get the sport markets AMM volume for /// @return the sport markets AMM volume for the account function getSportsAMMVolume(address account) external view returns (uint volumeforAccount) { for (uint i = 0; i < AMM_EXTRA_REWARD_PERIODS; i++) { if (periodsOfStaking < sportsAMMVolume[account][i].period.add(AMM_EXTRA_REWARD_PERIODS)) volumeforAccount = volumeforAccount.add(sportsAMMVolume[account][i].amount); } } /// @notice Get the percentage of SNX rewards for the account /// @param account to get the percentage of SNX rewards for /// @return the percentage of SNX rewards for the account function getSNXBonusPercentage(address account) public view returns (uint) { uint baseReward = getBaseReward(account); if (baseReward == 0) { return 0; } uint stakedSNX = _getSNXStakedForAccount(account); // SNX staked more than base reward return stakedSNX >= baseReward.mul(SNXVolumeRewardsMultiplier) ? maxSNXRewardsPercentage.mul(ONE_PERCENT) : stakedSNX.mul(maxSNXRewardsPercentage).mul(ONE_PERCENT).div(baseReward.mul(SNXVolumeRewardsMultiplier)); } /// @notice Get the SNX staking bonus rewards for the account /// @param account to get the SNX staking bonus rewards for /// @return the SNX staking bonus rewards for the account function getSNXBonus(address account) public view returns (uint) { uint baseReward = getBaseReward(account); uint SNXBonusPercentage = getSNXBonusPercentage(account); return baseReward.mul(SNXBonusPercentage).div(ONE); } /// @notice Get the percentage of protocol volume rewards for the account /// @param account to get the percentage of protocol volume rewards for /// @return the percentage of protocol volume rewards for the account function getAMMBonusPercentage(address account) public view returns (uint) { uint baseReward = getBaseReward(account); if (baseReward == 0) { return 0; } return _getTotalAMMVolume(account) >= baseReward.mul(AMMVolumeRewardsMultiplier) ? maxAMMVolumeRewardsPercentage.mul(ONE_PERCENT) : _getTotalAMMVolume(account).mul(ONE_PERCENT).mul(maxAMMVolumeRewardsPercentage).div( baseReward.mul(AMMVolumeRewardsMultiplier) ); } /// @notice Get the protocol volume bonus rewards for the account /// @param account to get the protocol volume bonus rewards for /// @return the protocol volume bonus rewards for the account function getAMMBonus(address account) public view returns (uint) { uint baseReward = getBaseReward(account); uint AMMPercentage = getAMMBonusPercentage(account); return baseReward.mul(AMMPercentage).div(ONE); } function getTotalBonusPercentage(address account) public view returns (uint) { uint snxPercentage = getSNXBonusPercentage(account); uint ammPercentage = getAMMBonusPercentage(account); return snxPercentage.add(ammPercentage); } /// @notice Get the total bonus rewards for the account /// @param account to get the total bonus rewards for /// @return the total bonus rewards for the account function getTotalBonus(address account) public view returns (uint) { uint baseReward = getBaseReward(account); uint totalBonusPercentage = getTotalBonusPercentage(account); // failsafe require(totalBonusPercentage < ONE, "Bonus Exceeds base rewards"); return baseReward.mul(totalBonusPercentage).div(ONE); } /// @notice Get the flag that indicates whether the current period can be closed /// @return the flag that indicates whether the current period can be closed function canClosePeriod() external view returns (bool) { return (startTimeStamp > 0 && (block.timestamp >= lastPeriodTimeStamp.add(durationPeriod))); } /// @notice Get the current SNX target ratio /// @return the current SNX target ratio function getSNXTargetRatio() public view returns (uint) { uint hund = 100 * 100 * 1e18; return hund.div(ISNXRewards(getSNXRewardsAddress()).issuanceRatio()); } /// @notice Get the current SNX C-Ratio for the account /// @param account to get the current SNX C-Ratio for /// @return the current SNX C-Ratio for the account function getCRatio(address account) public view returns (uint) { uint debt = ISNXRewards(getSNXRewardsAddress()).debtBalanceOf(account, "sUSD"); if (debt == 0) { return 0; } uint hund = 100 * 100 * 1e18; (uint cRatio, ) = ISNXRewards(getSNXRewardsAddress()).collateralisationRatioAndAnyRatesInvalid(account); return hund.div(cRatio); } /// @notice Get the current SNX rate /// @return the current SNX rate function getSNXRateForCurrency() public view returns (uint) { return priceFeed.rateForCurrency("SNX"); } /// @notice Get the current SNX debt for the account /// @param account to get the current SNX debt for /// @return the current SNX debt for the account function getSNXDebt(address account) public view returns (uint) { return ISNXRewards(getSNXRewardsAddress()).debtBalanceOf(account, "sUSD"); } /* ========== PUBLIC ========== */ /// @notice Start the first staking period function startStakingPeriod() external onlyOwner { require(startTimeStamp == 0, "Staking has already started"); startTimeStamp = block.timestamp; periodsOfStaking = 0; lastPeriodTimeStamp = startTimeStamp; _totalUnclaimedRewards = 0; _totalRewardsClaimed = 0; _totalRewardFeesClaimed = 0; _totalStakedAmount = 0; _totalEscrowedAmount = 0; _totalPendingStakeAmount = 0; emit StakingPeriodStarted(); } /// @notice Close the current staking period function closePeriod() external nonReentrant notPaused { require(startTimeStamp > 0, "Staking period has not started"); require( block.timestamp >= lastPeriodTimeStamp.add(durationPeriod), "A full period has not passed since the last closed period" ); iEscrowThales.updateCurrentPeriod(); lastPeriodTimeStamp = block.timestamp; periodsOfStaking = iEscrowThales.currentVestingPeriod(); _totalEscrowedAmount = iEscrowThales.totalEscrowedRewards().sub( iEscrowThales.totalEscrowBalanceNotIncludedInStaking() ); //Actions taken on every closed period currentPeriodRewards = fixedPeriodReward; _totalUnclaimedRewards = _totalUnclaimedRewards.add(currentPeriodRewards.add(periodExtraReward)); currentPeriodFees = feeToken.balanceOf(address(this)); totalStakedLastPeriodEnd = _totalStakedAmount; totalEscrowedLastPeriodEnd = _totalEscrowedAmount; emit ClosedPeriod(periodsOfStaking, lastPeriodTimeStamp); } /// @notice Stake the amount of staking token to get weekly rewards /// @param amount to stake function stake(uint amount) external nonReentrant notPaused { _stake(amount, msg.sender, msg.sender); emit Staked(msg.sender, amount); } /// @notice Start unstaking cooldown for the amount of staking token /// @param amount to unstake function startUnstake(uint amount) external notPaused { require(amount > 0, "Cannot unstake 0"); require(_stakedBalances[msg.sender] >= amount, "Account doesnt have that much staked"); require(!unstaking[msg.sender], "Account has already triggered unstake cooldown"); if (address(sportsAMMLiquidityPool) != address(0)) { require(!sportsAMMLiquidityPool.isUserLPing(msg.sender), "Cannot unstake while LPing"); } if (_calculateAvailableRewardsToClaim(msg.sender) > 0) { _claimReward(msg.sender); } lastUnstakeTime[msg.sender] = block.timestamp; unstaking[msg.sender] = true; _totalStakedAmount = _totalStakedAmount.sub(amount); unstakingAmount[msg.sender] = amount; _stakedBalances[msg.sender] = _stakedBalances[msg.sender].sub(amount); // on full unstake add his escrowed balance to totalEscrowBalanceNotIncludedInStaking if (_stakedBalances[msg.sender] == 0) { if (iEscrowThales.totalAccountEscrowedAmount(msg.sender) > 0) { iEscrowThales.addTotalEscrowBalanceNotIncludedInStaking( iEscrowThales.totalAccountEscrowedAmount(msg.sender) ); } } emit UnstakeCooldown(msg.sender, lastUnstakeTime[msg.sender].add(unstakeDurationPeriod), amount); } /// @notice Cancel unstaking cooldown function cancelUnstake() external notPaused { require(unstaking[msg.sender], "Account is not unstaking"); // on revert full unstake remove his escrowed balance from totalEscrowBalanceNotIncludedInStaking _subtractTotalEscrowBalanceNotIncludedInStaking(msg.sender); if (_calculateAvailableRewardsToClaim(msg.sender) > 0) { _claimReward(msg.sender); } unstaking[msg.sender] = false; _totalStakedAmount = _totalStakedAmount.add(unstakingAmount[msg.sender]); _stakedBalances[msg.sender] = _stakedBalances[msg.sender].add(unstakingAmount[msg.sender]); unstakingAmount[msg.sender] = 0; emit CancelUnstake(msg.sender); } /// @notice Unstake after the cooldown period expired function unstake() external notPaused { require(unstaking[msg.sender], "Account has not triggered unstake cooldown"); require( lastUnstakeTime[msg.sender] < block.timestamp.sub(unstakeDurationPeriod), "Cannot unstake yet, cooldown not expired." ); unstaking[msg.sender] = false; uint unstakeAmount = unstakingAmount[msg.sender]; stakingToken.safeTransfer(msg.sender, unstakeAmount); unstakingAmount[msg.sender] = 0; emit Unstaked(msg.sender, unstakeAmount); } /// @notice Claim the weekly staking rewards function claimReward() public nonReentrant notPaused { _claimReward(msg.sender); } /// @notice Claim the weekly staking rewards on behalf of the account /// @param account to claim on behalf of function claimRewardOnBehalf(address account) public nonReentrant notPaused { require(account != address(0) && account != msg.sender, "Invalid address"); require(canClaimOnBehalf[account][msg.sender], "Cannot claim on behalf"); _claimReward(account); } /// @notice Update the protocol volume for the account /// @param account to update the protocol volume for /// @param amount to add to the existing protocol volume function updateVolume(address account, uint amount) external { require(account != address(0) && amount > 0, "Invalid params"); if (delegatedVolume[account] != address(0)) { account = delegatedVolume[account]; } require( msg.sender == thalesAMM || msg.sender == exoticBonds || msg.sender == thalesRangedAMM || msg.sender == sportsAMM || supportedSportVault[msg.sender] || supportedAMMVault[msg.sender], "Invalid address" ); amount = IPositionalMarketManager(IThalesAMM(sportsAMM).manager()).reverseTransformCollateral(amount); if (lastAMMUpdatePeriod[account] < periodsOfStaking) { stakerAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = 0; stakerAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].period = periodsOfStaking; lastAMMUpdatePeriod[account] = periodsOfStaking; } stakerAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = stakerAMMVolume[account][ periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS) ].amount.add(amount); if (msg.sender == thalesAMM || supportedAMMVault[msg.sender]) { if (lastThalesAMMUpdatePeriod[account] < periodsOfStaking) { thalesAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = 0; thalesAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].period = periodsOfStaking; lastThalesAMMUpdatePeriod[account] = periodsOfStaking; } thalesAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = thalesAMMVolume[account][ periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS) ].amount.add(amount); } if (msg.sender == thalesRangedAMM) { if (lastThalesRangedAMMUpdatePeriod[account] < periodsOfStaking) { thalesRangedAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = 0; thalesRangedAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].period = periodsOfStaking; lastThalesRangedAMMUpdatePeriod[account] = periodsOfStaking; } thalesRangedAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = thalesRangedAMMVolume[ account ][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount.add(amount); } if (msg.sender == sportsAMM || supportedSportVault[msg.sender]) { if (lastSportsAMMUpdatePeriod[account] < periodsOfStaking) { sportsAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = 0; sportsAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].period = periodsOfStaking; lastSportsAMMUpdatePeriod[account] = periodsOfStaking; } sportsAMMVolume[account][periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS)].amount = sportsAMMVolume[account][ periodsOfStaking.mod(AMM_EXTRA_REWARD_PERIODS) ].amount.add(amount); } emit AMMVolumeUpdated(account, amount, msg.sender); } /// @notice Merge account to transfer all staking amounts to another account /// @param destAccount to merge into function mergeAccount(address destAccount) external notPaused { require(mergeAccountEnabled, "Merge account is disabled"); require(destAccount != address(0) && destAccount != msg.sender, "Invalid address"); require( _calculateAvailableRewardsToClaim(msg.sender) == 0 && _calculateAvailableRewardsToClaim(destAccount) == 0, "Cannot merge, claim rewards on both accounts before merging" ); require( !unstaking[msg.sender] && !unstaking[destAccount], "Cannot merge, cancel unstaking on both accounts before merging" ); iEscrowThales.mergeAccount(msg.sender, destAccount); _stakedBalances[destAccount] = _stakedBalances[destAccount].add(_stakedBalances[msg.sender]); stakerLifetimeRewardsClaimed[destAccount] = stakerLifetimeRewardsClaimed[destAccount].add( stakerLifetimeRewardsClaimed[msg.sender] ); stakerFeesClaimed[destAccount] = stakerFeesClaimed[destAccount].add(stakerFeesClaimed[msg.sender]); _lastRewardsClaimedPeriod[destAccount] = periodsOfStaking; _lastStakingPeriod[destAccount] = periodsOfStaking; lastAMMUpdatePeriod[destAccount] = periodsOfStaking; uint stakerAMMVolumeIndex; uint stakerAMMVolumePeriod; for (uint i = 1; i <= AMM_EXTRA_REWARD_PERIODS; i++) { stakerAMMVolumeIndex = periodsOfStaking.add(i).mod(AMM_EXTRA_REWARD_PERIODS); stakerAMMVolumePeriod = periodsOfStaking.sub(AMM_EXTRA_REWARD_PERIODS.sub(i)); if (stakerAMMVolumePeriod != stakerAMMVolume[destAccount][stakerAMMVolumeIndex].period) { stakerAMMVolume[destAccount][stakerAMMVolumeIndex].amount = 0; stakerAMMVolume[destAccount][stakerAMMVolumeIndex].period = stakerAMMVolumePeriod; } if (stakerAMMVolumePeriod == stakerAMMVolume[msg.sender][stakerAMMVolumeIndex].period) { stakerAMMVolume[destAccount][stakerAMMVolumeIndex].amount = stakerAMMVolume[destAccount][ stakerAMMVolumeIndex ].amount.add(stakerAMMVolume[msg.sender][stakerAMMVolumeIndex].amount); } } delete lastUnstakeTime[msg.sender]; delete unstaking[msg.sender]; delete unstakingAmount[msg.sender]; delete _stakedBalances[msg.sender]; delete stakerLifetimeRewardsClaimed[msg.sender]; delete stakerFeesClaimed[msg.sender]; delete _lastRewardsClaimedPeriod[msg.sender]; delete _lastStakingPeriod[msg.sender]; delete lastAMMUpdatePeriod[msg.sender]; delete stakerAMMVolume[msg.sender]; emit AccountMerged(msg.sender, destAccount); } /// @notice Set flag to enable/disable claim on behalf of the msg.sender for the account /// @param account to enable/disable claim on behalf of msg.sender /// @param _canClaimOnBehalf enable/disable claim on behalf of the msg.sender for the account function setCanClaimOnBehalf(address account, bool _canClaimOnBehalf) external notPaused { require(account != address(0) && account != msg.sender, "Invalid address"); canClaimOnBehalf[msg.sender][account] = _canClaimOnBehalf; emit CanClaimOnBehalfChanged(msg.sender, account, _canClaimOnBehalf); } /// @notice delegate your volume to another address /// @param account address to delegate to function delegateVolume(address account) external notPaused { delegatedVolume[msg.sender] = account; emit DelegatedVolume(account); } /* ========== INTERNAL FUNCTIONS ========== */ function _claimReward(address account) internal notPaused { require(claimEnabled, "Claiming is not enabled."); require(startTimeStamp > 0, "Staking period has not started"); //Calculate rewards if (distributeFeesEnabled) { uint availableFeesToClaim = _calculateAvailableFeesToClaim(account); if (availableFeesToClaim > 0) { feeToken.safeTransfer(account, availableFeesToClaim); stakerFeesClaimed[account] = stakerFeesClaimed[account].add(availableFeesToClaim); _totalRewardFeesClaimed = _totalRewardFeesClaimed.add(availableFeesToClaim); emit FeeRewardsClaimed(account, availableFeesToClaim); } } uint availableRewardsToClaim = _calculateAvailableRewardsToClaim(account); if (availableRewardsToClaim > 0) { // Transfer THALES to Escrow contract ThalesStakingRewardsPool.addToEscrow(account, availableRewardsToClaim); // Record the total claimed rewards stakerLifetimeRewardsClaimed[account] = stakerLifetimeRewardsClaimed[account].add(availableRewardsToClaim); _totalRewardsClaimed = _totalRewardsClaimed.add(availableRewardsToClaim); _totalUnclaimedRewards = _totalUnclaimedRewards.sub(availableRewardsToClaim); emit RewardsClaimed( account, availableRewardsToClaim, getBaseReward(account), getSNXBonus(account), getAMMBonus(account) ); } // Update last claiming period _lastRewardsClaimedPeriod[account] = periodsOfStaking; } function _stake( uint amount, address staker, address sender ) internal { require(startTimeStamp > 0, "Staking period has not started"); require(amount > 0, "Cannot stake 0"); require(!unstaking[staker], "The staker is paused from staking due to unstaking"); // Check if there are not claimable rewards from last period. // Claim them, and add new stake if (_calculateAvailableRewardsToClaim(staker) > 0) { _claimReward(staker); } _lastStakingPeriod[staker] = periodsOfStaking; // if just started staking subtract his escrowed balance from totalEscrowBalanceNotIncludedInStaking _subtractTotalEscrowBalanceNotIncludedInStaking(staker); _totalStakedAmount = _totalStakedAmount.add(amount); _stakedBalances[staker] = _stakedBalances[staker].add(amount); stakingToken.safeTransferFrom(sender, address(this), amount); } function _subtractTotalEscrowBalanceNotIncludedInStaking(address account) internal { if (_stakedBalances[account] == 0) { if (iEscrowThales.totalAccountEscrowedAmount(account) > 0) { iEscrowThales.subtractTotalEscrowBalanceNotIncludedInStaking( iEscrowThales.totalAccountEscrowedAmount(account) ); } } } function _calculateAvailableRewardsToClaim(address account) internal view returns (uint) { uint baseReward = getBaseReward(account); if (baseReward == 0) { return 0; } if (!extraRewardsActive) { return baseReward; } else { return baseReward.add(getTotalBonus(account)); } } function _calculateAvailableFeesToClaim(address account) internal view returns (uint) { uint baseReward = getBaseReward(account); if (baseReward == 0) { return 0; } return _stakedBalances[account] .add(iEscrowThales.getStakedEscrowedBalanceForRewards(account)) .mul(currentPeriodFees) .div(totalStakedLastPeriodEnd.add(totalEscrowedLastPeriodEnd)); } function _getSNXStakedForAccount(address account) internal view returns (uint snxStaked) { if (address(addressResolver) != address(0)) { uint cRatio = getCRatio(account); uint targetRatio = getSNXTargetRatio(); uint snxPrice = priceFeed.rateForCurrency("SNX"); uint debt = ISNXRewards(getSNXRewardsAddress()).debtBalanceOf(account, "sUSD"); if (cRatio < targetRatio) { snxStaked = (cRatio.mul(cRatio).mul(debt).mul(1e14)).div(targetRatio.mul(snxPrice)); } else { snxStaked = (targetRatio.mul(debt).mul(1e14)).div(snxPrice); } } } function _getTotalAMMVolume(address account) internal view returns (uint totalAMMforAccount) { if (!(periodsOfStaking >= lastAMMUpdatePeriod[account].add(AMM_EXTRA_REWARD_PERIODS))) { for (uint i = 0; i < AMM_EXTRA_REWARD_PERIODS; i++) { if (periodsOfStaking < stakerAMMVolume[account][i].period.add(AMM_EXTRA_REWARD_PERIODS)) totalAMMforAccount = totalAMMforAccount.add(stakerAMMVolume[account][i].amount); } } } /* ========== EVENTS ========== */ event RewardAdded(uint reward); event Staked(address user, uint amount); event StakedOnBehalf(address user, address staker, uint amount); event ClosedPeriod(uint PeriodOfStaking, uint lastPeriodTimeStamp); event RewardsClaimed(address account, uint unclaimedReward, uint baseRewards, uint snxBonus, uint protocolBonus); event FeeRewardsClaimed(address account, uint unclaimedFees); event UnstakeCooldown(address account, uint cooldownTime, uint amount); event CancelUnstake(address account); event Unstaked(address account, uint unstakeAmount); event StakingParametersChanged( bool claimEnabled, bool distributeFeesEnabled, uint durationPeriod, uint unstakeDurationPeriod, bool mergeAccountEnabled ); event StakingRewardsParametersChanged( uint fixedPeriodReward, uint periodExtraReward, bool extraRewardsActive, uint maxSNXRewardsPercentage, uint maxAMMVolumeRewardsPercentage, uint maxThalesRoyaleRewardsPercentage, uint SNXVolumeRewardsMultiplier, uint AMMVolumeRewardsMultiplier ); event AddressesChanged( address SNXRewards, address thalesRoyale, address thalesAMM, address thalesRangedAMM, address exoticBonds, address sportsAMM, address priceFeed, address ThalesStakingRewardsPool, address addressResolver, address sportsAMMLiquidityPool ); event EscrowChanged(address newEscrow); event StakingPeriodStarted(); event AMMVolumeUpdated(address account, uint amount, address source); event AccountMerged(address srcAccount, address destAccount); event DelegatedVolume(address destAccount); event CanClaimOnBehalfChanged(address sender, address account, bool canClaimOnBehalf); event SupportedAMMVaultSet(address vault, bool value); event SupportedSportVaultSet(address vault, bool value); }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; import "openzeppelin-solidity-2.3.0/contracts/math/SafeMath.sol"; import "openzeppelin-solidity-2.3.0/contracts/token/ERC20/SafeERC20.sol"; import "../utils/proxy/ProxyReentrancyGuard.sol"; import "../utils/proxy/ProxyOwned.sol"; import "../utils/proxy/ProxyPausable.sol"; import "@openzeppelin/upgrades-core/contracts/Initializable.sol"; import "../interfaces/IEscrowThales.sol"; import "../interfaces/IStakingThales.sol"; import "../interfaces/IThalesStakingRewardsPool.sol"; /// @title A Escrow contract that provides logic for escrow and vesting staking rewards contract EscrowThales is IEscrowThales, Initializable, ProxyOwned, ProxyReentrancyGuard, ProxyPausable { using SafeMath for uint; using SafeERC20 for IERC20; IERC20 public vestingToken; IStakingThales public iStakingThales; address public airdropContract; uint public constant NUM_PERIODS = 10; uint public totalEscrowedRewards; uint public totalEscrowBalanceNotIncludedInStaking; uint public currentVestingPeriod; uint private _totalVested; struct VestingEntry { uint amount; uint vesting_period; } mapping(address => VestingEntry[NUM_PERIODS]) public vestingEntries; mapping(address => uint) public totalAccountEscrowedAmount; mapping(address => uint) public lastPeriodAddedReward; bool private testMode; IThalesStakingRewardsPool public ThalesStakingRewardsPool; /* ========== CONSTRUCTOR ========== */ function initialize( address _owner, address _vestingToken //THALES ) public initializer { setOwner(_owner); initNonReentrant(); vestingToken = IERC20(_vestingToken); } /* ========== VIEWS ========== */ /// @notice Get the vesting period of specific vesting entry for the account /// @param account to get the vesting period for /// @param index of vesting entry to get vesting period for /// @return the vesting period function getStakerPeriod(address account, uint index) external view returns (uint) { require(account != address(0), "Invalid account address"); return vestingEntries[account][index].vesting_period; } /// @notice Get the vesting amount of specific vesting entry for the account /// @param account to get the vesting amount for /// @param index of vesting entry to get vesting amount for /// @return the vesting amount for the account function getStakerAmounts(address account, uint index) external view returns (uint) { require(account != address(0), "Invalid account address"); return vestingEntries[account][index].amount; } /// @notice Get the staked escrowed balance for the account /// @param account to get the staked escrowed balance for /// @return the staked escrowed balance for the account function getStakedEscrowedBalanceForRewards(address account) external view returns (uint) { if (lastPeriodAddedReward[account] == currentVestingPeriod) { return totalAccountEscrowedAmount[account].sub( vestingEntries[account][currentVestingPeriod.mod(NUM_PERIODS)].amount ); } else { return totalAccountEscrowedAmount[account]; } } /// @notice Get the claimable vesting amount for the account /// @param account to get the claimable vesting amount for /// @return the claimable vesting amount for the account function claimable(address account) external view returns (uint) { require(account != address(0), "Invalid address"); return totalAccountEscrowedAmount[account].sub(_getVestingNotAvailable(account)); } /* ========== PUBLIC ========== */ /// @notice Add the amount of staking token to the escrow for the account /// @param account to add the amount to the escrow for /// @param amount to add to the escrow function addToEscrow(address account, uint amount) external notPaused { require(account != address(0), "Invalid address"); require(amount > 0, "Amount is 0"); require( msg.sender == address(ThalesStakingRewardsPool) || msg.sender == airdropContract, "Add to escrow can only be called from staking or ongoing airdrop contracts" ); totalAccountEscrowedAmount[account] = totalAccountEscrowedAmount[account].add(amount); if (lastPeriodAddedReward[account] == currentVestingPeriod) { vestingEntries[account][currentVestingPeriod.mod(NUM_PERIODS)].amount = vestingEntries[account][ currentVestingPeriod.mod(NUM_PERIODS) ] .amount .add(amount); } else { vestingEntries[account][currentVestingPeriod.mod(NUM_PERIODS)].amount = amount; } vestingEntries[account][currentVestingPeriod.mod(NUM_PERIODS)].vesting_period = currentVestingPeriod.add( NUM_PERIODS ); lastPeriodAddedReward[account] = currentVestingPeriod; totalEscrowedRewards = totalEscrowedRewards.add(amount); //Transfering THALES from StakingThales to EscrowThales vestingToken.safeTransferFrom(msg.sender, address(this), amount); // add to totalEscrowBalanceNotIncludedInStaking if user is not staking if (iStakingThales.stakedBalanceOf(account) == 0) { totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.add(amount); } emit AddedToEscrow(account, amount); } /// @notice Vest the amount of escrowed tokens /// @param amount to vest function vest(uint amount) external nonReentrant notPaused returns (bool) { require(amount > 0, "Claimed amount is 0"); require(currentVestingPeriod >= NUM_PERIODS, "Vesting rewards still not available"); uint vestingAmount = 0; vestingAmount = totalAccountEscrowedAmount[msg.sender].sub(_getVestingNotAvailable(msg.sender)); // Amount must be lower than the reward require(amount <= vestingAmount, "Amount exceeds the claimable rewards"); totalAccountEscrowedAmount[msg.sender] = totalAccountEscrowedAmount[msg.sender].sub(amount); totalEscrowedRewards = totalEscrowedRewards.sub(amount); _totalVested = _totalVested.add(amount); vestingToken.safeTransfer(msg.sender, amount); // subtract from totalEscrowBalanceNotIncludedInStaking if user is not staking if (iStakingThales.stakedBalanceOf(msg.sender) == 0) { totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.sub(amount); } emit Vested(msg.sender, amount); return true; } /// @notice Add the amount of tokens to the total escrow balance not included in staking /// @param amount to add function addTotalEscrowBalanceNotIncludedInStaking(uint amount) external { require(msg.sender == address(iStakingThales), "Can only be called from staking contract"); totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.add(amount); } /// @notice Subtract the amount of tokens form the total escrow balance not included in staking /// @param amount to subtract function subtractTotalEscrowBalanceNotIncludedInStaking(uint amount) external { require(msg.sender == address(iStakingThales), "Can only be called from staking contract"); totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.sub(amount); } /// @notice Update the current vesting period function updateCurrentPeriod() external returns (bool) { if (!testMode) { require(msg.sender == address(iStakingThales), "Can only be called from staking contract"); } currentVestingPeriod = currentVestingPeriod.add(1); return true; } /// @notice Set address of Staking Thales contract /// @param StakingThalesContract address of Staking Thales contract function setStakingThalesContract(address StakingThalesContract) external onlyOwner { require(StakingThalesContract != address(0), "Invalid address set"); iStakingThales = IStakingThales(StakingThalesContract); emit StakingThalesContractChanged(StakingThalesContract); } /// @notice Enable the test mode function enableTestMode() external onlyOwner { testMode = true; } /// @notice Set address of Airdrop contract /// @param AirdropContract address of Airdrop contract function setAirdropContract(address AirdropContract) external onlyOwner { require(AirdropContract != address(0), "Invalid address set"); airdropContract = AirdropContract; emit AirdropContractChanged(AirdropContract); } /// @notice Set address of Thales staking rewards pool /// @param _thalesStakingRewardsPool address of Thales staking rewards pool function setThalesStakingRewardsPool(address _thalesStakingRewardsPool) public onlyOwner { require(_thalesStakingRewardsPool != address(0), "Invalid address"); ThalesStakingRewardsPool = IThalesStakingRewardsPool(_thalesStakingRewardsPool); emit ThalesStakingRewardsPoolChanged(_thalesStakingRewardsPool); } /// @notice Fix the vesting entry for the account /// @param account to fix the vesting entry for function fixEscrowEntry(address account) external onlyOwner { vestingEntries[account][currentVestingPeriod.mod(NUM_PERIODS)].vesting_period = currentVestingPeriod.add( NUM_PERIODS ); } /// @notice Merge account to transfer all escrow amounts to another account /// @param srcAccount to merge /// @param destAccount to merge into function mergeAccount(address srcAccount, address destAccount) external { require(msg.sender == address(iStakingThales), "Can only be called from staking contract"); if (iStakingThales.stakedBalanceOf(srcAccount) == 0 && iStakingThales.stakedBalanceOf(destAccount) > 0) { if (totalAccountEscrowedAmount[srcAccount] > 0) { totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.sub( totalAccountEscrowedAmount[srcAccount] ); } } if (iStakingThales.stakedBalanceOf(destAccount) == 0 && iStakingThales.stakedBalanceOf(srcAccount) > 0) { if (totalAccountEscrowedAmount[destAccount] > 0) { totalEscrowBalanceNotIncludedInStaking = totalEscrowBalanceNotIncludedInStaking.sub( totalAccountEscrowedAmount[destAccount] ); } } totalAccountEscrowedAmount[destAccount] = totalAccountEscrowedAmount[destAccount].add( totalAccountEscrowedAmount[srcAccount] ); lastPeriodAddedReward[destAccount] = currentVestingPeriod; uint vestingEntriesIndex; uint vestingEntriesPeriod; for (uint i = 1; i <= NUM_PERIODS; i++) { vestingEntriesIndex = currentVestingPeriod.add(i).mod(NUM_PERIODS); vestingEntriesPeriod = currentVestingPeriod.add(i); if (vestingEntriesPeriod != vestingEntries[destAccount][vestingEntriesIndex].vesting_period) { vestingEntries[destAccount][vestingEntriesIndex].amount = 0; vestingEntries[destAccount][vestingEntriesIndex].vesting_period = vestingEntriesPeriod; } if (vestingEntriesPeriod == vestingEntries[srcAccount][vestingEntriesIndex].vesting_period) { vestingEntries[destAccount][vestingEntriesIndex].amount = vestingEntries[destAccount][vestingEntriesIndex] .amount .add(vestingEntries[srcAccount][vestingEntriesIndex].amount); } } delete totalAccountEscrowedAmount[srcAccount]; delete lastPeriodAddedReward[srcAccount]; delete vestingEntries[srcAccount]; } /* ========== INTERNAL FUNCTIONS ========== */ function _getVestingNotAvailable(address account) internal view returns (uint) { uint vesting_not_available = 0; for (uint i = 0; i < NUM_PERIODS; i++) { if (vestingEntries[account][i].vesting_period > currentVestingPeriod) { vesting_not_available = vesting_not_available.add(vestingEntries[account][i].amount); } } return vesting_not_available; } /* ========== EVENTS ========== */ event AddedToEscrow(address acount, uint amount); event Vested(address account, uint amount); event StakingThalesContractChanged(address newAddress); event AirdropContractChanged(address newAddress); event ThalesStakingRewardsPoolChanged(address thalesStakingRewardsPool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; // Clone of syntetix contract without constructor contract ProxyOwned { address public owner; address public nominatedOwner; bool private _initialized; bool private _transferredAtInit; function setOwner(address _owner) public { require(_owner != address(0), "Owner address cannot be 0"); require(!_initialized, "Already initialized, use nominateNewOwner"); _initialized = true; owner = _owner; emit OwnerChanged(address(0), _owner); } function nominateNewOwner(address _owner) external onlyOwner { nominatedOwner = _owner; emit OwnerNominated(_owner); } function acceptOwnership() external { require(msg.sender == nominatedOwner, "You must be nominated before you can accept ownership"); emit OwnerChanged(owner, nominatedOwner); owner = nominatedOwner; nominatedOwner = address(0); } function transferOwnershipAtInit(address proxyAddress) external onlyOwner { require(proxyAddress != address(0), "Invalid address"); require(!_transferredAtInit, "Already transferred"); owner = proxyAddress; _transferredAtInit = true; emit OwnerChanged(owner, proxyAddress); } modifier onlyOwner { _onlyOwner(); _; } function _onlyOwner() private view { require(msg.sender == owner, "Only the contract owner may perform this action"); } event OwnerNominated(address newOwner); event OwnerChanged(address oldOwner, address newOwner); }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; // Inheritance import "./ProxyOwned.sol"; // Clone of syntetix contract without constructor contract ProxyPausable is ProxyOwned { uint public lastPauseTime; bool public paused; /** * @notice Change the paused state of the contract * @dev Only the contract owner may call this. */ function setPaused(bool _paused) external onlyOwner { // Ensure we're actually changing the state before we do anything if (_paused == paused) { return; } // Set our paused state. paused = _paused; // If applicable, set the last pause time. if (paused) { lastPauseTime = block.timestamp; } // Let everyone know that our pause state has changed. emit PauseChanged(paused); } event PauseChanged(bool isPaused); modifier notPaused { require(!paused, "This action cannot be performed while the contract is paused"); _; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.4.24 <0.7.0; /** * @title Initializable * * @dev Helper contract to support initializer functions. To use it, replace * the constructor with a function that has the `initializer` modifier. * WARNING: Unlike constructors, initializer functions must be manually * invoked. This applies both to deploying an Initializable contract, as well * as extending an Initializable contract via inheritance. * WARNING: When used with inheritance, manual care must be taken to not invoke * a parent initializer twice, or ensure that all initializers are idempotent, * because this is not dealt with automatically as with constructors. */ contract Initializable { /** * @dev Indicates that the contract has been initialized. */ bool private initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private initializing; /** * @dev Modifier to use in the initializer function of a contract. */ modifier initializer() { require(initializing || isConstructor() || !initialized, "Contract instance has already been initialized"); bool isTopLevelCall = !initializing; if (isTopLevelCall) { initializing = true; initialized = true; } _; if (isTopLevelCall) { initializing = false; } } /// @dev Returns true if and only if the function is running in the constructor function isConstructor() private view returns (bool) { // extcodesize checks the size of the code stored in an address, and // address returns the current address. Since the code is still not // deployed when running a constructor, any checks on its code size will // yield zero, making it an effective way to detect if a contract is // under construction or not. address self = address(this); uint256 cs; assembly { cs := extcodesize(self) } return cs == 0; } // Reserved storage space to allow for layout changes in the future. uint256[50] private ______gap; }
pragma solidity ^0.5.0; import "./IERC20.sol"; import "../../math/SafeMath.sol"; import "../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the `nonReentrant` modifier * available, which can be aplied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. */ contract ProxyReentrancyGuard { /// @dev counter to allow mutex lock with only one SSTORE operation uint256 private _guardCounter; bool private _initialized; function initNonReentrant() public { require(!_initialized, "Already initialized"); _initialized = true; _guardCounter = 1; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { _guardCounter += 1; uint256 localCounter = _guardCounter; _; require(localCounter == _guardCounter, "ReentrancyGuard: reentrant call"); } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IEscrowThales { /* ========== VIEWS / VARIABLES ========== */ function getStakerPeriod(address account, uint index) external view returns (uint); function getStakerAmounts(address account, uint index) external view returns (uint); function totalAccountEscrowedAmount(address account) external view returns (uint); function getStakedEscrowedBalanceForRewards(address account) external view returns (uint); function totalEscrowedRewards() external view returns (uint); function totalEscrowBalanceNotIncludedInStaking() external view returns (uint); function currentVestingPeriod() external view returns (uint); function updateCurrentPeriod() external returns (bool); function claimable(address account) external view returns (uint); function addToEscrow(address account, uint amount) external; function vest(uint amount) external returns (bool); function addTotalEscrowBalanceNotIncludedInStaking(uint amount) external; function subtractTotalEscrowBalanceNotIncludedInStaking(uint amount) external; function mergeAccount(address srcAccount, address destAccount) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IStakingThales { function updateVolume(address account, uint amount) external; /* ========== VIEWS / VARIABLES ========== */ function totalStakedAmount() external view returns (uint); function stakedBalanceOf(address account) external view returns (uint); function currentPeriodRewards() external view returns (uint); function currentPeriodFees() external view returns (uint); function getLastPeriodOfClaimedRewards(address account) external view returns (uint); function getRewardsAvailable(address account) external view returns (uint); function getRewardFeesAvailable(address account) external view returns (uint); function getAlreadyClaimedRewards(address account) external view returns (uint); function getContractRewardFunds() external view returns (uint); function getContractFeeFunds() external view returns (uint); function getAMMVolume(address account) external view returns (uint); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface ISNXRewards { /* ========== VIEWS / VARIABLES ========== */ function collateralisationRatioAndAnyRatesInvalid(address account) external view returns (uint, bool); function debtBalanceOf(address _issuer, bytes32 currencyKey) external view returns (uint); function issuanceRatio() external view returns (uint); function setCRatio(address account, uint _c_ratio) external; function setIssuanceRatio(uint _issuanceRation) external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; pragma experimental ABIEncoderV2; import "../interfaces/IPassportPosition.sol"; interface IThalesRoyale { /* ========== VIEWS / VARIABLES ========== */ function getBuyInAmount() external view returns (uint); function season() external view returns (uint); function tokenSeason(uint tokenId) external view returns (uint); function seasonFinished(uint _season) external view returns (bool); function roundInASeason(uint _round) external view returns (uint); function roundResultPerSeason(uint _season, uint round) external view returns (uint); function isTokenAliveInASpecificSeason(uint tokenId, uint _season) external view returns (bool); function hasParticipatedInCurrentOrLastRoyale(address _player) external view returns (bool); function getTokenPositions(uint tokenId) external view returns (IPassportPosition.Position[] memory); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IPriceFeed { // Structs struct RateAndUpdatedTime { uint216 rate; uint40 time; } // Mutative functions function addAggregator(bytes32 currencyKey, address aggregatorAddress) external; function removeAggregator(bytes32 currencyKey) external; // Views function rateForCurrency(bytes32 currencyKey) external view returns (uint); function rateAndUpdatedTime(bytes32 currencyKey) external view returns (uint rate, uint time); function getRates() external view returns (uint[] memory); function getCurrencies() external view returns (bytes32[] memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; interface IThalesStakingRewardsPool { function addToEscrow(address account, uint amount) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.5.16; interface IAddressResolver { /* ========== VIEWS / VARIABLES ========== */ function getAddress(bytes32 name) external view returns (address); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface ISportsAMMLiquidityPool { /* ========== VIEWS / VARIABLES ========== */ function isUserLPing(address user) external view returns (bool isUserInLP); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "./IPriceFeed.sol"; interface IThalesAMM { enum Position { Up, Down } function manager() external view returns (address); function availableToBuyFromAMM(address market, Position position) external view returns (uint); function impliedVolatilityPerAsset(bytes32 oracleKey) external view returns (uint); function buyFromAmmQuote( address market, Position position, uint amount ) external view returns (uint); function buyFromAMM( address market, Position position, uint amount, uint expectedPayout, uint additionalSlippage ) external returns (uint); function availableToSellToAMM(address market, Position position) external view returns (uint); function sellToAmmQuote( address market, Position position, uint amount ) external view returns (uint); function sellToAMM( address market, Position position, uint amount, uint expectedPayout, uint additionalSlippage ) external returns (uint); function isMarketInAMMTrading(address market) external view returns (bool); function price(address market, Position position) external view returns (uint); function buyPriceImpact( address market, Position position, uint amount ) external view returns (int); function priceFeed() external view returns (IPriceFeed); }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "../interfaces/IPositionalMarket.sol"; interface IPositionalMarketManager { /* ========== VIEWS / VARIABLES ========== */ function durations() external view returns (uint expiryDuration, uint maxTimeToMaturity); function capitalRequirement() external view returns (uint); function marketCreationEnabled() external view returns (bool); function onlyAMMMintingAndBurning() external view returns (bool); function transformCollateral(uint value) external view returns (uint); function reverseTransformCollateral(uint value) external view returns (uint); function totalDeposited() external view returns (uint); function numActiveMarkets() external view returns (uint); function activeMarkets(uint index, uint pageSize) external view returns (address[] memory); function numMaturedMarkets() external view returns (uint); function maturedMarkets(uint index, uint pageSize) external view returns (address[] memory); function isActiveMarket(address candidate) external view returns (bool); function isKnownMarket(address candidate) external view returns (bool); function getThalesAMM() external view returns (address); /* ========== MUTATIVE FUNCTIONS ========== */ function createMarket( bytes32 oracleKey, uint strikePrice, uint maturity, uint initialMint // initial sUSD to mint options for, ) external returns (IPositionalMarket); function resolveMarket(address market) external; function expireMarkets(address[] calldata market) external; function transferSusdTo( address sender, address receiver, uint amount ) external; }
pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see `ERC20Detailed`. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through `transferFrom`. This is * zero by default. * * This value changes when `approve` or `transferFrom` are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * > Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an `Approval` event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a `Transfer` event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to `approve`. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
pragma solidity ^0.5.0; /** * @dev Collection of functions related to the address type, */ library Address { /** * @dev Returns true if `account` is a contract. * * This test is non-exhaustive, and there may be false-negatives: during the * execution of a contract's constructor, its address will be reported as * not containing a contract. * * > It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. */ function isContract(address account) internal view returns (bool) { // This method relies in extcodesize, which returns 0 for contracts in // construction, since the code is only stored at the end of the // constructor execution. uint256 size; // solhint-disable-next-line no-inline-assembly assembly { size := extcodesize(account) } return size > 0; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; interface IPassportPosition { struct Position { uint round; uint position; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "../interfaces/IPositionalMarketManager.sol"; import "../interfaces/IPosition.sol"; import "../interfaces/IPriceFeed.sol"; interface IPositionalMarket { /* ========== TYPES ========== */ enum Phase { Trading, Maturity, Expiry } enum Side { Up, Down } /* ========== VIEWS / VARIABLES ========== */ function getOptions() external view returns (IPosition up, IPosition down); function times() external view returns (uint maturity, uint destructino); function getOracleDetails() external view returns ( bytes32 key, uint strikePrice, uint finalPrice ); function fees() external view returns (uint poolFee, uint creatorFee); function deposited() external view returns (uint); function creator() external view returns (address); function resolved() external view returns (bool); function phase() external view returns (Phase); function oraclePrice() external view returns (uint); function oraclePriceAndTimestamp() external view returns (uint price, uint updatedAt); function canResolve() external view returns (bool); function result() external view returns (Side); function balancesOf(address account) external view returns (uint up, uint down); function totalSupplies() external view returns (uint up, uint down); function getMaximumBurnable(address account) external view returns (uint amount); /* ========== MUTATIVE FUNCTIONS ========== */ function mint(uint value) external; function exerciseOptions() external returns (uint); function burnOptions(uint amount) external; function burnOptionsMaximum() external; }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "./IPositionalMarket.sol"; interface IPosition { /* ========== VIEWS / VARIABLES ========== */ function getBalanceOf(address account) external view returns (uint); function getTotalSupply() external view returns (uint); function exerciseWithAmount(address claimant, uint amount) external; }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_escrowThales","type":"address"}],"name":"EscrowThalesChnaged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isPaused","type":"bool"}],"name":"PauseChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_stakingThales","type":"address"}],"name":"StakingThalesChnaged","type":"event"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"escrowThales","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getStakingData","outputs":[{"components":[{"internalType":"bool","name":"paused","type":"bool"},{"internalType":"uint256","name":"periodsOfStaking","type":"uint256"},{"internalType":"uint256","name":"lastPeriodTimeStamp","type":"uint256"},{"internalType":"uint256","name":"durationPeriod","type":"uint256"},{"internalType":"uint256","name":"unstakeDurationPeriod","type":"uint256"},{"internalType":"uint256","name":"baseRewardsPool","type":"uint256"},{"internalType":"uint256","name":"bonusRewardsPool","type":"uint256"},{"internalType":"uint256","name":"totalStakedAmount","type":"uint256"},{"internalType":"uint256","name":"maxSNXRewardsPercentage","type":"uint256"},{"internalType":"uint256","name":"maxAMMVolumeRewardsPercentage","type":"uint256"},{"internalType":"uint256","name":"maxThalesRoyaleRewardsPercentage","type":"uint256"},{"internalType":"uint256","name":"SNXVolumeRewardsMultiplier","type":"uint256"},{"internalType":"uint256","name":"AMMVolumeRewardsMultiplier","type":"uint256"},{"internalType":"bool","name":"canClosePeriod","type":"bool"},{"internalType":"bool","name":"mergeAccountEnabled","type":"bool"},{"internalType":"uint256","name":"totalEscrowBalanceNotIncludedInStaking","type":"uint256"},{"internalType":"uint256","name":"totalEscrowedRewards","type":"uint256"}],"internalType":"struct StakingData.StakingData","name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserStakingData","outputs":[{"components":[{"internalType":"uint256","name":"thalesStaked","type":"uint256"},{"internalType":"bool","name":"unstaking","type":"bool"},{"internalType":"uint256","name":"lastUnstakeTime","type":"uint256"},{"internalType":"uint256","name":"unstakingAmount","type":"uint256"},{"internalType":"address","name":"delegatedVolume","type":"address"},{"internalType":"uint256","name":"rewards","type":"uint256"},{"internalType":"uint256","name":"baseRewards","type":"uint256"},{"internalType":"uint256","name":"totalBonus","type":"uint256"},{"internalType":"uint256","name":"snxBonus","type":"uint256"},{"internalType":"uint256","name":"ammBonus","type":"uint256"},{"internalType":"uint256","name":"snxStaked","type":"uint256"},{"internalType":"uint256","name":"ammVolume","type":"uint256"},{"internalType":"uint256","name":"thalesAmmVolume","type":"uint256"},{"internalType":"uint256","name":"rangedAmmVolume","type":"uint256"},{"internalType":"uint256","name":"sportsAmmVolume","type":"uint256"},{"internalType":"uint256","name":"lastPeriodOfClaimedRewards","type":"uint256"},{"internalType":"uint256","name":"escrowedBalance","type":"uint256"},{"internalType":"uint256","name":"claimable","type":"uint256"}],"internalType":"struct StakingData.UserStakingData","name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserVestingData","outputs":[{"components":[{"internalType":"uint256","name":"numberOfPeriods","type":"uint256"},{"internalType":"uint256","name":"currentVestingPeriod","type":"uint256"},{"internalType":"uint256","name":"lastPeriodTimeStamp","type":"uint256"},{"internalType":"uint256","name":"claimable","type":"uint256"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"vesting_period","type":"uint256"}],"internalType":"struct EscrowThales.VestingEntry[]","name":"vestingEntries","type":"tuple[]"}],"internalType":"struct StakingData.UserVestingData","name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"initialize","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"lastPauseTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_escrowThales","type":"address"}],"name":"setEscrowThales","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_stakingThales","type":"address"}],"name":"setStakingThales","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"stakingThales","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"proxyAddress","type":"address"}],"name":"transferOwnershipAtInit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b506125e9806100206000396000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c806376e35d89116100a2578063909ece0511610071578063909ece05146101fe57806391b4ded914610211578063c3b83f5f14610226578063c4d66de814610239578063fd8a8cc61461024c5761010b565b806376e35d89146101c657806379ba5097146101db5780637f852582146101e35780638da5cb5b146101f65761010b565b806338d22110116100de57806338d2211014610174578063436ec6ef1461018957806353a47bb7146101a95780635c975abb146101b15761010b565b806304c475801461011057806313af4035146101395780631627540c1461014e57806316c38b3c14610161575b600080fd5b61012361011e366004611d93565b610254565b604051610130919061251e565b60405180910390f35b61014c610147366004611d93565b6105f8565b005b61014c61015c366004611d93565b6106bf565b61014c61016f366004611dd7565b610712565b61017c610787565b6040516101309190612429565b61019c610197366004611d93565b610796565b604051610130919061250f565b61017c6110dc565b6101b96110eb565b6040516101309190612482565b6101ce6110f4565b6040516101309190612500565b61014c6118fe565b61014c6101f1366004611d93565b61199a565b61017c6119f2565b61014c61020c366004611d93565b611a01565b610219611a54565b604051610130919061252f565b61014c610234366004611d93565b611a5a565b61014c610247366004611d93565b611b1a565b61017c611ba7565b61025c611bed565b60365460375460408051630faab8cf60e01b815290516101009093046001600160a01b03908116939216916000918391630faab8cf91600480820192602092909190829003018186803b1580156102b257600080fd5b505afa1580156102c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506102ea9190810190611e13565b905060608160405190808252806020026020018201604052801561032857816020015b610315611c1c565b81526020019060019003908161030d5790505b50905060005b828110156103fc57600080856001600160a01b031663ab6108508a856040518363ffffffff1660e01b8152600401610367929190612467565b604080518083038186803b15801561037e57600080fd5b505afa158015610392573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506103b69190810190611e31565b91509150818484815181106103c757fe5b60200260200101516000018181525050808484815181106103e457fe5b6020908102919091018101510152505060010161032e565b506040518060a00160405280846001600160a01b0316630faab8cf6040518163ffffffff1660e01b815260040160206040518083038186803b15801561044157600080fd5b505afa158015610455573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506104799190810190611e13565b8152602001846001600160a01b0316635d1385056040518163ffffffff1660e01b815260040160206040518083038186803b1580156104b757600080fd5b505afa1580156104cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506104ef9190810190611e13565b8152602001856001600160a01b031663200743546040518163ffffffff1660e01b815260040160206040518083038186803b15801561052d57600080fd5b505afa158015610541573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506105659190810190611e13565b8152602001846001600160a01b031663402914f5896040518263ffffffff1660e01b81526004016105969190612429565b60206040518083038186803b1580156105ae57600080fd5b505afa1580156105c2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506105e69190810190611e13565b81526020019190915295945050505050565b6001600160a01b0381166106275760405162461bcd60e51b815260040161061e906124f0565b60405180910390fd5b603454600160a01b900460ff16156106515760405162461bcd60e51b815260040161061e906124b0565b6034805460ff60a01b1916600160a01b179055603380546001600160a01b0383166001600160a01b03199091161790556040517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c906106b4906000908490612437565b60405180910390a150565b6106c7611bbb565b603480546001600160a01b0319166001600160a01b0383161790556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce22906106b4908390612429565b61071a611bbb565b60365460ff161515811515141561073057610784565b6036805460ff1916821515179081905560ff161561074d57426035555b6036546040517f8fb6c181ee25a520cf3dd6565006ef91229fcfe5a989566c2a3b8c115570cec5916106b49160ff90911690612482565b50565b6037546001600160a01b031681565b61079e611c36565b60365460375460408051610240810191829052631676539160e01b9091526101009092046001600160a01b0390811692911690808363167653916107e6886102448501612429565b60206040518083038186803b1580156107fe57600080fd5b505afa158015610812573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108369190810190611e13565b8152602001836001600160a01b031663cb8d751a876040518263ffffffff1660e01b81526004016108679190612429565b60206040518083038186803b15801561087f57600080fd5b505afa158015610893573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108b79190810190611df5565b15158152602001836001600160a01b031663331e03a8876040518263ffffffff1660e01b81526004016108ea9190612429565b60206040518083038186803b15801561090257600080fd5b505afa158015610916573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061093a9190810190611e13565b8152602001836001600160a01b0316632d287886876040518263ffffffff1660e01b815260040161096b9190612429565b60206040518083038186803b15801561098357600080fd5b505afa158015610997573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506109bb9190810190611e13565b8152602001836001600160a01b031663bd450062876040518263ffffffff1660e01b81526004016109ec9190612429565b60206040518083038186803b158015610a0457600080fd5b505afa158015610a18573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610a3c9190810190611db9565b6001600160a01b03168152602001836001600160a01b0316637a685677876040518263ffffffff1660e01b8152600401610a769190612429565b60206040518083038186803b158015610a8e57600080fd5b505afa158015610aa2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610ac69190810190611e13565b8152602001836001600160a01b0316639a109bc2876040518263ffffffff1660e01b8152600401610af79190612429565b60206040518083038186803b158015610b0f57600080fd5b505afa158015610b23573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610b479190810190611e13565b8152602001836001600160a01b03166336468b5a876040518263ffffffff1660e01b8152600401610b789190612429565b60206040518083038186803b158015610b9057600080fd5b505afa158015610ba4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610bc89190810190611e13565b8152602001836001600160a01b0316639e6b892b876040518263ffffffff1660e01b8152600401610bf99190612429565b60206040518083038186803b158015610c1157600080fd5b505afa158015610c25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610c499190810190611e13565b8152602001836001600160a01b031663c5986949876040518263ffffffff1660e01b8152600401610c7a9190612429565b60206040518083038186803b158015610c9257600080fd5b505afa158015610ca6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610cca9190810190611e13565b8152602001836001600160a01b031663b9cce86a876040518263ffffffff1660e01b8152600401610cfb9190612429565b60206040518083038186803b158015610d1357600080fd5b505afa158015610d27573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610d4b9190810190611e13565b8152602001836001600160a01b0316639a09edab876040518263ffffffff1660e01b8152600401610d7c9190612429565b60206040518083038186803b158015610d9457600080fd5b505afa158015610da8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610dcc9190810190611e13565b8152602001836001600160a01b031663ac8e71ea876040518263ffffffff1660e01b8152600401610dfd9190612429565b60206040518083038186803b158015610e1557600080fd5b505afa158015610e29573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610e4d9190810190611e13565b8152602001836001600160a01b03166360962e06876040518263ffffffff1660e01b8152600401610e7e9190612429565b60206040518083038186803b158015610e9657600080fd5b505afa158015610eaa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610ece9190810190611e13565b8152602001836001600160a01b031663a0ad2229876040518263ffffffff1660e01b8152600401610eff9190612429565b60206040518083038186803b158015610f1757600080fd5b505afa158015610f2b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610f4f9190810190611e13565b8152602001836001600160a01b0316634c4e75df876040518263ffffffff1660e01b8152600401610f809190612429565b60206040518083038186803b158015610f9857600080fd5b505afa158015610fac573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610fd09190810190611e13565b8152602001826001600160a01b031663698f15ca876040518263ffffffff1660e01b81526004016110019190612429565b60206040518083038186803b15801561101957600080fd5b505afa15801561102d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506110519190810190611e13565b8152602001826001600160a01b031663402914f5876040518263ffffffff1660e01b81526004016110829190612429565b60206040518083038186803b15801561109a57600080fd5b505afa1580156110ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506110d29190810190611e13565b9052949350505050565b6034546001600160a01b031681565b60365460ff1681565b6110fc611ccc565b603654603754604080516102208101808352635c975abb60e01b905290516101009093046001600160a01b039081169392169181908490635c975abb9061022480850191602091818703018186803b15801561115757600080fd5b505afa15801561116b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061118f9190810190611df5565b15158152602001836001600160a01b0316637c17f6fc6040518163ffffffff1660e01b815260040160206040518083038186803b1580156111cf57600080fd5b505afa1580156111e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506112079190810190611e13565b8152602001836001600160a01b031663200743546040518163ffffffff1660e01b815260040160206040518083038186803b15801561124557600080fd5b505afa158015611259573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061127d9190810190611e13565b8152602001836001600160a01b03166362139e0e6040518163ffffffff1660e01b815260040160206040518083038186803b1580156112bb57600080fd5b505afa1580156112cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506112f39190810190611e13565b8152602001836001600160a01b03166393eb2e666040518163ffffffff1660e01b815260040160206040518083038186803b15801561133157600080fd5b505afa158015611345573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113699190810190611e13565b8152602001836001600160a01b03166315da50646040518163ffffffff1660e01b815260040160206040518083038186803b1580156113a757600080fd5b505afa1580156113bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506113df9190810190611e13565b8152602001836001600160a01b0316634ed25b436040518163ffffffff1660e01b815260040160206040518083038186803b15801561141d57600080fd5b505afa158015611431573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506114559190810190611e13565b8152602001836001600160a01b031663567e98f96040518163ffffffff1660e01b815260040160206040518083038186803b15801561149357600080fd5b505afa1580156114a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506114cb9190810190611e13565b8152602001836001600160a01b031663cf26dbbc6040518163ffffffff1660e01b815260040160206040518083038186803b15801561150957600080fd5b505afa15801561151d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506115419190810190611e13565b8152602001836001600160a01b031663ebaf5b3c6040518163ffffffff1660e01b815260040160206040518083038186803b15801561157f57600080fd5b505afa158015611593573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506115b79190810190611e13565b8152602001836001600160a01b0316632a1a1e486040518163ffffffff1660e01b815260040160206040518083038186803b1580156115f557600080fd5b505afa158015611609573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061162d9190810190611e13565b8152602001836001600160a01b031663faa27d516040518163ffffffff1660e01b815260040160206040518083038186803b15801561166b57600080fd5b505afa15801561167f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506116a39190810190611e13565b8152602001836001600160a01b031663d78fc2906040518163ffffffff1660e01b815260040160206040518083038186803b1580156116e157600080fd5b505afa1580156116f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506117199190810190611e13565b8152602001836001600160a01b031663afac7fb16040518163ffffffff1660e01b815260040160206040518083038186803b15801561175757600080fd5b505afa15801561176b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061178f9190810190611df5565b15158152602001836001600160a01b031663c731a3d16040518163ffffffff1660e01b815260040160206040518083038186803b1580156117cf57600080fd5b505afa1580156117e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506118079190810190611df5565b15158152602001826001600160a01b0316638fa6d02e6040518163ffffffff1660e01b815260040160206040518083038186803b15801561184757600080fd5b505afa15801561185b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061187f9190810190611e13565b8152602001826001600160a01b031663b9d1c70b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156118bd57600080fd5b505afa1580156118d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506118f59190810190611e13565b90529250505090565b6034546001600160a01b031633146119285760405162461bcd60e51b815260040161061e90612490565b6033546034546040517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c9261196b926001600160a01b0391821692911690612459565b60405180910390a160348054603380546001600160a01b03199081166001600160a01b03841617909155169055565b6119a2611bbb565b60368054610100600160a81b0319166101006001600160a01b038416021790556040517f98744f498f8e1eb18db2b0234645b098f1b79154bef95dc68f2ebc4245e9f49d906106b4908390612429565b6033546001600160a01b031681565b611a09611bbb565b603780546001600160a01b0319166001600160a01b0383161790556040517f3eb2b20323f4f588be40f88adb8fb16a1beff75f815b08eabd9ccaebd4c38132906106b4908390612429565b60355481565b611a62611bbb565b6001600160a01b038116611a885760405162461bcd60e51b815260040161061e906124a0565b603454600160a81b900460ff1615611ab25760405162461bcd60e51b815260040161061e906124d0565b603380546001600160a01b038084166001600160a01b031990921691909117918290556034805460ff60a81b1916600160a81b1790556040517fb532073b38c83145e3e5135377a08bf9aab55bc0fd7c1179cd4fb995d2a5159c926106b49216908490612459565b600054610100900460ff1680611b335750611b33611be7565b80611b41575060005460ff16155b611b5d5760405162461bcd60e51b815260040161061e906124e0565b600054610100900460ff16158015611b88576000805460ff1961ff0019909116610100171660011790555b611b91826105f8565b8015611ba3576000805461ff00191690555b5050565b60365461010090046001600160a01b031681565b6033546001600160a01b03163314611be55760405162461bcd60e51b815260040161061e906124c0565b565b303b1590565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001606081525090565b604051806040016040528060008152602001600081525090565b60405180610240016040528060008152602001600015158152602001600081526020016000815260200160006001600160a01b03168152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b60405180610220016040528060001515815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160001515815260200160001515815260200160008152602001600081525090565b8035611d6181612580565b92915050565b8051611d6181612580565b8035611d6181612594565b8051611d6181612594565b8051611d618161259d565b600060208284031215611da557600080fd5b6000611db18484611d56565b949350505050565b600060208284031215611dcb57600080fd5b6000611db18484611d67565b600060208284031215611de957600080fd5b6000611db18484611d72565b600060208284031215611e0757600080fd5b6000611db18484611d7d565b600060208284031215611e2557600080fd5b6000611db18484611d88565b60008060408385031215611e4457600080fd5b6000611e508585611d88565b9250506020611e6185828601611d88565b9150509250929050565b6000611e778383612400565b505060400190565b611e888161256f565b82525050565b611e8881612550565b6000611ea282612543565b611eac8185612547565b9350611eb78361253d565b8060005b83811015611ee5578151611ecf8882611e6b565b9750611eda8361253d565b925050600101611ebb565b509495945050505050565b611e888161255b565b6000611f06603583612547565b7f596f75206d757374206265206e6f6d696e61746564206265666f726520796f7581527402063616e20616363657074206f776e65727368697605c1b602082015260400192915050565b6000611f5d600f83612547565b6e496e76616c6964206164647265737360881b815260200192915050565b6000611f88602983612547565b7f416c726561647920696e697469616c697a65642c20757365206e6f6d696e617481526832a732bba7bbb732b960b91b602082015260400192915050565b6000611fd3602f83612547565b7f4f6e6c792074686520636f6e7472616374206f776e6572206d6179207065726681526e37b936903a3434b99030b1ba34b7b760891b602082015260400192915050565b6000612024601383612547565b72105b1c9958591e481d1c985b9cd9995c9c9959606a1b815260200192915050565b6000612053602e83612547565b7f436f6e747261637420696e7374616e63652068617320616c726561647920626581526d195b881a5b9a5d1a585b1a5e995960921b602082015260400192915050565b60006120a3601983612547565b7f4f776e657220616464726573732063616e6e6f74206265203000000000000000815260200192915050565b80516102208301906120e18482611ef0565b5060208201516120f46020850182612420565b5060408201516121076040850182612420565b50606082015161211a6060850182612420565b50608082015161212d6080850182612420565b5060a082015161214060a0850182612420565b5060c082015161215360c0850182612420565b5060e082015161216660e0850182612420565b5061010082015161217b610100850182612420565b50610120820151612190610120850182612420565b506101408201516121a5610140850182612420565b506101608201516121ba610160850182612420565b506101808201516121cf610180850182612420565b506101a08201516121e46101a0850182611ef0565b506101c08201516121f96101c0850182611ef0565b506101e082015161220e6101e0850182612420565b50610200820151612223610200850182612420565b50505050565b805161024083019061223b8482612420565b50602082015161224e6020850182611ef0565b5060408201516122616040850182612420565b5060608201516122746060850182612420565b5060808201516122876080850182611e8e565b5060a082015161229a60a0850182612420565b5060c08201516122ad60c0850182612420565b5060e08201516122c060e0850182612420565b506101008201516122d5610100850182612420565b506101208201516122ea610120850182612420565b506101408201516122ff610140850182612420565b50610160820151612314610160850182612420565b50610180820151612329610180850182612420565b506101a082015161233e6101a0850182612420565b506101c08201516123536101c0850182612420565b506101e08201516123686101e0850182612420565b5061020082015161237d610200850182612420565b50610220820151612223610220850182612420565b805160009060a08401906123a68582612420565b5060208301516123b96020860182612420565b5060408301516123cc6040860182612420565b5060608301516123df6060860182612420565b50608083015184820360808601526123f78282611e97565b95945050505050565b805160408301906124118482612420565b50602082015161222360208501825b611e888161256c565b60208101611d618284611e8e565b604081016124458285611e7f565b6124526020830184611e8e565b9392505050565b604081016124458285611e8e565b604081016124758285611e8e565b6124526020830184612420565b60208101611d618284611ef0565b60208082528101611d6181611ef9565b60208082528101611d6181611f50565b60208082528101611d6181611f7b565b60208082528101611d6181611fc6565b60208082528101611d6181612017565b60208082528101611d6181612046565b60208082528101611d6181612096565b6102208101611d6182846120cf565b6102408101611d618284612229565b602080825281016124528184612392565b60208101611d618284612420565b60200190565b5190565b90815260200190565b6000611d6182612560565b151590565b6001600160a01b031690565b90565b6000611d61826000611d6182612550565b61258981612550565b811461078457600080fd5b6125898161255b565b6125898161256c56fea365627a7a723158201241303410f49d9b4029c1d2c7f7db0557b08b19c38cdfd349658c6a04b20a1f6c6578706572696d656e74616cf564736f6c63430005100040