Source Code
Overview
S Balance
More Info
ContractCreator
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Latest 25 internal transactions (View All)
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
25563270 | 9 hrs ago | 0 S | ||||
24706790 | 5 days ago | 0 S | ||||
24706721 | 5 days ago | 0 S | ||||
24706660 | 5 days ago | 0 S | ||||
24706514 | 5 days ago | 0 S | ||||
24706000 | 5 days ago | 0 S | ||||
24705241 | 5 days ago | 0 S | ||||
24705076 | 5 days ago | 0 S | ||||
24704931 | 5 days ago | 0 S | ||||
24704716 | 5 days ago | 0 S | ||||
24704594 | 5 days ago | 0 S | ||||
24704357 | 5 days ago | 0 S | ||||
24703989 | 5 days ago | 0 S | ||||
24703665 | 5 days ago | 0 S | ||||
24539905 | 6 days ago | 0 S | ||||
24536771 | 6 days ago | 0 S | ||||
24535094 | 6 days ago | 0 S | ||||
24535018 | 6 days ago | 0 S | ||||
24534245 | 6 days ago | 0 S | ||||
24534163 | 6 days ago | 0 S | ||||
24534116 | 6 days ago | 0 S | ||||
24534053 | 6 days ago | 0 S | ||||
24533934 | 6 days ago | 0 S | ||||
24528968 | 6 days ago | 0 S | ||||
24378737 | 7 days ago | 0 S |
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x9a169085...23d154107 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
StakingPool
Compiler Version
v0.8.18+commit.87f61d96
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.18; import "../../abstract/Multicall.sol"; import "../../interfaces/IStakingPool.sol"; import "../../interfaces/IStakingNFT.sol"; import "../../interfaces/ITokenController.sol"; import "../../interfaces/ISAFURAMaster.sol"; import "../../interfaces/ISAFURAToken.sol"; import "../../interfaces/IStakingProducts.sol"; import "../../libraries/Math.sol"; import "../../libraries/UncheckedMath.sol"; import "../../libraries/SafeUintCast.sol"; import "./StakingTypesLib.sol"; // total stake = active stake + expired stake // total capacity = active stake * global capacity factor // total product capacity = total capacity * capacity reduction factor * product weight // total product capacity = allocated product capacity + available product capacity // on cover buys we allocate the available product capacity // on cover expiration we deallocate the capacity and it becomes available again contract StakingPool is IStakingPool, Multicall { using StakingTypesLib for TrancheAllocationGroup; using StakingTypesLib for TrancheGroupBucket; using SafeUintCast for uint; using UncheckedMath for uint; /* storage */ // slot 1 // supply of pool stake shares used by tranches uint128 internal stakeSharesSupply; // supply of pool rewards shares used by tranches uint128 internal rewardsSharesSupply; // slot 2 // accumulated rewarded nxm per reward share uint96 internal accNxmPerRewardsShare; // currently active staked nxm amount uint96 internal activeStake; uint32 internal firstActiveTrancheId; uint32 internal firstActiveBucketId; // slot 3 // timestamp when accNxmPerRewardsShare was last updated uint32 internal lastAccNxmUpdate; // current nxm reward per second for the entire pool // applies to active stake only and does not need update on deposits uint96 internal rewardPerSecond; uint40 internal poolId; uint24 internal lastAllocationId; bool public override isPrivatePool; bool public override isHalted; uint8 internal poolFee; uint8 internal maxPoolFee; // 32 bytes left in slot 3 // tranche id => tranche data mapping(uint => Tranche) internal tranches; // tranche id => expired tranche data mapping(uint => ExpiredTranche) internal expiredTranches; // reward bucket id => RewardBucket mapping(uint => uint) public rewardPerSecondCut; // product id => tranche group id => active allocations for a tranche group mapping(uint => mapping(uint => TrancheAllocationGroup)) public trancheAllocationGroups; // product id => bucket id => bucket tranche group id => tranche group's expiring cover amounts mapping(uint => mapping(uint => mapping(uint => TrancheGroupBucket))) public expiringCoverBuckets; // cover id => per tranche cover amounts (8 32-bit values, one per tranche, packed in a slot) // starts with the first active tranche at the time of cover buy mapping(uint => uint) public coverTrancheAllocations; // token id => tranche id => deposit data mapping(uint => mapping(uint => Deposit)) public deposits; /* immutables */ IStakingNFT public immutable stakingNFT; ISAFURAToken public immutable nxm; ITokenController public immutable tokenController; address public immutable coverContract; ISAFURAMaster public immutable masterContract; IStakingProducts public immutable stakingProducts; /* constants */ // 7 * 13 = 91 uint public constant BUCKET_DURATION = 28 days; uint public constant TRANCHE_DURATION = 91 days; uint public constant MAX_ACTIVE_TRANCHES = 8; // 7 whole quarters + 1 partial quarter uint public constant COVER_TRANCHE_GROUP_SIZE = 5; uint public constant BUCKET_TRANCHE_GROUP_SIZE = 8; uint public constant REWARD_BONUS_PER_TRANCHE_RATIO = 10_00; // 10.00% uint public constant REWARD_BONUS_PER_TRANCHE_DENOMINATOR = 100_00; uint public constant WEIGHT_DENOMINATOR = 100; uint public constant REWARDS_DENOMINATOR = 100_00; uint public constant POOL_FEE_DENOMINATOR = 100; // denominators for cover contract parameters uint public constant GLOBAL_CAPACITY_DENOMINATOR = 100_00; uint public constant CAPACITY_REDUCTION_DENOMINATOR = 100_00; // +2% for every 1%, ie +200% for 100% // 1 nxm = 1e18 uint internal constant ONE_NXM = 1 ether; // internally we store capacity using 2 decimals // 1 nxm of capacity is stored as 100 uint public constant ALLOCATION_UNITS_PER_NXM = 100; // given capacities have 2 decimals // smallest unit we can allocate is 1e18 / 100 = 1e16 = 0.01 NXM uint public constant NXM_PER_ALLOCATION_UNIT = ONE_NXM / ALLOCATION_UNITS_PER_NXM; modifier onlyCoverContract { if (msg.sender != coverContract) { revert OnlyCoverContract(); } _; } modifier onlyManager { if (msg.sender != manager()) { revert OnlyManager(); } _; } modifier whenNotPaused { if (masterContract.isPause()) { revert SystemPaused(); } _; } modifier whenNotHalted { if (isHalted) { revert PoolHalted(); } _; } constructor ( address _stakingNFT, address _token, address _coverContract, address _tokenController, address _master, address _stakingProducts ) { stakingNFT = IStakingNFT(_stakingNFT); nxm = ISAFURAToken(_token); coverContract = _coverContract; tokenController = ITokenController(_tokenController); masterContract = ISAFURAMaster(_master); stakingProducts = IStakingProducts(_stakingProducts); } function initialize( bool _isPrivatePool, uint _initialPoolFee, uint _maxPoolFee, uint _poolId, string calldata ipfsDescriptionHash ) external { if (msg.sender != address(stakingProducts)) { revert OnlyStakingProductsContract(); } if (_initialPoolFee > _maxPoolFee) { revert PoolFeeExceedsMax(); } if (_maxPoolFee >= 100) { revert MaxPoolFeeAbove100(); } isPrivatePool = _isPrivatePool; poolFee = uint8(_initialPoolFee); maxPoolFee = uint8(_maxPoolFee); poolId = _poolId.toUint40(); emit PoolDescriptionSet(ipfsDescriptionHash); } // updateUntilCurrentTimestamp forces rewards update until current timestamp not just until // bucket/tranche expiry timestamps. Must be true when changing shares or reward per second. function processExpirations(bool updateUntilCurrentTimestamp) public { uint _firstActiveBucketId = firstActiveBucketId; uint _firstActiveTrancheId = firstActiveTrancheId; uint currentBucketId = block.timestamp / BUCKET_DURATION; uint currentTrancheId = block.timestamp / TRANCHE_DURATION; // if the pool is new if (_firstActiveBucketId == 0) { _firstActiveBucketId = currentBucketId; _firstActiveTrancheId = currentTrancheId; } // if a force update was not requested if (!updateUntilCurrentTimestamp) { bool canExpireBuckets = _firstActiveBucketId < currentBucketId; bool canExpireTranches = _firstActiveTrancheId < currentTrancheId; // and if there's nothing to expire if (!canExpireBuckets && !canExpireTranches) { // we can exit return; } } // SLOAD uint _activeStake = activeStake; uint _rewardPerSecond = rewardPerSecond; uint _stakeSharesSupply = stakeSharesSupply; uint _rewardsSharesSupply = rewardsSharesSupply; uint _accNxmPerRewardsShare = accNxmPerRewardsShare; uint _lastAccNxmUpdate = lastAccNxmUpdate; // exit early if we already updated in the current block if (_lastAccNxmUpdate == block.timestamp) { return; } while (_firstActiveBucketId < currentBucketId || _firstActiveTrancheId < currentTrancheId) { // what expires first, the bucket or the tranche? bool bucketExpiresFirst; { uint nextBucketStart = (_firstActiveBucketId + 1) * BUCKET_DURATION; uint nextTrancheStart = (_firstActiveTrancheId + 1) * TRANCHE_DURATION; bucketExpiresFirst = nextBucketStart <= nextTrancheStart; } if (bucketExpiresFirst) { // expire a bucket // each bucket contains a reward reduction - we subtract it when the bucket *starts*! ++_firstActiveBucketId; uint bucketStartTime = _firstActiveBucketId * BUCKET_DURATION; uint elapsed = bucketStartTime - _lastAccNxmUpdate; uint newAccNxmPerRewardsShare = _rewardsSharesSupply != 0 ? elapsed * _rewardPerSecond * ONE_NXM / _rewardsSharesSupply : 0; _accNxmPerRewardsShare = _accNxmPerRewardsShare.uncheckedAdd(newAccNxmPerRewardsShare); _rewardPerSecond -= rewardPerSecondCut[_firstActiveBucketId]; _lastAccNxmUpdate = bucketStartTime; emit BucketExpired(_firstActiveBucketId - 1); continue; } // expire a tranche // each tranche contains shares - we expire them when the tranche *ends* // TODO: check if we have to expire the tranche { uint trancheEndTime = (_firstActiveTrancheId + 1) * TRANCHE_DURATION; uint elapsed = trancheEndTime - _lastAccNxmUpdate; uint newAccNxmPerRewardsShare = _rewardsSharesSupply != 0 ? elapsed * _rewardPerSecond * ONE_NXM / _rewardsSharesSupply : 0; _accNxmPerRewardsShare = _accNxmPerRewardsShare.uncheckedAdd(newAccNxmPerRewardsShare); _lastAccNxmUpdate = trancheEndTime; // SSTORE expiredTranches[_firstActiveTrancheId] = ExpiredTranche( _accNxmPerRewardsShare.toUint96(), // accNxmPerRewardShareAtExpiry _activeStake.toUint96(), // stakeAmountAtExpiry _stakeSharesSupply.toUint128() // stakeSharesSupplyAtExpiry ); // SLOAD and then SSTORE zero to get the gas refund Tranche memory expiringTranche = tranches[_firstActiveTrancheId]; delete tranches[_firstActiveTrancheId]; // the tranche is expired now so we decrease the stake and the shares supply uint expiredStake = _stakeSharesSupply != 0 ? (_activeStake * expiringTranche.stakeShares) / _stakeSharesSupply : 0; _activeStake -= expiredStake; _stakeSharesSupply -= expiringTranche.stakeShares; _rewardsSharesSupply -= expiringTranche.rewardsShares; emit TrancheExpired(_firstActiveTrancheId); // advance to the next tranche _firstActiveTrancheId++; } // end while } if (updateUntilCurrentTimestamp) { uint elapsed = block.timestamp - _lastAccNxmUpdate; uint newAccNxmPerRewardsShare = _rewardsSharesSupply != 0 ? elapsed * _rewardPerSecond * ONE_NXM / _rewardsSharesSupply : 0; _accNxmPerRewardsShare = _accNxmPerRewardsShare.uncheckedAdd(newAccNxmPerRewardsShare); _lastAccNxmUpdate = block.timestamp; } firstActiveTrancheId = _firstActiveTrancheId.toUint32(); firstActiveBucketId = _firstActiveBucketId.toUint32(); activeStake = _activeStake.toUint96(); rewardPerSecond = _rewardPerSecond.toUint96(); accNxmPerRewardsShare = _accNxmPerRewardsShare.toUint96(); lastAccNxmUpdate = _lastAccNxmUpdate.toUint32(); stakeSharesSupply = _stakeSharesSupply.toUint128(); rewardsSharesSupply = _rewardsSharesSupply.toUint128(); } function depositTo( uint amount, uint trancheId, uint requestTokenId, address destination ) public whenNotPaused whenNotHalted returns (uint tokenId) { if (isPrivatePool && msg.sender != manager()) { revert PrivatePool(); } if (block.timestamp <= nxm.isLockedForMV(msg.sender) && msg.sender != manager()) { revert NxmIsLockedForGovernanceVote(); } { uint _firstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint maxTranche = _firstActiveTrancheId + MAX_ACTIVE_TRANCHES - 1; if (amount == 0) { revert InsufficientDepositAmount(); } if (trancheId > maxTranche) { revert RequestedTrancheIsNotYetActive(); } if (trancheId < _firstActiveTrancheId) { revert RequestedTrancheIsExpired(); } // if the pool has no previous deposits if (firstActiveTrancheId == 0) { firstActiveTrancheId = _firstActiveTrancheId.toUint32(); firstActiveBucketId = (block.timestamp / BUCKET_DURATION).toUint32(); lastAccNxmUpdate = block.timestamp.toUint32(); } else { processExpirations(true); } } // storage reads uint _activeStake = activeStake; uint _stakeSharesSupply = stakeSharesSupply; uint _rewardsSharesSupply = rewardsSharesSupply; uint _accNxmPerRewardsShare = accNxmPerRewardsShare; uint totalAmount; // deposit to token id = 0 is not allowed // we treat it as a flag to create a new token if (requestTokenId == 0) { address to = destination == address(0) ? msg.sender : destination; tokenId = stakingNFT.mint(poolId, to); } else { // validate token id exists and belongs to this pool // stakingPoolOf() reverts for non-existent tokens if (stakingNFT.stakingPoolOf(requestTokenId) != poolId) { revert InvalidStakingPoolForToken(); } // validate only the token owner or an approved address can deposit if (!stakingNFT.isApprovedOrOwner(msg.sender, requestTokenId)) { revert NotTokenOwnerOrApproved(); } tokenId = requestTokenId; } uint newStakeShares = _stakeSharesSupply == 0 ? Math.sqrt(amount) : _stakeSharesSupply * amount / _activeStake; uint newRewardsShares; // update deposit and pending reward { // conditional read Deposit memory deposit = requestTokenId == 0 ? Deposit(0, 0, 0, 0) : deposits[tokenId][trancheId]; newRewardsShares = calculateNewRewardShares( deposit.stakeShares, // initialStakeShares newStakeShares, // newStakeShares trancheId, // initialTrancheId trancheId, // newTrancheId, the same as initialTrancheId in this case block.timestamp ); // if we're increasing an existing deposit if (deposit.rewardsShares != 0) { uint newEarningsPerShare = _accNxmPerRewardsShare.uncheckedSub(deposit.lastAccNxmPerRewardShare); deposit.pendingRewards += (newEarningsPerShare * deposit.rewardsShares / ONE_NXM).toUint96(); } deposit.stakeShares += newStakeShares.toUint128(); deposit.rewardsShares += newRewardsShares.toUint128(); deposit.lastAccNxmPerRewardShare = _accNxmPerRewardsShare.toUint96(); // store deposits[tokenId][trancheId] = deposit; } // update pool manager's reward shares { Deposit memory feeDeposit = deposits[0][trancheId]; { // create fee deposit reward shares uint newFeeRewardShares = newRewardsShares * poolFee / (POOL_FEE_DENOMINATOR - poolFee); newRewardsShares += newFeeRewardShares; // calculate rewards until now uint newRewardPerShare = _accNxmPerRewardsShare.uncheckedSub(feeDeposit.lastAccNxmPerRewardShare); feeDeposit.pendingRewards += (newRewardPerShare * feeDeposit.rewardsShares / ONE_NXM).toUint96(); feeDeposit.lastAccNxmPerRewardShare = _accNxmPerRewardsShare.toUint96(); feeDeposit.rewardsShares += newFeeRewardShares.toUint128(); } deposits[0][trancheId] = feeDeposit; } // update tranche { Tranche memory tranche = tranches[trancheId]; tranche.stakeShares += newStakeShares.toUint128(); tranche.rewardsShares += newRewardsShares.toUint128(); tranches[trancheId] = tranche; } totalAmount += amount; _activeStake += amount; _stakeSharesSupply += newStakeShares; _rewardsSharesSupply += newRewardsShares; // transfer nxm from the staker and update the pool deposit balance tokenController.depositStakedNXM(msg.sender, totalAmount, poolId); // update globals activeStake = _activeStake.toUint96(); stakeSharesSupply = _stakeSharesSupply.toUint128(); rewardsSharesSupply = _rewardsSharesSupply.toUint128(); emit StakeDeposited(msg.sender, amount, trancheId, tokenId); } function getTimeLeftOfTranche(uint trancheId, uint blockTimestamp) internal pure returns (uint) { uint endDate = (trancheId + 1) * TRANCHE_DURATION; return endDate > blockTimestamp ? endDate - blockTimestamp : 0; } /// Calculates the amount of new reward shares based on the initial and new stake shares /// /// @param initialStakeShares Amount of stake shares the deposit is already entitled to /// @param stakeSharesIncrease Amount of additional stake shares the deposit will be entitled to /// @param initialTrancheId The id of the initial tranche that defines the deposit period /// @param newTrancheId The new id of the tranche that will define the deposit period /// @param blockTimestamp The timestamp of the block when the new shares are recalculated function calculateNewRewardShares( uint initialStakeShares, uint stakeSharesIncrease, uint initialTrancheId, uint newTrancheId, uint blockTimestamp ) public pure returns (uint) { uint timeLeftOfInitialTranche = getTimeLeftOfTranche(initialTrancheId, blockTimestamp); uint timeLeftOfNewTranche = getTimeLeftOfTranche(newTrancheId, blockTimestamp); // the bonus is based on the the time left and the total amount of stake shares (initial + new) uint newBonusShares = (initialStakeShares + stakeSharesIncrease) * REWARD_BONUS_PER_TRANCHE_RATIO * timeLeftOfNewTranche / TRANCHE_DURATION / REWARD_BONUS_PER_TRANCHE_DENOMINATOR; // for existing deposits, the previous bonus is deducted from the final amount uint previousBonusSharesDeduction = initialStakeShares * REWARD_BONUS_PER_TRANCHE_RATIO * timeLeftOfInitialTranche / TRANCHE_DURATION / REWARD_BONUS_PER_TRANCHE_DENOMINATOR; return stakeSharesIncrease + newBonusShares - previousBonusSharesDeduction; } function withdraw( uint tokenId, bool withdrawStake, bool withdrawRewards, uint[] memory trancheIds ) public whenNotPaused returns (uint withdrawnStake, uint withdrawnRewards) { uint managerLockedInGovernanceUntil = nxm.isLockedForMV(manager()); // pass false as it does not modify the share supply nor the reward per second processExpirations(true); uint _accNxmPerRewardsShare = accNxmPerRewardsShare; uint _firstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint trancheCount = trancheIds.length; for (uint j = 0; j < trancheCount; j++) { uint trancheId = trancheIds[j]; Deposit memory deposit = deposits[tokenId][trancheId]; { uint trancheRewardsToWithdraw; uint trancheStakeToWithdraw; // can withdraw stake only if the tranche is expired if (withdrawStake && trancheId < _firstActiveTrancheId) { // Deposit withdrawals are not permitted while the manager is locked in governance to // prevent double voting. if (managerLockedInGovernanceUntil > block.timestamp) { revert ManagerNxmIsLockedForGovernanceVote(); } // calculate the amount of nxm for this deposit uint stake = expiredTranches[trancheId].stakeAmountAtExpiry; uint _stakeSharesSupply = expiredTranches[trancheId].stakeSharesSupplyAtExpiry; trancheStakeToWithdraw = stake * deposit.stakeShares / _stakeSharesSupply; withdrawnStake += trancheStakeToWithdraw; // mark as withdrawn deposit.stakeShares = 0; } if (withdrawRewards) { // if the tranche is expired, use the accumulator value saved at expiration time uint accNxmPerRewardShareToUse = trancheId < _firstActiveTrancheId ? expiredTranches[trancheId].accNxmPerRewardShareAtExpiry : _accNxmPerRewardsShare; // calculate reward since checkpoint uint newRewardPerShare = accNxmPerRewardShareToUse.uncheckedSub(deposit.lastAccNxmPerRewardShare); trancheRewardsToWithdraw = newRewardPerShare * deposit.rewardsShares / ONE_NXM + deposit.pendingRewards; withdrawnRewards += trancheRewardsToWithdraw; // save checkpoint deposit.lastAccNxmPerRewardShare = accNxmPerRewardShareToUse.toUint96(); deposit.pendingRewards = 0; } emit Withdraw(msg.sender, tokenId, trancheId, trancheStakeToWithdraw, trancheRewardsToWithdraw); } deposits[tokenId][trancheId] = deposit; } address destination = tokenId == 0 ? manager() : stakingNFT.ownerOf(tokenId); tokenController.withdrawNXMStakeAndRewards( destination, withdrawnStake, withdrawnRewards, poolId ); return (withdrawnStake, withdrawnRewards); } function requestAllocation( uint amount, uint previousPremium, AllocationRequest calldata request ) external onlyCoverContract returns (uint premium, uint allocationId) { // passing true because we change the reward per second processExpirations(true); // prevent allocation requests (edits and forced expirations) for expired covers if (request.allocationId != 0) { uint expirationBucketId = Math.divCeil(request.previousExpiration, BUCKET_DURATION); if (coverTrancheAllocations[request.allocationId] == 0 || firstActiveBucketId >= expirationBucketId) { revert AlreadyDeallocated(request.allocationId); } } uint[] memory trancheAllocations = request.allocationId == 0 ? getActiveAllocations(request.productId) : getActiveAllocationsWithoutCover( request.productId, request.allocationId, request.previousStart, request.previousExpiration ); // we are only deallocating // rewards streaming is left as is if (amount == 0) { // store deallocated amount updateStoredAllocations( request.productId, block.timestamp / TRANCHE_DURATION, // firstActiveTrancheId trancheAllocations ); // update coverTrancheAllocations when deallocating so we can track deallocation delete coverTrancheAllocations[request.allocationId]; emit Deallocated(request.allocationId); return (0, 0); } uint coverAllocationAmount; uint initialCapacityUsed; uint totalCapacity; ( coverAllocationAmount, initialCapacityUsed, totalCapacity, allocationId ) = allocate(amount, request, trancheAllocations); // the returned premium value has 18 decimals premium = stakingProducts.getPremium( poolId, request.productId, request.period, coverAllocationAmount, initialCapacityUsed, totalCapacity, request.globalMinPrice, request.useFixedPrice, NXM_PER_ALLOCATION_UNIT, ALLOCATION_UNITS_PER_NXM ); // add new rewards { if (request.rewardRatio > REWARDS_DENOMINATOR) { revert RewardRatioTooHigh(); } uint expirationBucket = Math.divCeil(block.timestamp + request.period, BUCKET_DURATION); uint rewardStreamPeriod = expirationBucket * BUCKET_DURATION - block.timestamp; uint _rewardPerSecond = (premium * request.rewardRatio / REWARDS_DENOMINATOR) / rewardStreamPeriod; // store rewardPerSecondCut[expirationBucket] += _rewardPerSecond; rewardPerSecond += _rewardPerSecond.toUint96(); uint rewardsToMint = _rewardPerSecond * rewardStreamPeriod; tokenController.mintStakingPoolNXMRewards(rewardsToMint, poolId); } // remove previous rewards if (previousPremium > 0) { uint prevRewards = previousPremium * request.previousRewardsRatio / REWARDS_DENOMINATOR; uint prevExpirationBucket = Math.divCeil(request.previousExpiration, BUCKET_DURATION); uint rewardStreamPeriod = prevExpirationBucket * BUCKET_DURATION - request.previousStart; uint prevRewardsPerSecond = prevRewards / rewardStreamPeriod; // store rewardPerSecondCut[prevExpirationBucket] -= prevRewardsPerSecond; rewardPerSecond -= prevRewardsPerSecond.toUint96(); // prevRewardsPerSecond * rewardStreamPeriodLeft uint rewardsToBurn = prevRewardsPerSecond * (prevExpirationBucket * BUCKET_DURATION - block.timestamp); tokenController.burnStakingPoolNXMRewards(rewardsToBurn, poolId); } return (premium, allocationId); } function getActiveAllocationsWithoutCover( uint productId, uint allocationId, uint start, uint expiration ) internal returns (uint[] memory activeAllocations) { uint packedCoverTrancheAllocation = coverTrancheAllocations[allocationId]; activeAllocations = getActiveAllocations(productId); uint currentFirstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint[] memory coverAllocations = new uint[](MAX_ACTIVE_TRANCHES); // number of already expired tranches to skip // currentFirstActiveTranche - previousFirstActiveTranche uint offset = currentFirstActiveTrancheId - (start / TRANCHE_DURATION); for (uint i = offset; i < MAX_ACTIVE_TRANCHES; i++) { uint allocated = uint32(packedCoverTrancheAllocation >> (i * 32)); uint currentTrancheIdx = i - offset; activeAllocations[currentTrancheIdx] -= allocated; coverAllocations[currentTrancheIdx] = allocated; } // remove expiring cover amounts from buckets updateExpiringCoverAmounts( productId, currentFirstActiveTrancheId, Math.divCeil(expiration, BUCKET_DURATION), // targetBucketId coverAllocations, false // isAllocation ); return activeAllocations; } function getActiveAllocations( uint productId ) public view returns (uint[] memory trancheAllocations) { uint _firstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint currentBucket = block.timestamp / BUCKET_DURATION; uint lastBucketId; (trancheAllocations, lastBucketId) = getStoredAllocations(productId, _firstActiveTrancheId); if (lastBucketId == 0) { lastBucketId = currentBucket; } for (uint bucketId = lastBucketId + 1; bucketId <= currentBucket; bucketId++) { uint[] memory expirations = getExpiringCoverAmounts(productId, bucketId, _firstActiveTrancheId); for (uint i = 0; i < MAX_ACTIVE_TRANCHES; i++) { trancheAllocations[i] -= expirations[i]; } } return trancheAllocations; } function getStoredAllocations( uint productId, uint firstTrancheId ) internal view returns ( uint[] memory storedAllocations, uint16 lastBucketId ) { storedAllocations = new uint[](MAX_ACTIVE_TRANCHES); uint firstGroupId = firstTrancheId / COVER_TRANCHE_GROUP_SIZE; uint lastGroupId = (firstTrancheId + MAX_ACTIVE_TRANCHES - 1) / COVER_TRANCHE_GROUP_SIZE; // min 2 and max 3 groups uint groupCount = lastGroupId - firstGroupId + 1; TrancheAllocationGroup[] memory allocationGroups = new TrancheAllocationGroup[](groupCount); for (uint i = 0; i < groupCount; i++) { allocationGroups[i] = trancheAllocationGroups[productId][firstGroupId + i]; } lastBucketId = allocationGroups[0].getLastBucketId(); // flatten groups for (uint i = 0; i < MAX_ACTIVE_TRANCHES; i++) { uint trancheId = firstTrancheId + i; uint trancheGroupIndex = trancheId / COVER_TRANCHE_GROUP_SIZE - firstGroupId; uint trancheIndexInGroup = trancheId % COVER_TRANCHE_GROUP_SIZE; storedAllocations[i] = allocationGroups[trancheGroupIndex].getItemAt(trancheIndexInGroup); } } function getExpiringCoverAmounts( uint productId, uint bucketId, uint firstTrancheId ) internal view returns (uint[] memory expiringCoverAmounts) { expiringCoverAmounts = new uint[](MAX_ACTIVE_TRANCHES); uint firstGroupId = firstTrancheId / BUCKET_TRANCHE_GROUP_SIZE; uint lastGroupId = (firstTrancheId + MAX_ACTIVE_TRANCHES - 1) / BUCKET_TRANCHE_GROUP_SIZE; // min 1, max 2 uint groupCount = lastGroupId - firstGroupId + 1; TrancheGroupBucket[] memory trancheGroupBuckets = new TrancheGroupBucket[](groupCount); // min 1 and max 2 reads for (uint i = 0; i < groupCount; i++) { trancheGroupBuckets[i] = expiringCoverBuckets[productId][bucketId][firstGroupId + i]; } // flatten bucket tranche groups for (uint i = 0; i < MAX_ACTIVE_TRANCHES; i++) { uint trancheId = firstTrancheId + i; uint trancheGroupIndex = trancheId / BUCKET_TRANCHE_GROUP_SIZE - firstGroupId; uint trancheIndexInGroup = trancheId % BUCKET_TRANCHE_GROUP_SIZE; expiringCoverAmounts[i] = trancheGroupBuckets[trancheGroupIndex].getItemAt(trancheIndexInGroup); } return expiringCoverAmounts; } function getActiveTrancheCapacities( uint productId, uint globalCapacityRatio, uint capacityReductionRatio ) public view returns ( uint[] memory trancheCapacities, uint totalCapacity ) { trancheCapacities = getTrancheCapacities( productId, block.timestamp / TRANCHE_DURATION, // first active tranche id MAX_ACTIVE_TRANCHES, globalCapacityRatio, capacityReductionRatio ); totalCapacity = Math.sum(trancheCapacities); return (trancheCapacities, totalCapacity); } function getTrancheCapacities( uint productId, uint firstTrancheId, uint trancheCount, uint capacityRatio, uint reductionRatio ) public view returns (uint[] memory trancheCapacities) { // will revert if with unprocessed expirations if (firstTrancheId < block.timestamp / TRANCHE_DURATION) { revert RequestedTrancheIsExpired(); } uint _activeStake = activeStake; uint _stakeSharesSupply = stakeSharesSupply; trancheCapacities = new uint[](trancheCount); if (_stakeSharesSupply == 0) { return trancheCapacities; } // TODO: can we get rid of the extra call to SP here? uint multiplier = capacityRatio * (CAPACITY_REDUCTION_DENOMINATOR - reductionRatio) * stakingProducts.getProductTargetWeight(poolId, productId); uint denominator = GLOBAL_CAPACITY_DENOMINATOR * CAPACITY_REDUCTION_DENOMINATOR * WEIGHT_DENOMINATOR; for (uint i = 0; i < trancheCount; i++) { uint trancheStake = (_activeStake * tranches[firstTrancheId + i].stakeShares / _stakeSharesSupply); trancheCapacities[i] = trancheStake * multiplier / denominator / NXM_PER_ALLOCATION_UNIT; } return trancheCapacities; } function allocate( uint amount, AllocationRequest calldata request, uint[] memory trancheAllocations ) internal returns ( uint coverAllocationAmount, uint initialCapacityUsed, uint totalCapacity, uint allocationId ) { if (request.allocationId == 0) { allocationId = ++lastAllocationId; } else { allocationId = request.allocationId; } coverAllocationAmount = Math.divCeil(amount, NXM_PER_ALLOCATION_UNIT); uint _firstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint[] memory coverAllocations = new uint[](MAX_ACTIVE_TRANCHES); { uint firstTrancheIdToUse = (block.timestamp + request.period + request.gracePeriod) / TRANCHE_DURATION; uint startIndex = firstTrancheIdToUse - _firstActiveTrancheId; uint[] memory trancheCapacities = getTrancheCapacities( request.productId, _firstActiveTrancheId, MAX_ACTIVE_TRANCHES, // count request.globalCapacityRatio, request.capacityReductionRatio ); uint remainingAmount = coverAllocationAmount; uint carryOver; uint packedCoverAllocations; for (uint i = 0; i < startIndex; i++) { uint allocated = trancheAllocations[i]; uint capacity = trancheCapacities[i]; if (allocated > capacity) { carryOver += allocated - capacity; } else if (carryOver > 0) { carryOver -= Math.min(carryOver, capacity - allocated); } } initialCapacityUsed = carryOver; for (uint i = startIndex; i < MAX_ACTIVE_TRANCHES; i++) { initialCapacityUsed += trancheAllocations[i]; totalCapacity += trancheCapacities[i]; if (trancheAllocations[i] >= trancheCapacities[i]) { // carry over overallocation carryOver += trancheAllocations[i] - trancheCapacities[i]; continue; } if (remainingAmount == 0) { // not breaking out of the for loop because we need the total capacity calculated above continue; } uint allocatedAmount; { uint available = trancheCapacities[i] - trancheAllocations[i]; if (carryOver > available) { // no capacity left in this tranche carryOver -= available; continue; } available -= carryOver; carryOver = 0; allocatedAmount = Math.min(available, remainingAmount); } coverAllocations[i] = allocatedAmount; trancheAllocations[i] += allocatedAmount; remainingAmount -= allocatedAmount; packedCoverAllocations |= allocatedAmount << i * 32; } coverTrancheAllocations[allocationId] = packedCoverAllocations; if (remainingAmount != 0) { revert InsufficientCapacity(); } } updateExpiringCoverAmounts( request.productId, _firstActiveTrancheId, Math.divCeil(block.timestamp + request.period, BUCKET_DURATION), // targetBucketId coverAllocations, true // isAllocation ); updateStoredAllocations( request.productId, _firstActiveTrancheId, trancheAllocations ); return (coverAllocationAmount, initialCapacityUsed, totalCapacity, allocationId); } function updateStoredAllocations( uint productId, uint firstTrancheId, uint[] memory allocations ) internal { uint firstGroupId = firstTrancheId / COVER_TRANCHE_GROUP_SIZE; uint lastGroupId = (firstTrancheId + MAX_ACTIVE_TRANCHES - 1) / COVER_TRANCHE_GROUP_SIZE; uint groupCount = lastGroupId - firstGroupId + 1; TrancheAllocationGroup[] memory allocationGroups = new TrancheAllocationGroup[](groupCount); // min 2 and max 3 reads for (uint i = 0; i < groupCount; i++) { allocationGroups[i] = trancheAllocationGroups[productId][firstGroupId + i]; } for (uint i = 0; i < MAX_ACTIVE_TRANCHES; i++) { uint trancheId = firstTrancheId + i; uint trancheGroupIndex = trancheId / COVER_TRANCHE_GROUP_SIZE - firstGroupId; uint trancheIndexInGroup = trancheId % COVER_TRANCHE_GROUP_SIZE; // setItemAt does not mutate so we have to reassign it allocationGroups[trancheGroupIndex] = allocationGroups[trancheGroupIndex].setItemAt( trancheIndexInGroup, allocations[i].toUint48() ); } uint16 currentBucket = (block.timestamp / BUCKET_DURATION).toUint16(); for (uint i = 0; i < groupCount; i++) { trancheAllocationGroups[productId][firstGroupId + i] = allocationGroups[i].setLastBucketId(currentBucket); } } function updateExpiringCoverAmounts( uint productId, uint firstTrancheId, uint targetBucketId, uint[] memory coverTrancheAllocation, bool isAllocation ) internal { uint firstGroupId = firstTrancheId / BUCKET_TRANCHE_GROUP_SIZE; uint lastGroupId = (firstTrancheId + MAX_ACTIVE_TRANCHES - 1) / BUCKET_TRANCHE_GROUP_SIZE; uint groupCount = lastGroupId - firstGroupId + 1; TrancheGroupBucket[] memory trancheGroupBuckets = new TrancheGroupBucket[](groupCount); // min 1 and max 2 reads for (uint i = 0; i < groupCount; i++) { trancheGroupBuckets[i] = expiringCoverBuckets[productId][targetBucketId][firstGroupId + i]; } for (uint i = 0; i < MAX_ACTIVE_TRANCHES; i++) { uint trancheId = firstTrancheId + i; uint trancheGroupId = trancheId / BUCKET_TRANCHE_GROUP_SIZE - firstGroupId; uint trancheIndexInGroup = trancheId % BUCKET_TRANCHE_GROUP_SIZE; uint32 expiringAmount = trancheGroupBuckets[trancheGroupId].getItemAt(trancheIndexInGroup); uint32 trancheAllocation = coverTrancheAllocation[i].toUint32(); if (isAllocation) { expiringAmount += trancheAllocation; } else { expiringAmount -= trancheAllocation; } // setItemAt does not mutate so we have to reassign it trancheGroupBuckets[trancheGroupId] = trancheGroupBuckets[trancheGroupId].setItemAt( trancheIndexInGroup, expiringAmount ); } for (uint i = 0; i < groupCount; i++) { expiringCoverBuckets[productId][targetBucketId][firstGroupId + i] = trancheGroupBuckets[i]; } } /// Extends the period of an existing deposit until a tranche that ends further into the future /// /// @param tokenId The id of the NFT that proves the ownership of the deposit. /// @param initialTrancheId The id of the tranche the deposit is already a part of. /// @param newTrancheId The id of the new tranche determining the new deposit period. /// @param topUpAmount An optional amount if the user wants to also increase the deposit function extendDeposit( uint tokenId, uint initialTrancheId, uint newTrancheId, uint topUpAmount ) external whenNotPaused whenNotHalted { // token id 0 is only used for pool manager fee tracking, no deposits allowed if (tokenId == 0) { revert InvalidTokenId(); } // validate token id exists and belongs to this pool // stakingPoolOf() reverts for non-existent tokens if (stakingNFT.stakingPoolOf(tokenId) != poolId) { revert InvalidStakingPoolForToken(); } if (isPrivatePool && msg.sender != manager()) { revert PrivatePool(); } if (!stakingNFT.isApprovedOrOwner(msg.sender, tokenId)) { revert NotTokenOwnerOrApproved(); } if (topUpAmount > 0 && block.timestamp <= nxm.isLockedForMV(msg.sender)) { revert NxmIsLockedForGovernanceVote(); } uint _firstActiveTrancheId = block.timestamp / TRANCHE_DURATION; { if (initialTrancheId >= newTrancheId) { revert NewTrancheEndsBeforeInitialTranche(); } uint maxTrancheId = _firstActiveTrancheId + MAX_ACTIVE_TRANCHES - 1; if (newTrancheId > maxTrancheId) { revert RequestedTrancheIsNotYetActive(); } if (newTrancheId < firstActiveTrancheId) { revert RequestedTrancheIsExpired(); } } // if the initial tranche is expired, withdraw everything and make a new deposit // this requires the user to have grante sufficient allowance if (initialTrancheId < _firstActiveTrancheId) { uint[] memory trancheIds = new uint[](1); trancheIds[0] = initialTrancheId; (uint withdrawnStake, /* uint rewardsToWithdraw */) = withdraw( tokenId, true, // withdraw the deposit true, // withdraw the rewards trancheIds ); depositTo(withdrawnStake + topUpAmount, newTrancheId, tokenId, msg.sender); return; // done! skip the rest of the function. } // if we got here - the initial tranche is still active. move all the shares to the new tranche // passing true because we mint reward shares processExpirations(true); Deposit memory initialDeposit = deposits[tokenId][initialTrancheId]; Deposit memory updatedDeposit = deposits[tokenId][newTrancheId]; uint _activeStake = activeStake; uint _stakeSharesSupply = stakeSharesSupply; uint newStakeShares; // calculate the new stake shares if there's a deposit top up if (topUpAmount > 0) { newStakeShares = _stakeSharesSupply * topUpAmount / _activeStake; activeStake = (_activeStake + topUpAmount).toUint96(); } // calculate the new reward shares uint newRewardsShares = calculateNewRewardShares( initialDeposit.stakeShares, newStakeShares, initialTrancheId, newTrancheId, block.timestamp ); { Tranche memory initialTranche = tranches[initialTrancheId]; Tranche memory newTranche = tranches[newTrancheId]; // move the shares to the new tranche initialTranche.stakeShares -= initialDeposit.stakeShares; initialTranche.rewardsShares -= initialDeposit.rewardsShares; newTranche.stakeShares += initialDeposit.stakeShares + newStakeShares.toUint128(); newTranche.rewardsShares += (initialDeposit.rewardsShares + newRewardsShares).toUint128(); // store the updated tranches tranches[initialTrancheId] = initialTranche; tranches[newTrancheId] = newTranche; } uint _accNxmPerRewardsShare = accNxmPerRewardsShare; // if there already is a deposit on the new tranche, calculate its pending rewards if (updatedDeposit.lastAccNxmPerRewardShare != 0) { uint newEarningsPerShare = _accNxmPerRewardsShare.uncheckedSub(updatedDeposit.lastAccNxmPerRewardShare); updatedDeposit.pendingRewards += (newEarningsPerShare * updatedDeposit.rewardsShares / ONE_NXM).toUint96(); } // calculate the rewards for the deposit being extended and move them to the new deposit { uint newEarningsPerShare = _accNxmPerRewardsShare.uncheckedSub(initialDeposit.lastAccNxmPerRewardShare); updatedDeposit.pendingRewards += (newEarningsPerShare * initialDeposit.rewardsShares / ONE_NXM).toUint96(); updatedDeposit.pendingRewards += initialDeposit.pendingRewards; } updatedDeposit.lastAccNxmPerRewardShare = _accNxmPerRewardsShare.toUint96(); updatedDeposit.stakeShares += (initialDeposit.stakeShares + newStakeShares).toUint128(); updatedDeposit.rewardsShares += (initialDeposit.rewardsShares + newRewardsShares).toUint128(); // everything is moved, delete the initial deposit delete deposits[tokenId][initialTrancheId]; // store the new deposit. deposits[tokenId][newTrancheId] = updatedDeposit; // update global shares supply stakeSharesSupply = (_stakeSharesSupply + newStakeShares).toUint128(); rewardsSharesSupply += newRewardsShares.toUint128(); // transfer nxm from the staker and update the pool deposit balance tokenController.depositStakedNXM(msg.sender, topUpAmount, poolId); emit DepositExtended(msg.sender, tokenId, initialTrancheId, newTrancheId, topUpAmount); } function burnStake(uint amount, BurnStakeParams calldata params) external onlyCoverContract { // passing false because neither the amount of shares nor the reward per second are changed processExpirations(false); // sload uint _activeStake = activeStake; // If all stake is burned, leave 1 wei and close pool if (amount >= _activeStake) { amount = _activeStake - 1; isHalted = true; } tokenController.burnStakedNXM(amount, poolId); // sstore activeStake = (_activeStake - amount).toUint96(); uint initialPackedCoverTrancheAllocation = coverTrancheAllocations[params.allocationId]; uint[] memory activeAllocations = getActiveAllocations(params.productId); uint currentFirstActiveTrancheId = block.timestamp / TRANCHE_DURATION; uint[] memory coverDeallocations = new uint[](MAX_ACTIVE_TRANCHES); uint remainingDeallocationAmount = params.deallocationAmount / NXM_PER_ALLOCATION_UNIT; uint newPackedCoverAllocations; // number of already expired tranches to skip // currentFirstActiveTranche - previousFirstActiveTranche uint offset = currentFirstActiveTrancheId - (params.start / TRANCHE_DURATION); // iterate the tranches backward to remove allocation from future tranches first for (uint i = MAX_ACTIVE_TRANCHES - 1; i >= offset; i--) { // i = tranche index when the allocation was made // i - offset = index of the same tranche but in currently active tranches arrays uint currentTrancheIdx = i - offset; uint allocated = uint32(initialPackedCoverTrancheAllocation >> (i * 32)); uint deallocateAmount = Math.min(allocated, remainingDeallocationAmount); activeAllocations[currentTrancheIdx] -= deallocateAmount; coverDeallocations[currentTrancheIdx] = deallocateAmount; newPackedCoverAllocations |= (allocated - deallocateAmount) << i * 32; remainingDeallocationAmount -= deallocateAmount; // avoids underflow in the for decrement loop if (i == 0) { break; } } coverTrancheAllocations[params.allocationId] = newPackedCoverAllocations; updateExpiringCoverAmounts( params.productId, currentFirstActiveTrancheId, Math.divCeil(params.start + params.period, BUCKET_DURATION), // targetBucketId coverDeallocations, false // isAllocation ); updateStoredAllocations( params.productId, currentFirstActiveTrancheId, activeAllocations ); emit StakeBurned(amount); } /* pool management */ function setPoolFee(uint newFee) external onlyManager { if (newFee > maxPoolFee) { revert PoolFeeExceedsMax(); } uint oldFee = poolFee; poolFee = uint8(newFee); // passing true because the amount of rewards shares changes processExpirations(true); uint fromTrancheId = block.timestamp / TRANCHE_DURATION; uint toTrancheId = fromTrancheId + MAX_ACTIVE_TRANCHES - 1; uint _accNxmPerRewardsShare = accNxmPerRewardsShare; for (uint trancheId = fromTrancheId; trancheId <= toTrancheId; trancheId++) { // sload Deposit memory feeDeposit = deposits[0][trancheId]; if (feeDeposit.rewardsShares == 0) { continue; } // update pending reward and reward shares uint newRewardPerRewardsShare = _accNxmPerRewardsShare.uncheckedSub(feeDeposit.lastAccNxmPerRewardShare); feeDeposit.pendingRewards += (newRewardPerRewardsShare * feeDeposit.rewardsShares / ONE_NXM).toUint96(); feeDeposit.lastAccNxmPerRewardShare = _accNxmPerRewardsShare.toUint96(); // TODO: would using tranche.rewardsShares give a better precision? feeDeposit.rewardsShares = (uint(feeDeposit.rewardsShares) * newFee / oldFee).toUint128(); // sstore deposits[0][trancheId] = feeDeposit; } emit PoolFeeChanged(msg.sender, newFee); } function setPoolPrivacy(bool _isPrivatePool) external onlyManager { isPrivatePool = _isPrivatePool; emit PoolPrivacyChanged(msg.sender, _isPrivatePool); } function setPoolDescription(string memory ipfsDescriptionHash) external onlyManager { emit PoolDescriptionSet(ipfsDescriptionHash); } /* getters */ function manager() public override view returns (address) { return tokenController.getStakingPoolManager(poolId); } function getPoolId() external override view returns (uint) { return poolId; } function getPoolFee() external override view returns (uint) { return poolFee; } function getMaxPoolFee() external override view returns (uint) { return maxPoolFee; } function getActiveStake() external override view returns (uint) { return activeStake; } function getStakeSharesSupply() external override view returns (uint) { return stakeSharesSupply; } function getRewardsSharesSupply() external override view returns (uint) { return rewardsSharesSupply; } function getRewardPerSecond() external override view returns (uint) { return rewardPerSecond; } function getAccNxmPerRewardsShare() external override view returns (uint) { return accNxmPerRewardsShare; } function getLastAccNxmUpdate() external override view returns (uint) { return lastAccNxmUpdate; } function getFirstActiveTrancheId() external override view returns (uint) { return firstActiveTrancheId; } function getFirstActiveBucketId() external override view returns (uint) { return firstActiveBucketId; } function getNextAllocationId() external override view returns (uint) { return lastAllocationId + 1; } function getDeposit(uint tokenId, uint trancheId) external override view returns ( uint lastAccNxmPerRewardShare, uint pendingRewards, uint stakeShares, uint rewardsShares ) { Deposit memory deposit = deposits[tokenId][trancheId]; return ( deposit.lastAccNxmPerRewardShare, deposit.pendingRewards, deposit.stakeShares, deposit.rewardsShares ); } function getTranche(uint trancheId) external override view returns ( uint stakeShares, uint rewardsShares ) { Tranche memory tranche = tranches[trancheId]; return ( tranche.stakeShares, tranche.rewardsShares ); } function getExpiredTranche(uint trancheId) external override view returns ( uint accNxmPerRewardShareAtExpiry, uint stakeAmountAtExpiry, uint stakeSharesSupplyAtExpiry ) { ExpiredTranche memory expiredTranche = expiredTranches[trancheId]; return ( expiredTranche.accNxmPerRewardShareAtExpiry, expiredTranche.stakeAmountAtExpiry, expiredTranche.stakeSharesSupplyAtExpiry ); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165.sol"; /** * @dev Required interface of an ERC721 compliant contract. */ interface IERC721 is IERC165 { /** * @dev Emitted when `tokenId` token is transferred from `from` to `to`. */ event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. */ event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); /** * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. */ event ApprovalForAll(address indexed owner, address indexed operator, bool approved); /** * @dev Returns the number of tokens in ``owner``'s account. */ function balanceOf(address owner) external view returns (uint256 balance); /** * @dev Returns the owner of the `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function ownerOf(uint256 tokenId) external view returns (address owner); /** * @dev Safely transfers `tokenId` token from `from` to `to`. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId, bytes calldata data ) external; /** * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients * are aware of the ERC721 protocol to prevent tokens from being forever locked. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must exist and be owned by `from`. * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}. * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. * * Emits a {Transfer} event. */ function safeTransferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Transfers `tokenId` token from `from` to `to`. * * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `tokenId` token must be owned by `from`. * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 tokenId ) external; /** * @dev Gives permission to `to` to transfer `tokenId` token to another account. * The approval is cleared when the token is transferred. * * Only a single account can be approved at a time, so approving the zero address clears previous approvals. * * Requirements: * * - The caller must own the token or be an approved operator. * - `tokenId` must exist. * * Emits an {Approval} event. */ function approve(address to, uint256 tokenId) external; /** * @dev Approve or remove `operator` as an operator for the caller. * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. * * Requirements: * * - The `operator` cannot be the caller. * * Emits an {ApprovalForAll} event. */ function setApprovalForAll(address operator, bool _approved) external; /** * @dev Returns the account approved for `tokenId` token. * * Requirements: * * - `tokenId` must exist. */ function getApproved(uint256 tokenId) external view returns (address operator); /** * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. * * See {setApprovalForAll} */ function isApprovedForAll(address owner, address operator) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.18; abstract contract Multicall { error RevertedWithoutReason(uint index); // WARNING: Do not set this function as payable function multicall(bytes[] calldata data) external returns (bytes[] memory results) { uint callCount = data.length; results = new bytes[](callCount); for (uint i = 0; i < callCount; i++) { (bool ok, bytes memory result) = address(this).delegatecall(data[i]); if (!ok) { uint length = result.length; // 0 length returned from empty revert() / require(false) if (length == 0) { revert RevertedWithoutReason(i); } assembly { revert(add(result, 0x20), length) } } results[i] = result; } } }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./IStakingPoolFactory.sol"; /** * @dev IStakingPoolFactory is missing the changeOperator() and operator() functions. * @dev Any change to the original interface will affect staking pool addresses * @dev This interface is created to add the missing functions so it can be used in other contracts. */ interface ICompleteStakingPoolFactory is IStakingPoolFactory { function operator() external view returns (address); function changeOperator(address newOperator) external; }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./ICoverNFT.sol"; import "./IStakingNFT.sol"; import "./IStakingPool.sol"; import "./ICompleteStakingPoolFactory.sol"; /* io structs */ enum ClaimMethod { IndividualClaims, YieldTokenIncidents } struct PoolAllocationRequest { uint40 poolId; bool skip; uint coverAmountInAsset; } struct BuyCoverParams { uint coverId; address owner; uint24 productId; uint8 coverAsset; uint96 amount; uint32 period; uint maxPremiumInAsset; uint8 paymentAsset; uint16 commissionRatio; address commissionDestination; string ipfsData; } /* storage structs */ struct PoolAllocation { uint40 poolId; uint96 coverAmountInNXM; uint96 premiumInNXM; uint24 allocationId; } struct CoverData { uint24 productId; uint8 coverAsset; uint96 amountPaidOut; } struct CoverSegment { uint96 amount; uint32 start; uint32 period; // seconds uint32 gracePeriod; // seconds uint24 globalRewardsRatio; uint24 globalCapacityRatio; } interface ICover { /* ========== DATA STRUCTURES ========== */ /* internal structs */ struct RequestAllocationVariables { uint previousPoolAllocationsLength; uint previousPremiumInNXM; uint refund; uint coverAmountInNXM; } /* storage structs */ struct ActiveCover { // Global active cover amount per asset. uint192 totalActiveCoverInAsset; // The last time activeCoverExpirationBuckets was updated uint64 lastBucketUpdateId; } /* ========== VIEWS ========== */ function coverData(uint coverId) external view returns (CoverData memory); function coverDataCount() external view returns (uint); function coverSegmentsCount(uint coverId) external view returns (uint); function coverSegments(uint coverId) external view returns (CoverSegment[] memory); function coverSegmentWithRemainingAmount( uint coverId, uint segmentId ) external view returns (CoverSegment memory); function recalculateActiveCoverInAsset(uint coverAsset) external; function totalActiveCoverInAsset(uint coverAsset) external view returns (uint); function getGlobalCapacityRatio() external view returns (uint); function getGlobalRewardsRatio() external view returns (uint); function getGlobalMinPriceRatio() external pure returns (uint); function getGlobalCapacityAndPriceRatios() external view returns ( uint _globalCapacityRatio, uint _globalMinPriceRatio ); function GLOBAL_MIN_PRICE_RATIO() external view returns (uint); /* === MUTATIVE FUNCTIONS ==== */ function buyCover( BuyCoverParams calldata params, PoolAllocationRequest[] calldata coverChunkRequests ) external payable returns (uint coverId); function burnStake( uint coverId, uint segmentId, uint amount ) external returns (address coverOwner); function changeStakingPoolFactoryOperator() external; function coverNFT() external returns (ICoverNFT); function stakingNFT() external returns (IStakingNFT); function stakingPoolFactory() external returns (ICompleteStakingPoolFactory); /* ========== EVENTS ========== */ event CoverEdited(uint indexed coverId, uint indexed productId, uint indexed segmentId, address buyer, string ipfsMetadata); // Auth error OnlyOwnerOrApproved(); // Cover details error CoverPeriodTooShort(); error CoverPeriodTooLong(); error CoverOutsideOfTheGracePeriod(); error CoverAmountIsZero(); // Products error ProductNotFound(); error ProductDeprecated(); error UnexpectedProductId(); // Cover and payment assets error CoverAssetNotSupported(); error InvalidPaymentAsset(); error UnexpectedCoverAsset(); error UnexpectedEthSent(); error EditNotSupported(); // Price & Commission error PriceExceedsMaxPremiumInAsset(); error CommissionRateTooHigh(); // ETH transfers error InsufficientEthSent(); error SendingEthToPoolFailed(); error SendingEthToCommissionDestinationFailed(); error ReturningEthRemainderToSenderFailed(); // Misc error ExpiredCoversCannotBeEdited(); error CoverNotYetExpired(uint coverId); error InsufficientCoverAmountAllocated(); error UnexpectedPoolId(); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "@openzeppelin/contracts-v4/token/ERC721/IERC721.sol"; interface ICoverNFT is IERC721 { function isApprovedOrOwner(address spender, uint tokenId) external returns (bool); function mint(address to) external returns (uint tokenId); function changeOperator(address newOperator) external; function changeNFTDescriptor(address newNFTDescriptor) external; function totalSupply() external view returns (uint); function name() external view returns (string memory); error NotOperator(); error NotMinted(); error WrongFrom(); error InvalidRecipient(); error InvalidNewOperatorAddress(); error InvalidNewNFTDescriptorAddress(); error NotAuthorized(); error UnsafeRecipient(); error AlreadyMinted(); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./ICover.sol"; /* io structs */ struct ProductInitializationParams { uint productId; uint8 weight; uint96 initialPrice; uint96 targetPrice; } /* storage structs */ struct Product { uint16 productType; address yieldTokenAddress; // cover assets bitmap. each bit represents whether the asset with // the index of that bit is enabled as a cover asset for this product uint32 coverAssets; uint16 initialPriceRatio; uint16 capacityReductionRatio; bool isDeprecated; bool useFixedPrice; } struct ProductType { uint8 claimMethod; uint32 gracePeriod; } interface ICoverProducts { /* storage structs */ struct Metadata { string ipfsHash; uint timestamp; } /* io structs */ struct ProductParam { string productName; uint productId; string ipfsMetadata; Product product; uint[] allowedPools; } struct ProductTypeParam { string productTypeName; uint productTypeId; string ipfsMetadata; ProductType productType; } /* ========== VIEWS ========== */ function getProductType(uint productTypeId) external view returns (ProductType memory); function getProductTypeName(uint productTypeId) external view returns (string memory); function getProductTypeCount() external view returns (uint); function getProductTypes() external view returns (ProductType[] memory); function getProduct(uint productId) external view returns (Product memory); function getProductName(uint productTypeId) external view returns (string memory); function getProductCount() external view returns (uint); function getProducts() external view returns (Product[] memory); // add grace period function? function getProductWithType(uint productId) external view returns (Product memory, ProductType memory); function getLatestProductMetadata(uint productId) external view returns (Metadata memory); function getLatestProductTypeMetadata(uint productTypeId) external view returns (Metadata memory); function getProductMetadata(uint productId) external view returns (Metadata[] memory); function getProductTypeMetadata(uint productTypeId) external view returns (Metadata[] memory); function getAllowedPools(uint productId) external view returns (uint[] memory _allowedPools); function getAllowedPoolsCount(uint productId) external view returns (uint); function isPoolAllowed(uint productId, uint poolId) external view returns (bool); function requirePoolIsAllowed(uint[] calldata productIds, uint poolId) external view; function getCapacityReductionRatios(uint[] calldata productIds) external view returns (uint[] memory); function getInitialPrices(uint[] calldata productIds) external view returns (uint[] memory); function prepareStakingProductsParams( ProductInitializationParams[] calldata params ) external returns ( ProductInitializationParams[] memory validatedParams ); /* === MUTATIVE FUNCTIONS ==== */ function setProductTypes(ProductTypeParam[] calldata productTypes) external; function setProducts(ProductParam[] calldata params) external; /* ========== EVENTS ========== */ event ProductSet(uint id); event ProductTypeSet(uint id); // Products and product types error ProductNotFound(); error ProductTypeNotFound(); error ProductDeprecated(); error PoolNotAllowedForThisProduct(uint productId); error StakingPoolDoesNotExist(); error MismatchedArrayLengths(); error MetadataRequired(); // Misc error UnsupportedCoverAssets(); error InitialPriceRatioBelowGlobalMinPriceRatio(); error InitialPriceRatioAbove100Percent(); error CapacityReductionRatioAbove100Percent(); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface ISAFURAMaster { function tokenAddress() external view returns (address); function owner() external view returns (address); function emergencyAdmin() external view returns (address); function masterInitialized() external view returns (bool); function isInternal(address _add) external view returns (bool); function isPause() external view returns (bool check); function isMember(address _add) external view returns (bool); function checkIsAuthToGoverned(address _add) external view returns (bool); function getLatestAddress(bytes2 _contractName) external view returns (address payable contractAddress); function contractAddresses(bytes2 code) external view returns (address payable); function upgradeMultipleContracts( bytes2[] calldata _contractCodes, address payable[] calldata newAddresses ) external; function removeContracts(bytes2[] calldata contractCodesToRemove) external; function addNewInternalContracts( bytes2[] calldata _contractCodes, address payable[] calldata newAddresses, uint[] calldata _types ) external; function updateOwnerParameters(bytes8 code, address payable val) external; }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface ISAFURAToken { function burn(uint256 amount) external returns (bool); function burnFrom(address from, uint256 value) external returns (bool); function operatorTransfer(address from, uint256 value) external returns (bool); function mint(address account, uint256 amount) external; function isLockedForMV(address member) external view returns (uint); function whiteListed(address member) external view returns (bool); function addToWhiteList(address _member) external returns (bool); function removeFromWhiteList(address _member) external returns (bool); function changeOperator(address _newOperator) external returns (bool); function lockForMemberVote(address _of, uint _days) external; /** * @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. * * IMPORTANT: 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); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "@openzeppelin/contracts-v4/token/ERC721/IERC721.sol"; interface IStakingNFT is IERC721 { function isApprovedOrOwner(address spender, uint tokenId) external returns (bool); function mint(uint poolId, address to) external returns (uint tokenId); function changeOperator(address newOperator) external; function changeNFTDescriptor(address newNFTDescriptor) external; function totalSupply() external returns (uint); function tokenInfo(uint tokenId) external view returns (uint poolId, address owner); function stakingPoolOf(uint tokenId) external view returns (uint poolId); function stakingPoolFactory() external view returns (address); function name() external view returns (string memory); error NotOperator(); error NotMinted(); error WrongFrom(); error InvalidRecipient(); error InvalidNewOperatorAddress(); error InvalidNewNFTDescriptorAddress(); error NotAuthorized(); error UnsafeRecipient(); error AlreadyMinted(); error NotStakingPool(); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; /* structs for io */ struct AllocationRequest { uint productId; uint coverId; uint allocationId; uint period; uint gracePeriod; bool useFixedPrice; uint previousStart; uint previousExpiration; uint previousRewardsRatio; uint globalCapacityRatio; uint capacityReductionRatio; uint rewardRatio; uint globalMinPrice; } struct BurnStakeParams { uint allocationId; uint productId; uint start; uint period; uint deallocationAmount; } interface IStakingPool { /* structs for storage */ // stakers are grouped in tranches based on the timelock expiration // tranche index is calculated based on the expiration date // the initial proposal is to have 4 tranches per year (1 tranche per quarter) struct Tranche { uint128 stakeShares; uint128 rewardsShares; } struct ExpiredTranche { uint96 accNxmPerRewardShareAtExpiry; uint96 stakeAmountAtExpiry; // nxm total supply is 6.7e24 and uint96.max is 7.9e28 uint128 stakeSharesSupplyAtExpiry; } struct Deposit { uint96 lastAccNxmPerRewardShare; uint96 pendingRewards; uint128 stakeShares; uint128 rewardsShares; } function initialize( bool isPrivatePool, uint initialPoolFee, uint maxPoolFee, uint _poolId, string memory ipfsDescriptionHash ) external; function processExpirations(bool updateUntilCurrentTimestamp) external; function requestAllocation( uint amount, uint previousPremium, AllocationRequest calldata request ) external returns (uint premium, uint allocationId); function burnStake(uint amount, BurnStakeParams calldata params) external; function depositTo( uint amount, uint trancheId, uint requestTokenId, address destination ) external returns (uint tokenId); function withdraw( uint tokenId, bool withdrawStake, bool withdrawRewards, uint[] memory trancheIds ) external returns (uint withdrawnStake, uint withdrawnRewards); function isPrivatePool() external view returns (bool); function isHalted() external view returns (bool); function manager() external view returns (address); function getPoolId() external view returns (uint); function getPoolFee() external view returns (uint); function getMaxPoolFee() external view returns (uint); function getActiveStake() external view returns (uint); function getStakeSharesSupply() external view returns (uint); function getRewardsSharesSupply() external view returns (uint); function getRewardPerSecond() external view returns (uint); function getAccNxmPerRewardsShare() external view returns (uint); function getLastAccNxmUpdate() external view returns (uint); function getFirstActiveTrancheId() external view returns (uint); function getFirstActiveBucketId() external view returns (uint); function getNextAllocationId() external view returns (uint); function getDeposit(uint tokenId, uint trancheId) external view returns ( uint lastAccNxmPerRewardShare, uint pendingRewards, uint stakeShares, uint rewardsShares ); function getTranche(uint trancheId) external view returns ( uint stakeShares, uint rewardsShares ); function getExpiredTranche(uint trancheId) external view returns ( uint accNxmPerRewardShareAtExpiry, uint stakeAmountAtExpiry, uint stakeShareSupplyAtExpiry ); function setPoolFee(uint newFee) external; function setPoolPrivacy(bool isPrivatePool) external; function getActiveAllocations( uint productId ) external view returns (uint[] memory trancheAllocations); function getTrancheCapacities( uint productId, uint firstTrancheId, uint trancheCount, uint capacityRatio, uint reductionRatio ) external view returns (uint[] memory trancheCapacities); /* ========== EVENTS ========== */ event StakeDeposited(address indexed user, uint256 amount, uint256 trancheId, uint256 tokenId); event DepositExtended(address indexed user, uint256 tokenId, uint256 initialTrancheId, uint256 newTrancheId, uint256 topUpAmount); event PoolPrivacyChanged(address indexed manager, bool isPrivate); event PoolFeeChanged(address indexed manager, uint newFee); event PoolDescriptionSet(string ipfsDescriptionHash); event Withdraw(address indexed user, uint indexed tokenId, uint tranche, uint amountStakeWithdrawn, uint amountRewardsWithdrawn); event StakeBurned(uint amount); event Deallocated(uint productId); event BucketExpired(uint bucketId); event TrancheExpired(uint trancheId); // Auth error OnlyCoverContract(); error OnlyStakingProductsContract(); error OnlyManager(); error PrivatePool(); error SystemPaused(); error PoolHalted(); // Fees error PoolFeeExceedsMax(); error MaxPoolFeeAbove100(); // Voting error NxmIsLockedForGovernanceVote(); error ManagerNxmIsLockedForGovernanceVote(); // Deposit error InsufficientDepositAmount(); error RewardRatioTooHigh(); // Staking NFTs error InvalidTokenId(); error NotTokenOwnerOrApproved(); error InvalidStakingPoolForToken(); // Tranche & capacity error NewTrancheEndsBeforeInitialTranche(); error RequestedTrancheIsNotYetActive(); error RequestedTrancheIsExpired(); error InsufficientCapacity(); // Allocation error AlreadyDeallocated(uint allocationId); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; interface IStakingPoolFactory { function stakingPoolCount() external view returns (uint); function beacon() external view returns (address); function create(address beacon) external returns (uint poolId, address stakingPoolAddress); event StakingPoolCreated(uint indexed poolId, address indexed stakingPoolAddress); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./ICoverProducts.sol"; import "./IStakingPool.sol"; interface IStakingProducts { struct StakedProductParam { uint productId; bool recalculateEffectiveWeight; bool setTargetWeight; uint8 targetWeight; bool setTargetPrice; uint96 targetPrice; } struct Weights { uint32 totalEffectiveWeight; uint32 totalTargetWeight; } struct StakedProduct { uint16 lastEffectiveWeight; uint8 targetWeight; uint96 targetPrice; uint96 bumpedPrice; uint32 bumpedPriceUpdateTime; } /* ============= PRODUCT FUNCTIONS ============= */ function setProducts(uint poolId, StakedProductParam[] memory params) external; function getProductTargetWeight(uint poolId, uint productId) external view returns (uint); function getTotalTargetWeight(uint poolId) external view returns (uint); function getTotalEffectiveWeight(uint poolId) external view returns (uint); function getProduct(uint poolId, uint productId) external view returns ( uint lastEffectiveWeight, uint targetWeight, uint targetPrice, uint bumpedPrice, uint bumpedPriceUpdateTime ); /* ============= PRICING FUNCTIONS ============= */ function getPremium( uint poolId, uint productId, uint period, uint coverAmount, uint initialCapacityUsed, uint totalCapacity, uint globalMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNxm ) external returns (uint premium); function calculateFixedPricePremium( uint coverAmount, uint period, uint fixedPrice, uint nxmPerAllocationUnit, uint targetPriceDenominator ) external pure returns (uint); function calculatePremium( StakedProduct memory product, uint period, uint coverAmount, uint initialCapacityUsed, uint totalCapacity, uint targetPrice, uint currentBlockTimestamp, uint nxmPerAllocationUnit, uint allocationUnitsPerNxm, uint targetPriceDenominator ) external pure returns (uint premium, StakedProduct memory); function calculatePremiumPerYear( uint basePrice, uint coverAmount, uint initialCapacityUsed, uint totalCapacity, uint nxmPerAllocationUnit, uint allocationUnitsPerNxm, uint targetPriceDenominator ) external pure returns (uint); // Calculates the premium for a given cover amount starting with the surge point function calculateSurgePremium( uint amountOnSurge, uint totalCapacity, uint allocationUnitsPerNxm ) external pure returns (uint); /* ========== STAKING POOL CREATION ========== */ function stakingPool(uint poolId) external view returns (IStakingPool); function getStakingPoolCount() external view returns (uint); function createStakingPool( bool isPrivatePool, uint initialPoolFee, uint maxPoolFee, ProductInitializationParams[] calldata productInitParams, string calldata ipfsDescriptionHash ) external returns (uint poolId, address stakingPoolAddress); function changeStakingPoolFactoryOperator(address newOperator) external; /* ============= EVENTS ============= */ event ProductUpdated(uint productId, uint8 targetWeight, uint96 targetPrice); /* ============= ERRORS ============= */ // Auth error OnlyStakingPool(); error OnlyCoverContract(); error OnlyManager(); // Products & weights error MustSetPriceForNewProducts(); error MustSetWeightForNewProducts(); error TargetPriceTooHigh(); error TargetPriceBelowMin(); error TargetWeightTooHigh(); error MustRecalculateEffectiveWeight(); error TotalTargetWeightExceeded(); error TotalEffectiveWeightExceeded(); // Staking Pool creation error ProductDoesntExistOrIsDeprecated(); error InvalidProductType(); error TargetPriceBelowGlobalMinPriceRatio(); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.5.0; import "./ISAFURAToken.sol"; interface ITokenController { struct StakingPoolNXMBalances { uint128 rewards; uint128 deposits; } struct CoverInfo { uint16 claimCount; bool hasOpenClaim; bool hasAcceptedClaim; uint96 requestedPayoutAmount; // note: still 128 bits available here, can be used later } struct StakingPoolOwnershipOffer { address proposedManager; uint96 deadline; } function coverInfo(uint id) external view returns ( uint16 claimCount, bool hasOpenClaim, bool hasAcceptedClaim, uint96 requestedPayoutAmount ); function withdrawCoverNote( address _of, uint[] calldata _coverIds, uint[] calldata _indexes ) external; function changeOperator(address _newOperator) external; function operatorTransfer(address _from, address _to, uint _value) external returns (bool); function burnFrom(address _of, uint amount) external returns (bool); function addToWhitelist(address _member) external; function removeFromWhitelist(address _member) external; function mint(address _member, uint _amount) external; function lockForMemberVote(address _of, uint _days) external; function withdrawClaimAssessmentTokens(address[] calldata users) external; function getLockReasons(address _of) external view returns (bytes32[] memory reasons); function totalSupply() external view returns (uint); function totalBalanceOf(address _of) external view returns (uint amount); function totalBalanceOfWithoutDelegations(address _of) external view returns (uint amount); function getTokenPrice() external view returns (uint tokenPrice); function token() external view returns (ISAFURAToken); function getStakingPoolManager(uint poolId) external view returns (address manager); function getManagerStakingPools(address manager) external view returns (uint[] memory poolIds); function isStakingPoolManager(address member) external view returns (bool); function getStakingPoolOwnershipOffer(uint poolId) external view returns (address proposedManager, uint deadline); function transferStakingPoolsOwnership(address from, address to) external; function assignStakingPoolManager(uint poolId, address manager) external; function createStakingPoolOwnershipOffer(uint poolId, address proposedManager, uint deadline) external; function acceptStakingPoolOwnershipOffer(uint poolId) external; function cancelStakingPoolOwnershipOffer(uint poolId) external; function mintStakingPoolNXMRewards(uint amount, uint poolId) external; function burnStakingPoolNXMRewards(uint amount, uint poolId) external; function depositStakedNXM(address from, uint amount, uint poolId) external; function withdrawNXMStakeAndRewards(address to, uint stakeToWithdraw, uint rewardsToWithdraw, uint poolId) external; function burnStakedNXM(uint amount, uint poolId) external; function stakingPoolNXMBalances(uint poolId) external view returns(uint128 rewards, uint128 deposits); function tokensLocked(address _of, bytes32 _reason) external view returns (uint256 amount); function getWithdrawableCoverNotes( address coverOwner ) external view returns ( uint[] memory coverIds, bytes32[] memory lockReasons, uint withdrawableAmount ); function getPendingRewards(address member) external view returns (uint); }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.18; /** * @dev Simple library that defines min, max and babylonian sqrt functions */ library Math { function min(uint a, uint b) internal pure returns (uint) { return a < b ? a : b; } function max(uint a, uint b) internal pure returns (uint) { return a > b ? a : b; } function sum(uint[] memory items) internal pure returns (uint) { uint count = items.length; uint total; for (uint i = 0; i < count; i++) { total += items[i]; } return total; } function divRound(uint a, uint b) internal pure returns (uint) { return (a + b / 2) / b; } function divCeil(uint a, uint b) internal pure returns (uint) { return (a + b - 1) / b; } function roundUp(uint a, uint b) internal pure returns (uint) { return divCeil(a, b) * b; } // babylonian method function sqrt(uint y) internal pure returns (uint) { if (y > 3) { uint z = y; uint x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } return z; } if (y != 0) { return 1; } return 0; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.18; /** * @dev Wrappers over Solidity's uintXX casting operators with added overflow * checks. * * Downcasting from uint256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such 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 SafeUintCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits */ function toUint248(uint256 value) internal pure returns (uint248) { require(value < 2**248, "SafeCast: value doesn\'t fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits */ function toUint240(uint256 value) internal pure returns (uint240) { require(value < 2**240, "SafeCast: value doesn\'t fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits */ function toUint232(uint256 value) internal pure returns (uint232) { require(value < 2**232, "SafeCast: value doesn\'t fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits */ function toUint224(uint256 value) internal pure returns (uint224) { require(value < 2**224, "SafeCast: value doesn\'t fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits */ function toUint216(uint256 value) internal pure returns (uint216) { require(value < 2**216, "SafeCast: value doesn\'t fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits */ function toUint208(uint256 value) internal pure returns (uint208) { require(value < 2**208, "SafeCast: value doesn\'t fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits */ function toUint200(uint256 value) internal pure returns (uint200) { require(value < 2**200, "SafeCast: value doesn\'t fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits */ function toUint192(uint256 value) internal pure returns (uint192) { require(value < 2**192, "SafeCast: value doesn\'t fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits */ function toUint184(uint256 value) internal pure returns (uint184) { require(value < 2**184, "SafeCast: value doesn\'t fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits */ function toUint176(uint256 value) internal pure returns (uint176) { require(value < 2**176, "SafeCast: value doesn\'t fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits */ function toUint168(uint256 value) internal pure returns (uint168) { require(value < 2**168, "SafeCast: value doesn\'t fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits */ function toUint160(uint256 value) internal pure returns (uint160) { require(value < 2**160, "SafeCast: value doesn\'t fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits */ function toUint152(uint256 value) internal pure returns (uint152) { require(value < 2**152, "SafeCast: value doesn\'t fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits */ function toUint144(uint256 value) internal pure returns (uint144) { require(value < 2**144, "SafeCast: value doesn\'t fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits */ function toUint136(uint256 value) internal pure returns (uint136) { require(value < 2**136, "SafeCast: value doesn\'t fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits */ function toUint120(uint256 value) internal pure returns (uint120) { require(value < 2**120, "SafeCast: value doesn\'t fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits */ function toUint112(uint256 value) internal pure returns (uint112) { require(value < 2**112, "SafeCast: value doesn\'t fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits */ function toUint104(uint256 value) internal pure returns (uint104) { require(value < 2**104, "SafeCast: value doesn\'t fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 96 bits */ function toUint96(uint256 value) internal pure returns (uint96) { require(value < 2**96, "SafeCast: value doesn\'t fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 88 bits */ function toUint88(uint256 value) internal pure returns (uint88) { require(value < 2**88, "SafeCast: value doesn\'t fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 80 bits */ function toUint80(uint256 value) internal pure returns (uint80) { require(value < 2**80, "SafeCast: value doesn\'t fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits */ function toUint56(uint256 value) internal pure returns (uint56) { require(value < 2**56, "SafeCast: value doesn\'t fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits */ function toUint48(uint256 value) internal pure returns (uint48) { require(value < 2**48, "SafeCast: value doesn\'t fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits */ function toUint40(uint256 value) internal pure returns (uint40) { require(value < 2**40, "SafeCast: value doesn\'t fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits */ function toUint24(uint256 value) internal pure returns (uint24) { require(value < 2**24, "SafeCast: value doesn\'t fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits"); return uint8(value); } }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.18; /** * @dev Simple library that defines basic math functions that allow overflow */ library UncheckedMath { function uncheckedAdd(uint a, uint b) internal pure returns (uint) { unchecked { return a + b; } } function uncheckedSub(uint a, uint b) internal pure returns (uint) { unchecked { return a - b; } } function uncheckedMul(uint a, uint b) internal pure returns (uint) { unchecked { return a * b; } } function uncheckedDiv(uint a, uint b) internal pure returns (uint) { unchecked { return a / b; } } }
// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.18; // 5 x uint48 activeAllocation + 1 x uint16 lastBucketId // 5 * 48 + 16 = 256 type TrancheAllocationGroup is uint; // group ids: ________0_________|_________1_________|_________3__ ... // tranche ids: 0 1 2 3 4 | 5 6 7 8 9 | 10 11 12 ... // active tranches: \________________________________/ // 8 x (uint32 expiringAllocation) type TrancheGroupBucket is uint; library StakingTypesLib { // TrancheAllocationGroup function getLastBucketId(TrancheAllocationGroup items) internal pure returns (uint16) { return uint16(TrancheAllocationGroup.unwrap(items)); } function setLastBucketId( TrancheAllocationGroup items, uint16 lastBucketId ) internal pure returns (TrancheAllocationGroup) { // applying the mask using binary AND to clear target item's bits uint mask = ~(uint(type(uint16).max)); uint underlying = TrancheAllocationGroup.unwrap(items); return TrancheAllocationGroup.wrap(underlying & mask | uint(lastBucketId)); } function getItemAt( TrancheAllocationGroup items, uint index ) internal pure returns (uint48 allocation) { uint underlying = TrancheAllocationGroup.unwrap(items); return uint48(underlying >> (index * 48 + 16)); } // heads up: does not mutate the TrancheAllocationGroup but returns a new one instead function setItemAt( TrancheAllocationGroup items, uint index, uint48 allocation ) internal pure returns (TrancheAllocationGroup) { // applying the mask using binary AND to clear target item's bits uint mask = ~(uint(type(uint64).max) << (index * 48 + 16)); uint item = uint(allocation) << (index * 48 + 16); uint underlying = TrancheAllocationGroup.unwrap(items) & mask | item; return TrancheAllocationGroup.wrap(underlying); } // TrancheGroupBucket function getItemAt( TrancheGroupBucket items, uint index ) internal pure returns (uint32) { uint underlying = TrancheGroupBucket.unwrap(items); return uint32(underlying >> (index * 32)); } // heads up: does not mutate the TrancheGroupBucket but returns a new one instead function setItemAt( TrancheGroupBucket items, uint index, uint32 value ) internal pure returns (TrancheGroupBucket) { // applying the mask using binary AND to clear target item's bits uint mask = ~(uint(type(uint32).max) << (index * 32)); uint itemUnderlying = uint(value) << (index * 32); uint groupUnderlying = TrancheGroupBucket.unwrap(items) & mask | itemUnderlying; return TrancheGroupBucket.wrap(groupUnderlying); } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_stakingNFT","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_coverContract","type":"address"},{"internalType":"address","name":"_tokenController","type":"address"},{"internalType":"address","name":"_master","type":"address"},{"internalType":"address","name":"_stakingProducts","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"allocationId","type":"uint256"}],"name":"AlreadyDeallocated","type":"error"},{"inputs":[],"name":"InsufficientCapacity","type":"error"},{"inputs":[],"name":"InsufficientDepositAmount","type":"error"},{"inputs":[],"name":"InvalidStakingPoolForToken","type":"error"},{"inputs":[],"name":"InvalidTokenId","type":"error"},{"inputs":[],"name":"ManagerNxmIsLockedForGovernanceVote","type":"error"},{"inputs":[],"name":"MaxPoolFeeAbove100","type":"error"},{"inputs":[],"name":"NewTrancheEndsBeforeInitialTranche","type":"error"},{"inputs":[],"name":"NotTokenOwnerOrApproved","type":"error"},{"inputs":[],"name":"NxmIsLockedForGovernanceVote","type":"error"},{"inputs":[],"name":"OnlyCoverContract","type":"error"},{"inputs":[],"name":"OnlyManager","type":"error"},{"inputs":[],"name":"OnlyStakingProductsContract","type":"error"},{"inputs":[],"name":"PoolFeeExceedsMax","type":"error"},{"inputs":[],"name":"PoolHalted","type":"error"},{"inputs":[],"name":"PrivatePool","type":"error"},{"inputs":[],"name":"RequestedTrancheIsExpired","type":"error"},{"inputs":[],"name":"RequestedTrancheIsNotYetActive","type":"error"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"RevertedWithoutReason","type":"error"},{"inputs":[],"name":"RewardRatioTooHigh","type":"error"},{"inputs":[],"name":"SystemPaused","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bucketId","type":"uint256"}],"name":"BucketExpired","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"productId","type":"uint256"}],"name":"Deallocated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"initialTrancheId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newTrancheId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"topUpAmount","type":"uint256"}],"name":"DepositExtended","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"ipfsDescriptionHash","type":"string"}],"name":"PoolDescriptionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"manager","type":"address"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"PoolFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"manager","type":"address"},{"indexed":false,"internalType":"bool","name":"isPrivate","type":"bool"}],"name":"PoolPrivacyChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"StakeBurned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"trancheId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"StakeDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"trancheId","type":"uint256"}],"name":"TrancheExpired","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tranche","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountStakeWithdrawn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountRewardsWithdrawn","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"ALLOCATION_UNITS_PER_NXM","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BUCKET_DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"BUCKET_TRANCHE_GROUP_SIZE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CAPACITY_REDUCTION_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"COVER_TRANCHE_GROUP_SIZE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GLOBAL_CAPACITY_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_ACTIVE_TRANCHES","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NXM_PER_ALLOCATION_UNIT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POOL_FEE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARDS_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARD_BONUS_PER_TRANCHE_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REWARD_BONUS_PER_TRANCHE_RATIO","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TRANCHE_DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WEIGHT_DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"components":[{"internalType":"uint256","name":"allocationId","type":"uint256"},{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"deallocationAmount","type":"uint256"}],"internalType":"struct BurnStakeParams","name":"params","type":"tuple"}],"name":"burnStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"initialStakeShares","type":"uint256"},{"internalType":"uint256","name":"stakeSharesIncrease","type":"uint256"},{"internalType":"uint256","name":"initialTrancheId","type":"uint256"},{"internalType":"uint256","name":"newTrancheId","type":"uint256"},{"internalType":"uint256","name":"blockTimestamp","type":"uint256"}],"name":"calculateNewRewardShares","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"coverContract","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"coverTrancheAllocations","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"trancheId","type":"uint256"},{"internalType":"uint256","name":"requestTokenId","type":"uint256"},{"internalType":"address","name":"destination","type":"address"}],"name":"depositTo","outputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"deposits","outputs":[{"internalType":"uint96","name":"lastAccNxmPerRewardShare","type":"uint96"},{"internalType":"uint96","name":"pendingRewards","type":"uint96"},{"internalType":"uint128","name":"stakeShares","type":"uint128"},{"internalType":"uint128","name":"rewardsShares","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"expiringCoverBuckets","outputs":[{"internalType":"TrancheGroupBucket","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"initialTrancheId","type":"uint256"},{"internalType":"uint256","name":"newTrancheId","type":"uint256"},{"internalType":"uint256","name":"topUpAmount","type":"uint256"}],"name":"extendDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAccNxmPerRewardsShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"productId","type":"uint256"}],"name":"getActiveAllocations","outputs":[{"internalType":"uint256[]","name":"trancheAllocations","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getActiveStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"globalCapacityRatio","type":"uint256"},{"internalType":"uint256","name":"capacityReductionRatio","type":"uint256"}],"name":"getActiveTrancheCapacities","outputs":[{"internalType":"uint256[]","name":"trancheCapacities","type":"uint256[]"},{"internalType":"uint256","name":"totalCapacity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"trancheId","type":"uint256"}],"name":"getDeposit","outputs":[{"internalType":"uint256","name":"lastAccNxmPerRewardShare","type":"uint256"},{"internalType":"uint256","name":"pendingRewards","type":"uint256"},{"internalType":"uint256","name":"stakeShares","type":"uint256"},{"internalType":"uint256","name":"rewardsShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"trancheId","type":"uint256"}],"name":"getExpiredTranche","outputs":[{"internalType":"uint256","name":"accNxmPerRewardShareAtExpiry","type":"uint256"},{"internalType":"uint256","name":"stakeAmountAtExpiry","type":"uint256"},{"internalType":"uint256","name":"stakeSharesSupplyAtExpiry","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFirstActiveBucketId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getFirstActiveTrancheId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastAccNxmUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMaxPoolFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getNextAllocationId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPoolId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardPerSecond","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRewardsSharesSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStakeSharesSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"trancheId","type":"uint256"}],"name":"getTranche","outputs":[{"internalType":"uint256","name":"stakeShares","type":"uint256"},{"internalType":"uint256","name":"rewardsShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"firstTrancheId","type":"uint256"},{"internalType":"uint256","name":"trancheCount","type":"uint256"},{"internalType":"uint256","name":"capacityRatio","type":"uint256"},{"internalType":"uint256","name":"reductionRatio","type":"uint256"}],"name":"getTrancheCapacities","outputs":[{"internalType":"uint256[]","name":"trancheCapacities","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_isPrivatePool","type":"bool"},{"internalType":"uint256","name":"_initialPoolFee","type":"uint256"},{"internalType":"uint256","name":"_maxPoolFee","type":"uint256"},{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"string","name":"ipfsDescriptionHash","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"isHalted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPrivatePool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"masterContract","outputs":[{"internalType":"contract ISAFURAMaster","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nxm","outputs":[{"internalType":"contract ISAFURAToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"updateUntilCurrentTimestamp","type":"bool"}],"name":"processExpirations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"previousPremium","type":"uint256"},{"components":[{"internalType":"uint256","name":"productId","type":"uint256"},{"internalType":"uint256","name":"coverId","type":"uint256"},{"internalType":"uint256","name":"allocationId","type":"uint256"},{"internalType":"uint256","name":"period","type":"uint256"},{"internalType":"uint256","name":"gracePeriod","type":"uint256"},{"internalType":"bool","name":"useFixedPrice","type":"bool"},{"internalType":"uint256","name":"previousStart","type":"uint256"},{"internalType":"uint256","name":"previousExpiration","type":"uint256"},{"internalType":"uint256","name":"previousRewardsRatio","type":"uint256"},{"internalType":"uint256","name":"globalCapacityRatio","type":"uint256"},{"internalType":"uint256","name":"capacityReductionRatio","type":"uint256"},{"internalType":"uint256","name":"rewardRatio","type":"uint256"},{"internalType":"uint256","name":"globalMinPrice","type":"uint256"}],"internalType":"struct AllocationRequest","name":"request","type":"tuple"}],"name":"requestAllocation","outputs":[{"internalType":"uint256","name":"premium","type":"uint256"},{"internalType":"uint256","name":"allocationId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardPerSecondCut","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"ipfsDescriptionHash","type":"string"}],"name":"setPoolDescription","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"setPoolFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_isPrivatePool","type":"bool"}],"name":"setPoolPrivacy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingNFT","outputs":[{"internalType":"contract IStakingNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingProducts","outputs":[{"internalType":"contract IStakingProducts","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenController","outputs":[{"internalType":"contract ITokenController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"trancheAllocationGroups","outputs":[{"internalType":"TrancheAllocationGroup","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"bool","name":"withdrawStake","type":"bool"},{"internalType":"bool","name":"withdrawRewards","type":"bool"},{"internalType":"uint256[]","name":"trancheIds","type":"uint256[]"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"withdrawnStake","type":"uint256"},{"internalType":"uint256","name":"withdrawnRewards","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061038e5760003560e01c806379087997116101de578063ae61df751161010f578063da5b4ee7116100ad578063eddd9d821161007c578063eddd9d8214610996578063ef980a62146109bd578063f3d1a10f146109e4578063f6e8eb20146109f857600080fd5b8063da5b4ee71461094c578063dd54a98c14610965578063e2db9a9414610978578063e3a5839b1461098157600080fd5b8063cd446e22116100e9578063cd446e221461088f578063d185ee11146108b6578063d2d7fddf146108e1578063d972e8ad1461090257600080fd5b8063ae61df7514610827578063b5216c3614610858578063c7ff15841461086b57600080fd5b806392e2dfed1161017c578063a1f1870911610156578063a1f18709146103ae578063a7612218146107e1578063a7d4d7e4146107f4578063ac9650d81461080757600080fd5b806392e2dfed146104e45780639501dc87146107bb5780639e43661f146107ce57600080fd5b806388f40fbf116101b857806388f40fbf146103ae5780638baa4989146107705780638c3110fe14610783578063915e5491146107a357600080fd5b8063790879971461075d578063809b18d5146104e457806383e25069146103ae57600080fd5b80632bd49780116102c357806347d30ab6116102615780635d70877c116102305780635d70877c146107195780636080f68d1461072b5780636741fad21461074b57806373bf18901461065c57600080fd5b806347d30ab61461065c578063481c6a75146106645780634e4a7fa31461066c57806357a607e51461070857600080fd5b806338fff2d01161029d57806338fff2d01461061d5780633abb449314610633578063404fde71146106465780634146f14e1461065457600080fd5b80632bd497801461054c5780632e286983146105e157806330e45f05146105f657600080fd5b806318b1efe6116103305780632393b1ca1161030a5780632393b1ca146104ec578063248a75b7146104fd57806327bda2b4146105245780632a6ea2121461052c57600080fd5b806318b1efe6146104535780631ad9076614610468578063200ebb58146104e457600080fd5b806313d135ed1161036c57806313d135ed146103f6578063160cee4b1461040057806317387b58146104285780631861bad91461044057600080fd5b806304ba189a146103935780630820f444146103ae5780630ce71e32146103b7575b600080fd5b61039b600581565b6040519081526020015b60405180910390f35b61039b61271081565b6103de7f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f981565b6040516001600160a01b0390911681526020016103a5565b61039b6277f88081565b61041361040e366004615744565b610a02565b604080519283526020830191909152016103a5565b600154600160601b90046001600160601b031661039b565b61039b61044e366004615818565b610f6e565b600154600160c01b900463ffffffff1661039b565b6104c9610476366004615853565b600081815260046020908152604091829020825160608101845281546001600160601b03808216808452600160601b909204169382018490526001909201546001600160801b0316930183905293909250565b604080519384526020840192909252908201526060016103a5565b61039b606481565b6001546001600160601b031661039b565b6103de7f000000000000000000000000baadc2cfb3dab70dcf96c6c22db0b21bbb59505681565b61039b611027565b61039b61053a366004615853565b60056020526000908152604090205481565b6105a761055a36600461586c565b6009602090815260009283526040808420909152908252902080546001909101546001600160601b0380831692600160601b900416906001600160801b0380821691600160801b90041684565b604080516001600160601b0395861681529490931660208501526001600160801b03918216928401929092521660608201526080016103a5565b6105f46105ef36600461588e565b61104e565b005b6103de7f000000000000000000000000925e40659323577d2263b7ea9d4f688de072a8ec81565b600254600160801b900464ffffffffff1661039b565b6105f46106413660046158c6565b6113d5565b60025463ffffffff1661039b565b61039b611448565b61039b600881565b6103de61145e565b6106e861067a36600461586c565b600091825260096020908152604080842092845291815291819020815160808101835281546001600160601b03808216808452600160601b909204169482018590526001909201546001600160801b03808216948301859052600160801b9091041660609091018190529093565b6040805194855260208501939093529183015260608201526080016103a5565b6000546001600160801b031661039b565b600254600160d81b900460ff1661039b565b61039b610739366004615853565b60086020526000908152604090205481565b600254600160d01b900460ff1661039b565b6105f461076b36600461595a565b6114ff565b6105f461077e36600461598c565b612108565b610796610791366004615853565b61219b565b6040516103a591906159e4565b600054600160801b90046001600160801b031661039b565b6105f46107c9366004615853565b612285565b6107966107dc366004615818565b612556565b6105f46107ef3660046159f7565b612795565b610413610802366004615a97565b6128d1565b61081a610815366004615ada565b612eed565b6040516103a59190615b94565b61039b610835366004615bf6565b600760209081526000938452604080852082529284528284209052825290205481565b61039b610866366004615c37565b613032565b60025461087f90600160c81b900460ff1681565b60405190151581526020016103a5565b6103de7f0000000000000000000000001ae7a669727cc7c2bb8bf00ef4c9840c5e167a1181565b61039b6108c436600461586c565b600660209081526000928352604080842090915290825290205481565b6108f46108ef366004615bf6565b613dbf565b6040516103a5929190615c78565b610413610910366004615853565b6000908152600360209081526040918290208251808401909352546001600160801b03808216808552600160801b909204169290910182905291565b60025464010000000090046001600160601b031661039b565b6105f461097336600461598c565b613df2565b61039b6103e881565b600154600160e01b900463ffffffff1661039b565b6103de7f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e7281565b6103de7f000000000000000000000000a07cf6eebac19d9a28b7ae4af83a95e519b8166381565b60025461087f90600160c01b900460ff1681565b61039b6224ea0081565b6000807f0000000000000000000000001ae7a669727cc7c2bb8bf00ef4c9840c5e167a116001600160a01b031663ff0938a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610a63573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a879190615c9a565b15610aa5576040516301ca793160e61b815260040160405180910390fd5b60007f000000000000000000000000925e40659323577d2263b7ea9d4f688de072a8ec6001600160a01b03166398fd371f610ade61145e565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015610b22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b469190615cb7565b9050610b526001613df2565b6001546001600160601b03166000610b6d6277f88042615cfc565b865190915060005b81811015610e1e576000888281518110610b9157610b91615d10565b60209081029190910181015160008e81526009835260408082208383528452808220815160808101835281546001600160601b038082168352600160601b9091041695810195909552600101546001600160801b0380821692860192909252600160801b9004166060840152909250808d8015610c0d57508684105b15610c9c5742891115610c33576040516363ef170960e11b815260040160405180910390fd5b60008481526004602052604090819020805460019091015491850151600160601b9091046001600160601b0316916001600160801b03908116918291610c7a911684615d26565b610c849190615cfc565b9250610c90838e615d3d565b600060408701529c5050505b8c15610d58576000878510610cb15788610cca565b6000858152600460205260409020546001600160601b03165b8451909150600090610ce69083906001600160601b0316614481565b905084602001516001600160601b0316670de0b6b3a764000086606001516001600160801b031683610d189190615d26565b610d229190615cfc565b610d2c9190615d3d565b9350610d38848d615d3d565b9b50610d438261448b565b6001600160601b031685525050600060208401525b60408051858152602081018390529081018390528f9033907fe08737ac48a1dab4b1a46c7dc9398bd5bfc6d7ad6fabb7cd8caa254de14def359060600160405180910390a3505060008d81526009602090815260408083209483529381529083902082518154928401516001600160601b03908116600160601b026001600160c01b0319909416911617919091178155918101516060909101516001600160801b03908116600160801b0291161760019091015580610e1681615d50565b915050610b75565b5060008a15610eb5576040516331a9108f60e11b8152600481018c90527f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f96001600160a01b031690636352211e90602401602060405180830381865afa158015610e8c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb09190615d69565b610ebd565b610ebd61145e565b60025460405163cc35b1b160e01b81526001600160a01b038084166004830152602482018b9052604482018a9052600160801b90920464ffffffffff1660648201529192507f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e72169063cc35b1b190608401600060405180830381600087803b158015610f4857600080fd5b505af1158015610f5c573d6000803e3d6000fd5b50505050505050505094509492505050565b600080610f7b85846144f3565b90506000610f8985856144f3565b905060006127106277f880836103e8610fa28c8e615d3d565b610fac9190615d26565b610fb69190615d26565b610fc09190615cfc565b610fca9190615cfc565b905060006127106277f88085610fe26103e88e615d26565b610fec9190615d26565b610ff69190615cfc565b6110009190615cfc565b90508061100d838b615d3d565b6110179190615d86565b9450505050505b95945050505050565b60025460009061104490600160a81b900462ffffff166001615d99565b62ffffff16905090565b336001600160a01b037f000000000000000000000000baadc2cfb3dab70dcf96c6c22db0b21bbb59505616146110975760405163ce57639760e01b815260040160405180910390fd5b6110a16000613df2565b600154600160601b90046001600160601b03168083106110dc576110c6600182615d86565b6002805460ff60c81b1916600160c81b17905592505b60025460405163e41060cd60e01b815260048101859052600160801b90910464ffffffffff1660248201527f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b03169063e41060cd90604401600060405180830381600087803b15801561115557600080fd5b505af1158015611169573d6000803e3d6000fd5b50505050611181838261117c9190615d86565b61448b565b600180546001600160601b0392909216600160601b026bffffffffffffffffffffffff60601b199092169190911790558135600090815260086020908152604082205491906111d29085013561219b565b905060006111e36277f88042615cfc565b604080516008808252610120820190925291925060009190602082016101008036833701905050905060006112216064670de0b6b3a7640000615cfc565b61122f906080890135615cfc565b90506000806112456277f88060408b0135615cfc565b61124f9086615d86565b9050600061125f60016008615d86565b90505b8181106113395760006112758383615d86565b90506000611284836020615d26565b8a901c63ffffffff169050600061129b8288614531565b9050808a84815181106112b0576112b0615d10565b602002602001018181516112c49190615d86565b905250875181908990859081106112dd576112dd615d10565b6020026020010181815250508360206112f69190615d26565b6113008284615d86565b901b95909517946113118188615d86565b96508360000361132357505050611339565b505050808061133190615db5565b915050611262565b5081600860008b6000013581526020019081526020016000208190555061138789602001358661137f8c606001358d604001356113769190615d3d565b6224ea00614549565b87600061456c565b6113968960200135868861480b565b6040518a81527f8c8ed170790f86961adab8559297e1e879f839da4879d703d9b7d4502349db239060200160405180910390a150505050505050505050565b6113dd61145e565b6001600160a01b0316336001600160a01b03161461140e5760405163605919ad60e11b815260040160405180910390fd5b7f620b71ba59f4bf619fea21a8038df3de79074cad49bc7cfef6a94a845b6cf9dc8160405161143d9190615dcc565b60405180910390a150565b61145b6064670de0b6b3a7640000615cfc565b81565b60025460405163380737c360e21b8152600160801b90910464ffffffffff1660048201526000907f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b03169063e01cdf0c90602401602060405180830381865afa1580156114d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114fa9190615d69565b905090565b7f0000000000000000000000001ae7a669727cc7c2bb8bf00ef4c9840c5e167a116001600160a01b031663ff0938a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561155d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115819190615c9a565b1561159f576040516301ca793160e61b815260040160405180910390fd5b600254600160c81b900460ff16156115ca57604051634aef26a960e01b815260040160405180910390fd5b836000036115eb576040516307ed98ed60e31b815260040160405180910390fd5b60025460405163cf11548b60e01b815260048101869052600160801b90910464ffffffffff16907f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f96001600160a01b03169063cf11548b90602401602060405180830381865afa158015611663573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116879190615cb7565b146116a557604051630a526af960e01b815260040160405180910390fd5b600254600160c01b900460ff1680156116d757506116c161145e565b6001600160a01b0316336001600160a01b031614155b156116f5576040516349e932bd60e11b815260040160405180910390fd5b60405163430c208160e01b8152336004820152602481018590527f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f96001600160a01b03169063430c2081906044016020604051808303816000875af1158015611762573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117869190615c9a565b6117a357604051634cd9539b60e11b815260040160405180910390fd5b60008111801561183a57506040516398fd371f60e01b81523360048201527f000000000000000000000000925e40659323577d2263b7ea9d4f688de072a8ec6001600160a01b0316906398fd371f90602401602060405180830381865afa158015611812573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118369190615cb7565b4211155b1561185857604051636fbfa1d760e01b815260040160405180910390fd5b60006118676277f88042615cfc565b905082841061188957604051636ef0780160e01b815260040160405180910390fd5b60006001611898600884615d3d565b6118a29190615d86565b9050808411156118c5576040516392fb02ab60e01b815260040160405180910390fd5b600154600160c01b900463ffffffff168410156118f55760405163d11ddee360e01b815260040160405180910390fd5b50808410156119705760408051600180825281830190925260009160208083019080368337019050509050848160008151811061193457611934615d10565b602002602001018181525050600061194f8760018085610a02565b50905061196761195f8583615d3d565b868933613032565b50505050612102565b61197a6001613df2565b600085815260096020908152604080832087845280835281842082516080808201855282546001600160601b038082168452600160601b918290048116848901526001948501546001600160801b03808216868a0152600160801b9182900481166060808801919091528e8c52978a52888b2089519586018a528054808516875285900484169a86019a909a5298860154808a1698850198909852909604871694820194909452915486549196929593900490931692909116908615611a855782611a458884615d26565b611a4f9190615cfc565b9050611a5e61117c8885615d3d565b6001600c6101000a8154816001600160601b0302191690836001600160601b031602179055505b6000611aa186604001516001600160801b0316838c8c42610f6e565b90506000600360008c81526020019081526020016000206040518060400160405290816000820160009054906101000a90046001600160801b03166001600160801b03166001600160801b031681526020016000820160109054906101000a90046001600160801b03166001600160801b03166001600160801b03168152505090506000600360008c81526020019081526020016000206040518060400160405290816000820160009054906101000a90046001600160801b03166001600160801b03166001600160801b031681526020016000820160109054906101000a90046001600160801b03166001600160801b03166001600160801b0316815250509050876040015182600001818151611bb99190615ddf565b6001600160801b03169052506060880151602083018051611bdb908390615ddf565b6001600160801b0316905250611bf084614a61565b8860400151611bff9190615dff565b81518290611c0e908390615dff565b6001600160801b0390811690915260608a0151611c379250611c3291869116615d3d565b614a61565b81602001818151611c489190615dff565b6001600160801b0390811690915260008e81526003602090815260408083208751978301518516600160801b9081029886169890981790558f83529091208451949091015182169094029216919091179091555060015485516001600160601b03918216911615611d1c578551600090611ccc9083906001600160601b0316614481565b9050611cfd670de0b6b3a764000088606001516001600160801b031683611cf39190615d26565b61117c9190615cfc565b87602001818151611d0e9190615e1f565b6001600160601b0316905250505b8651600090611d359083906001600160601b0316614481565b9050611d5c670de0b6b3a764000089606001516001600160801b031683611cf39190615d26565b87602001818151611d6d9190615e1f565b6001600160601b03169052506020808901519088018051611d8f908390615e1f565b6001600160601b0316905250611da690508161448b565b6001600160601b031686526040870151611dce90611c329085906001600160801b0316615d3d565b86604001818151611ddf9190615dff565b6001600160801b039081169091526060890151611e039250611c3291859116615d3d565b86606001818151611e149190615dff565b9150906001600160801b031690816001600160801b031681525050600960008d815260200190815260200160002060008c8152602001908152602001600020600080820160006101000a8154906001600160601b03021916905560008201600c6101000a8154906001600160601b0302191690556001820160006101000a8154906001600160801b0302191690556001820160106101000a8154906001600160801b030219169055505085600960008e815260200190815260200160002060008c815260200190815260200160002060008201518160000160006101000a8154816001600160601b0302191690836001600160601b03160217905550602082015181600001600c6101000a8154816001600160601b0302191690836001600160601b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b0316021790555060608201518160010160106101000a8154816001600160801b0302191690836001600160801b03160217905550905050611fa98385611c329190615d3d565b600080546001600160801b0319166001600160801b0392909216919091179055611fd282614a61565b60008054601090611ff4908490600160801b90046001600160801b0316615dff565b82546101009290920a6001600160801b0381810219909316919092169190910217905550600254604051630c36061160e11b8152336004820152602481018b9052600160801b90910464ffffffffff1660448201527f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b03169063186c0c2290606401600060405180830381600087803b15801561209757600080fd5b505af11580156120ab573d6000803e3d6000fd5b5050604080518f8152602081018f90529081018d9052606081018c90523392507f431443e9d10bd3a688b8f8554f4c479262ae505022d7b37c3d6849f8ef7324f6915060800160405180910390a250505050505050505b50505050565b61211061145e565b6001600160a01b0316336001600160a01b0316146121415760405163605919ad60e11b815260040160405180910390fd5b60028054821515600160c01b0260ff60c01b1990911617905560405133907f972890b5322556b724c8e4dec980e9d23a32918c8a236524d4b5190191601a429061219090841515815260200190565b60405180910390a250565b606060006121ac6277f88042615cfc565b905060006121bd6224ea0042615cfc565b905060006121cb8584614ac6565b90945061ffff16905060008190036121e05750805b60006121ed826001615d3d565b90505b82811161227c576000612204878387614cc1565b905060005b60088110156122675781818151811061222457612224615d10565b602002602001015187828151811061223e5761223e615d10565b602002602001018181516122529190615d86565b9052508061225f81615d50565b915050612209565b5050808061227490615d50565b9150506121f0565b50505050919050565b61228d61145e565b6001600160a01b0316336001600160a01b0316146122be5760405163605919ad60e11b815260040160405180910390fd5b600254600160d81b900460ff168111156122eb576040516338c0a19960e21b815260040160405180910390fd5b6002805460ff838116600160d01b90810260ff60d01b19841617909355919004166123166001613df2565b60006123256277f88042615cfc565b905060006001612336600884615d3d565b6123409190615d86565b6001549091506001600160601b0316825b8281116125195760008181527fec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6b60209081526040808320815160808101835281546001600160601b038082168352600160601b9091041693810193909352600101546001600160801b0380821692840192909252600160801b900416606082018190529091036123e15750612507565b80516000906123fa9085906001600160601b0316614481565b9050612421670de0b6b3a764000083606001516001600160801b031683611cf39190615d26565b826020018181516124329190615e1f565b6001600160601b03169052506124478461448b565b6001600160601b03168252606082015161247b908890612471908b906001600160801b0316615d26565b611c329190615cfc565b6001600160801b039081166060840190815260008581527fec8156718a8372b1db44bb411437d0870f3e3790d4a08526d024ce1b0b668f6b602090815260409182902086518154928801516001600160601b03908116600160601b026001600160c01b031990941691161791909117815594015190518216600160801b02911617600190920191909155505b8061251181615d50565b915050612351565b5060405185815233907f927f86db738f455726f09f0462bc510e3f0fe010971fd1eda5f3971e5e9ff1419060200160405180910390a25050505050565b60606125656277f88042615cfc565b8510156125855760405163d11ddee360e01b815260040160405180910390fd5b600154600054600160601b9091046001600160601b0316906001600160801b0316856001600160401b038111156125be576125be6156fe565b6040519080825280602002602001820160405280156125e7578160200160208202803683370190505b509250806000036125f957505061101e565b600254604051632d1ab88760e21b8152600160801b90910464ffffffffff166004820152602481018990526000907f000000000000000000000000a07cf6eebac19d9a28b7ae4af83a95e519b816636001600160a01b03169063b46ae21c90604401602060405180830381865afa158015612678573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061269c9190615cb7565b6126a886612710615d86565b6126b29088615d26565b6126bc9190615d26565b9050600060646126ce61271080615d26565b6126d89190615d26565b905060005b88811015612787576000846003826126f5858f615d3d565b8152602081019190915260400160002054612719906001600160801b031688615d26565b6127239190615cfc565b90506127386064670de0b6b3a7640000615cfc565b836127438684615d26565b61274d9190615cfc565b6127579190615cfc565b87838151811061276957612769615d10565b6020908102919091010152508061277f81615d50565b9150506126dd565b505050505095945050505050565b336001600160a01b037f000000000000000000000000a07cf6eebac19d9a28b7ae4af83a95e519b8166316146127de5760405163d1fc521b60e01b815260040160405180910390fd5b838511156127ff576040516338c0a19960e21b815260040160405180910390fd5b6064841061282057604051633f7b651360e11b815260040160405180910390fd5b6002805460ff868116600160d81b0260ff60d81b19918916600160d01b0260ff60d01b198b1515600160c01b021662ff00ff60c01b1990941693909317929092171617905561286e83614e87565b600260106101000a81548164ffffffffff021916908364ffffffffff1602179055507f620b71ba59f4bf619fea21a8038df3de79074cad49bc7cfef6a94a845b6cf9dc82826040516128c1929190615e3f565b60405180910390a1505050505050565b600080336001600160a01b037f000000000000000000000000baadc2cfb3dab70dcf96c6c22db0b21bbb595056161461291d5760405163ce57639760e01b815260040160405180910390fd5b6129276001613df2565b60408301351561299f5760006129448460e001356224ea00614549565b60408086013560009081526008602052205490915015806129745750600154600160e01b900463ffffffff168111155b1561299d57604080516323164f8160e21b81529085013560048201526024015b60405180910390fd5b505b60006040840135156129c9576129c48435604086013560c087013560e0880135614eed565b6129d3565b6129d3843561219b565b905085600003612a4f576129f584356129ef6277f88042615cfc565b8361480b565b604080850135600081815260086020528281205590517fba4a86b943802e8312866d85e2d4969455ccd03609e5f90990f4b0dcffba62a091612a3a9190815260200190565b60405180910390a16000809250925050612ee5565b6000806000612a5f898886615016565b809850819450829550839650505050507f000000000000000000000000a07cf6eebac19d9a28b7ae4af83a95e519b816636001600160a01b0316634820c765600260109054906101000a900464ffffffffff1689600001358a606001358787878e61018001358f60a0016020810190612ad8919061598c565b612aeb6064670de0b6b3a7640000615cfc565b6040516001600160e01b031960e08c901b16815264ffffffffff90991660048a015260248901979097526044880195909552606487810194909452608487019290925260a486015260c485015290151560e4840152610104830191909152610124820152610144016020604051808303816000875af1158015612b72573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b969190615cb7565b95506127108761016001351115612bc0576040516323b0721160e11b815260040160405180910390fd5b6000612bd361137660608a013542615d3d565b9050600042612be56224ea0084615d26565b612bef9190615d86565b9050600081612710612c066101608d01358c615d26565b612c109190615cfc565b612c1a9190615cfc565b905080600560008581526020019081526020016000206000828254612c3f9190615d3d565b90915550612c4e90508161448b565b60028054600490612c7190849064010000000090046001600160601b0316615e1f565b92506101000a8154816001600160601b0302191690836001600160601b0316021790555060008282612ca39190615d26565b6002546040516308cd3d6f60e01b815260048101839052600160801b90910464ffffffffff1660248201529091507f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b0316906308cd3d6f90604401600060405180830381600087803b158015612d1f57600080fd5b505af1158015612d33573d6000803e3d6000fd5b50505050505050506000881115612ee0576000612710612d586101008a01358b615d26565b612d629190615cfc565b90506000612d778960e001356224ea00614549565b9050600060c08a0135612d8d6224ea0084615d26565b612d979190615d86565b90506000612da58285615cfc565b905080600560008581526020019081526020016000206000828254612dca9190615d86565b90915550612dd990508161448b565b60028054600490612dfc90849064010000000090046001600160601b0316615e6e565b92506101000a8154816001600160601b0302191690836001600160601b031602179055506000426224ea0085612e329190615d26565b612e3c9190615d86565b612e469083615d26565b600254604051631c96ae9760e11b815260048101839052600160801b90910464ffffffffff1660248201529091507f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b03169063392d5d2e90604401600060405180830381600087803b158015612ec257600080fd5b505af1158015612ed6573d6000803e3d6000fd5b5050505050505050505b505050505b935093915050565b606081806001600160401b03811115612f0857612f086156fe565b604051908082528060200260200182016040528015612f3b57816020015b6060815260200190600190039081612f265790505b50915060005b8181101561302a5760008030878785818110612f5f57612f5f615d10565b9050602002810190612f719190615e8e565b604051612f7f929190615edb565b600060405180830381855af49150503d8060008114612fba576040519150601f19603f3d011682016040523d82523d6000602084013e612fbf565b606091505b509150915081612ff75780516000819003612ff05760405163f1a8c42d60e01b815260048101859052602401612994565b8060208301fd5b8085848151811061300a5761300a615d10565b60200260200101819052505050808061302290615d50565b915050612f41565b505092915050565b60007f0000000000000000000000001ae7a669727cc7c2bb8bf00ef4c9840c5e167a116001600160a01b031663ff0938a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613092573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130b69190615c9a565b156130d4576040516301ca793160e61b815260040160405180910390fd5b600254600160c81b900460ff16156130ff57604051634aef26a960e01b815260040160405180910390fd5b600254600160c01b900460ff168015613131575061311b61145e565b6001600160a01b0316336001600160a01b031614155b1561314f576040516349e932bd60e11b815260040160405180910390fd5b6040516398fd371f60e01b81523360048201527f000000000000000000000000925e40659323577d2263b7ea9d4f688de072a8ec6001600160a01b0316906398fd371f90602401602060405180830381865afa1580156131b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131d79190615cb7565b42111580156131ff57506131e961145e565b6001600160a01b0316336001600160a01b031614155b1561321d57604051636fbfa1d760e01b815260040160405180910390fd5b600061322c6277f88042615cfc565b90506000600161323d600884615d3d565b6132479190615d86565b90508660000361326a5760405163145f674d60e21b815260040160405180910390fd5b8086111561328b576040516392fb02ab60e01b815260040160405180910390fd5b818610156132ac5760405163d11ddee360e01b815260040160405180910390fd5b600154600160c01b900463ffffffff1660000361334e576132cc82615420565b6001805463ffffffff92909216600160c01b0263ffffffff60c01b199092169190911790556133066133016224ea0042615cfc565b615420565b6001601c6101000a81548163ffffffff021916908363ffffffff16021790555061332f42615420565b6002805463ffffffff191663ffffffff92909216919091179055613358565b6133586001613df2565b5050600154600080546001600160601b03600160601b84048116936001600160801b0380841694600160801b909404169291169087810361345c5760006001600160a01b038816156133aa57876133ac565b335b6002546040516394bf804d60e01b8152600160801b90910464ffffffffff1660048201526001600160a01b0380831660248301529192507f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f9909116906394bf804d906044016020604051808303816000875af1158015613430573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134549190615cb7565b9650506135c8565b60025460405163cf11548b60e01b8152600481018a9052600160801b90910464ffffffffff16907f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f96001600160a01b03169063cf11548b90602401602060405180830381865afa1580156134d4573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134f89190615cb7565b1461351657604051630a526af960e01b815260040160405180910390fd5b60405163430c208160e01b8152336004820152602481018990527f00000000000000000000000037a57ee1a6964c6b59cefc499b2e5685803e03f96001600160a01b03169063430c2081906044016020604051808303816000875af1158015613583573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135a79190615c9a565b6135c457604051634cd9539b60e11b815260040160405180910390fd5b8795505b600084156135ea57856135db8c87615d26565b6135e59190615cfc565b6135f3565b6135f38b615485565b90506000808a156136695760008981526009602090815260408083208f8452825291829020825160808101845281546001600160601b038082168352600160601b9091041692810192909252600101546001600160801b0380821693830193909352600160801b9004909116606082015261368e565b6040805160808101825260008082526020820181905291810182905260608101919091525b90506136aa81604001516001600160801b0316848e8f42610f6e565b915080606001516001600160801b03166000146137205780516000906136da9087906001600160601b0316614481565b9050613701670de0b6b3a764000083606001516001600160801b031683611cf39190615d26565b826020018181516137129190615e1f565b6001600160601b0316905250505b61372983614a61565b8160400181815161373a9190615dff565b6001600160801b031690525061374f82614a61565b816060018181516137609190615dff565b6001600160801b03169052506137758561448b565b81600001906001600160601b031690816001600160601b03168152505080600960008b815260200190815260200160002060008e815260200190815260200160002060008201518160000160006101000a8154816001600160601b0302191690836001600160601b03160217905550602082015181600001600c6101000a8154816001600160601b0302191690836001600160601b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b0316021790555060608201518160010160106101000a8154816001600160801b0302191690836001600160801b031602179055509050505060006009600080815260200190815260200160002060008d81526020019081526020016000206040518060800160405290816000820160009054906101000a90046001600160601b03166001600160601b03166001600160601b0316815260200160008201600c9054906101000a90046001600160601b03166001600160601b03166001600160601b031681526020016001820160009054906101000a90046001600160801b03166001600160801b03166001600160801b031681526020016001820160109054906101000a90046001600160801b03166001600160801b03166001600160801b031681525050905060006002601a9054906101000a900460ff1660ff16606461397f9190615d86565b60025461399690600160d01b900460ff1685615d26565b6139a09190615cfc565b90506139ac8184615d3d565b82519093506000906139c89088906001600160601b0316614481565b90506139ef670de0b6b3a764000084606001516001600160801b031683611cf39190615d26565b83602001818151613a009190615e1f565b6001600160601b0316905250613a158761448b565b6001600160601b03168352613a2982614a61565b83606001818151613a3a9190615dff565b9150906001600160801b031690816001600160801b0316815250505050806009600080815260200190815260200160002060008e815260200190815260200160002060008201518160000160006101000a8154816001600160601b0302191690836001600160601b03160217905550602082015181600001600c6101000a8154816001600160601b0302191690836001600160601b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b0316021790555060608201518160010160106101000a8154816001600160801b0302191690836001600160801b03160217905550905050506000600360008d81526020019081526020016000206040518060400160405290816000820160009054906101000a90046001600160801b03166001600160801b03166001600160801b031681526020016000820160109054906101000a90046001600160801b03166001600160801b03166001600160801b0316815250509050613bbd83614a61565b81518290613bcc908390615dff565b6001600160801b0316905250613be182614a61565b81602001818151613bf29190615dff565b6001600160801b0390811690915260008e8152600360209081526040909120845191909401518216600160801b0291161790915550613c318c84615d3d565b9250613c3d8c88615d3d565b9650613c498287615d3d565b9550613c558186615d3d565b600254604051630c36061160e11b815233600482015260248101869052600160801b90910464ffffffffff1660448201529095507f0000000000000000000000000cb49cb0c47890d774dd5ae680a67c8c8bc99e726001600160a01b03169063186c0c2290606401600060405180830381600087803b158015613cd757600080fd5b505af1158015613ceb573d6000803e3d6000fd5b50505050613cf88761448b565b6001600c6101000a8154816001600160601b0302191690836001600160601b03160217905550613d2786614a61565b600080546001600160801b0319166001600160801b0392909216919091179055613d5085614a61565b600080546001600160801b03928316600160801b029216919091179055604080518d8152602081018d905290810189905233907feb6032fe8d7a2f7003e5b33948bdc807f994be970351cd021a033784812c8baa9060600160405180910390a250505050505050949350505050565b60606000613ddd85613dd46277f88042615cfc565b60088787612556565b9150613de8826154fc565b9050935093915050565b60015463ffffffff600160e01b8204811691600160c01b9004166000613e1b6224ea0042615cfc565b90506000613e2c6277f88042615cfc565b905083600003613e3d578193508092505b84613e6457818410818410811582613e53575080155b15613e615750505050505050565b50505b6001546002546000546001600160601b03600160601b840481169364010000000084048216936001600160801b0380851694600160801b900416929091169063ffffffff16428103613ebd575050505050505050505050565b878a1080613eca57508689105b156142cc576000806224ea00613ee18d6001615d3d565b613eeb9190615d26565b905060006277f880613efe8d6001615d3d565b613f089190615d26565b909111801592509050613fe557613f1e8b615d50565b9a506000613f2f6224ea008d615d26565b90506000613f3d8483615d86565b9050600086600003613f50576000613f78565b86670de0b6b3a7640000613f648b85615d26565b613f6e9190615d26565b613f789190615cfc565b60008f81526005602052604090205496810196909150613f98908a615d86565b98508294507fc4f02ff0e7a03eddfec5cbfd9f8b9f01332bb451d8aeea1263f7906451bf253360018f613fcb9190615d86565b60405190815260200160405180910390a150505050613ebd565b60006277f880613ff68c6001615d3d565b6140009190615d26565b9050600061400e8483615d86565b9050600086600003614021576000614049565b86670de0b6b3a76400006140358b85615d26565b61403f9190615d26565b6140499190615cfc565b9050858101955082945060405180606001604052806140678861448b565b6001600160601b0316815260200161407e8c61448b565b6001600160601b031681526020016140958a614a61565b6001600160801b0316815250600460008f815260200190815260200160002060008201518160000160006101000a8154816001600160601b0302191690836001600160601b03160217905550602082015181600001600c6101000a8154816001600160601b0302191690836001600160601b0316021790555060408201518160010160006101000a8154816001600160801b0302191690836001600160801b031602179055509050506000600360008f81526020019081526020016000206040518060400160405290816000820160009054906101000a90046001600160801b03166001600160801b03166001600160801b031681526020016000820160109054906101000a90046001600160801b03166001600160801b03166001600160801b0316815250509050600360008f8152602001908152602001600020600080820160006101000a8154906001600160801b0302191690556000820160106101000a8154906001600160801b030219169055505060008960000361421957600061423a565b81518a90614230906001600160801b03168e615d26565b61423a9190615cfc565b9050614246818d615d86565b8251909c5061425e906001600160801b03168b615d86565b995081602001516001600160801b0316896142799190615d86565b98507fcc071cbd9ae50a4c78d1153b76bd2d46ba8d4c7662842718ec3de1d67a144daf8f6040516142ac91815260200190565b60405180910390a18e6142be81615d50565b9f5050505050505050613ebd565b8a156143245760006142de8242615d86565b90506000846000036142f1576000614319565b84670de0b6b3a76400006143058985615d26565b61430f9190615d26565b6143199190615cfc565b939093019250429150505b61432d89615420565b600160186101000a81548163ffffffff021916908363ffffffff1602179055506143568a615420565b6001601c6101000a81548163ffffffff021916908363ffffffff16021790555061437f8661448b565b6001600c6101000a8154816001600160601b0302191690836001600160601b031602179055506143ae8561448b565b600260046101000a8154816001600160601b0302191690836001600160601b031602179055506143dd8261448b565b600180546bffffffffffffffffffffffff19166001600160601b039290921691909117905561440b81615420565b6002805463ffffffff191663ffffffff9290921691909117905561442e84614a61565b600080546001600160801b0319166001600160801b039290921691909117905561445783614a61565b600080546001600160801b03928316600160801b0292169190911790555050505050505050505050565b8082035b92915050565b6000600160601b82106144ef5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203960448201526536206269747360d01b6064820152608401612994565b5090565b6000806277f880614505856001615d3d565b61450f9190615d26565b905082811161451f576000614529565b6145298382615d86565b949350505050565b60008183106145405781614542565b825b9392505050565b60008160016145588286615d3d565b6145629190615d86565b6145429190615cfc565b6000614579600886615cfc565b905060006008600161458b8289615d3d565b6145959190615d86565b61459f9190615cfc565b905060006145ad8383615d86565b6145b8906001615d3d565b90506000816001600160401b038111156145d4576145d46156fe565b6040519080825280602002602001820160405280156145fd578160200160208202803683370190505b50905060005b8281101561466d5760008a81526007602090815260408083208b845290915281209061462f8388615d3d565b81526020019081526020016000205482828151811061465057614650615d10565b60209081029190910101528061466581615d50565b915050614603565b5060005b600881101561478f576000614686828b615d3d565b9050600086614696600884615cfc565b6146a09190615d86565b905060006146af600884615eeb565b905060006146df828785815181106146c9576146c9615d10565b602002602001015161554d90919063ffffffff16565b905060006147058c87815181106146f8576146f8615d10565b6020026020010151615420565b90508a1561471e576147178183615eff565b915061472b565b6147288183615f1c565b91505b614759838389878151811061474257614742615d10565b60200260200101516155639092919063ffffffff16565b87858151811061476b5761476b615d10565b6020026020010181815250505050505050808061478790615d50565b915050614671565b5060005b828110156147ff578181815181106147ad576147ad615d10565b60209081029190910181015160008c81526007835260408082208c835290935291822090916147dc8489615d3d565b8152602081019190915260400160002055806147f781615d50565b915050614793565b50505050505050505050565b6000614818600584615cfc565b905060006005600161482b600887615d3d565b6148359190615d86565b61483f9190615cfc565b9050600061484d8383615d86565b614858906001615d3d565b90506000816001600160401b03811115614874576148746156fe565b60405190808252806020026020018201604052801561489d578160200160208202803683370190505b50905060005b82811015614902576000888152600660205260408120906148c48388615d3d565b8152602001908152602001600020548282815181106148e5576148e5615d10565b6020908102919091010152806148fa81615d50565b9150506148a3565b5060005b60088110156149c957600061491b8289615d3d565b905060008661492b600584615cfc565b6149359190615d86565b90506000614944600584615eeb565b90506149958161496c8b878151811061495f5761495f615d10565b60200260200101516155a1565b87858151811061497e5761497e615d10565b60200260200101516156089092919063ffffffff16565b8583815181106149a7576149a7615d10565b60200260200101818152505050505080806149c190615d50565b915050614906565b5060006149e16149dc6224ea0042615cfc565b615661565b905060005b83811015614a5657614a1a82848381518110614a0457614a04615d10565b60200260200101516156c490919063ffffffff16565b60008a815260066020526040812090614a33848a615d3d565b815260208101919091526040016000205580614a4e81615d50565b9150506149e6565b505050505050505050565b6000600160801b82106144ef5760405162461bcd60e51b815260206004820152602760248201527f53616665436173743a2076616c756520646f65736e27742066697420696e20316044820152663238206269747360c81b6064820152608401612994565b60408051600880825261012082019092526060916000919060208201610100803683370190505091506000614afc600585615cfc565b9050600060056001614b0f600888615d3d565b614b199190615d86565b614b239190615cfc565b90506000614b318383615d86565b614b3c906001615d3d565b90506000816001600160401b03811115614b5857614b586156fe565b604051908082528060200260200182016040528015614b81578160200160208202803683370190505b50905060005b82811015614be657600089815260066020526040812090614ba88388615d3d565b815260200190815260200160002054828281518110614bc957614bc9615d10565b602090810291909101015280614bde81615d50565b915050614b87565b50614c0881600081518110614bfd57614bfd615d10565b602002602001015190565b945060005b6008811015614cb5576000614c22828a615d3d565b9050600086614c32600584615cfc565b614c3c9190615d86565b90506000614c4b600584615eeb565b9050614c7981868481518110614c6357614c63615d10565b60200260200101516156d490919063ffffffff16565b65ffffffffffff168a8581518110614c9357614c93615d10565b6020026020010181815250505050508080614cad90615d50565b915050614c0d565b50505050509250929050565b604080516008808252610120820190925260609160208201610100803683370190505090506000614cf3600884615cfc565b9050600060086001614d058287615d3d565b614d0f9190615d86565b614d199190615cfc565b90506000614d278383615d86565b614d32906001615d3d565b90506000816001600160401b03811115614d4e57614d4e6156fe565b604051908082528060200260200182016040528015614d77578160200160208202803683370190505b50905060005b82811015614de75760008981526007602090815260408083208b8452909152812090614da98388615d3d565b815260200190815260200160002054828281518110614dca57614dca615d10565b602090810291909101015280614ddf81615d50565b915050614d7d565b5060005b6008811015614e7b576000614e008289615d3d565b9050600086614e10600884615cfc565b614e1a9190615d86565b90506000614e29600884615eeb565b9050614e41818684815181106146c9576146c9615d10565b63ffffffff16898581518110614e5957614e59615d10565b6020026020010181815250505050508080614e7390615d50565b915050614deb565b50505050509392505050565b60006501000000000082106144ef5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526530206269747360d01b6064820152608401612994565b600083815260086020526040902054606090614f088661219b565b91506000614f196277f88042615cfc565b60408051600880825261012082019092529192506000919060208201610100803683370190505090506000614f516277f88088615cfc565b614f5b9084615d86565b9050805b6008811015614fef576000614f75826020615d26565b86901c63ffffffff1690506000614f8c8484615d86565b905081888281518110614fa157614fa1615d10565b60200260200101818151614fb59190615d86565b90525084518290869083908110614fce57614fce615d10565b60200260200101818152505050508080614fe790615d50565b915050614f5f565b5061500a8984615002896224ea00614549565b85600061456c565b50505050949350505050565b600080600080856040013560000361506b576002805460159061504490600160a81b900462ffffff16615f39565b91906101000a81548162ffffff021916908362ffffff160217905562ffffff169050615072565b5060408501355b61508e876150896064670de0b6b3a7640000615cfc565b614549565b9350600061509f6277f88042615cfc565b604080516008808252610120820190925291925060009190602082016101008036833701905050905060006277f88060808a01356150e160608c013542615d3d565b6150eb9190615d3d565b6150f59190615cfc565b905060006151038483615d86565b905060006151238b600001358660088e61012001358f6101400135612556565b905088600080805b858110156151cd5760008e828151811061514757615147615d10565b60200260200101519050600086838151811061516557615165615d10565b6020026020010151905080821115615192576151818183615d86565b61518b9086615d3d565b94506151b8565b84156151b8576151ab856151a68484615d86565b614531565b6151b59086615d86565b94505b505080806151c590615d50565b91505061512b565b509099508990845b60088110156153ae578d81815181106151f0576151f0615d10565b60200260200101518c6152039190615d3d565b9b5084818151811061521757615217615d10565b60200260200101518b61522a9190615d3d565b9a5084818151811061523e5761523e615d10565b60200260200101518e828151811061525857615258615d10565b6020026020010151106152b45784818151811061527757615277615d10565b60200260200101518e828151811061529157615291615d10565b60200260200101516152a39190615d86565b6152ad9084615d3d565b925061539c565b831561539c576000808f83815181106152cf576152cf615d10565b60200260200101518784815181106152e9576152e9615d10565b60200260200101516152fb9190615d86565b9050808511156153185761530f8186615d86565b9450505061539c565b6153228582615d86565b9050600094506153328187614531565b9150508089838151811061534857615348615d10565b602002602001018181525050808f838151811061536757615367615d10565b6020026020010181815161537b9190615d3d565b9052506153888186615d86565b9450615395826020615d26565b1b91909117905b806153a681615d50565b9150506151d5565b50600089815260086020526040902081905582156153df57604051632e77ac1d60e11b815260040160405180910390fd5b5050505050506154098860000135836154018b60600135426113769190615d3d565b84600161456c565b6154158835838961480b565b505093509350935093565b600064010000000082106144ef5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203360448201526532206269747360d01b6064820152608401612994565b600060038211156154e65781600061549e600283615cfc565b6154a9906001615d3d565b90505b818110156154df579050806002816154c48187615cfc565b6154ce9190615d3d565b6154d89190615cfc565b90506154ac565b5092915050565b81156154f457506001919050565b506000919050565b805160009081805b828110156155455784818151811061551e5761551e615d10565b6020026020010151826155319190615d3d565b91508061553d81615d50565b915050615504565b509392505050565b60008261555b836020615d26565b1c9392505050565b600080615571846020615d26565b63ffffffff901b1990506000615588856020615d26565b63ffffffff9490941690931b9416939093179392505050565b6000660100000000000082106144ef5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203460448201526538206269747360d01b6064820152608401612994565b600080615616846030615d26565b615621906010615d3d565b6001600160401b03901b199050600061563b856030615d26565b615646906010615d3d565b65ffffffffffff9490941690931b9416939093179392505050565b60006201000082106144ef5760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b6064820152608401612994565b61ffff1661ffff19919091161790565b6000826156e2836030615d26565b61555b906010615d3d565b80151581146156fb57600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561573c5761573c6156fe565b604052919050565b6000806000806080858703121561575a57600080fd5b8435935060208086013561576d816156ed565b9350604086013561577d816156ed565b925060608601356001600160401b038082111561579957600080fd5b818801915088601f8301126157ad57600080fd5b8135818111156157bf576157bf6156fe565b8060051b91506157d0848301615714565b818152918301840191848101908b8411156157ea57600080fd5b938501935b83851015615808578435825293850193908501906157ef565b989b979a50959850505050505050565b600080600080600060a0868803121561583057600080fd5b505083359560208501359550604085013594606081013594506080013592509050565b60006020828403121561586557600080fd5b5035919050565b6000806040838503121561587f57600080fd5b50508035926020909101359150565b60008082840360c08112156158a257600080fd5b8335925060a0601f19820112156158b857600080fd5b506020830190509250929050565b600060208083850312156158d957600080fd5b82356001600160401b03808211156158f057600080fd5b818501915085601f83011261590457600080fd5b813581811115615916576159166156fe565b615928601f8201601f19168501615714565b9150808252868482850101111561593e57600080fd5b8084840185840137600090820190930192909252509392505050565b6000806000806080858703121561597057600080fd5b5050823594602084013594506040840135936060013592509050565b60006020828403121561599e57600080fd5b8135614542816156ed565b600081518084526020808501945080840160005b838110156159d9578151875295820195908201906001016159bd565b509495945050505050565b60208152600061454260208301846159a9565b60008060008060008060a08789031215615a1057600080fd5b8635615a1b816156ed565b955060208701359450604087013593506060870135925060808701356001600160401b0380821115615a4c57600080fd5b818901915089601f830112615a6057600080fd5b813581811115615a6f57600080fd5b8a6020828501011115615a8157600080fd5b6020830194508093505050509295509295509295565b60008060008385036101e0811215615aae57600080fd5b84359350602085013592506101a0603f1982011215615acc57600080fd5b506040840190509250925092565b60008060208385031215615aed57600080fd5b82356001600160401b0380821115615b0457600080fd5b818501915085601f830112615b1857600080fd5b813581811115615b2757600080fd5b8660208260051b8501011115615b3c57600080fd5b60209290920196919550909350505050565b6000815180845260005b81811015615b7457602081850181015186830182015201615b58565b506000602082860101526020601f19601f83011685010191505092915050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b82811015615be957603f19888603018452615bd7858351615b4e565b94509285019290850190600101615bbb565b5092979650505050505050565b600080600060608486031215615c0b57600080fd5b505081359360208301359350604090920135919050565b6001600160a01b03811681146156fb57600080fd5b60008060008060808587031215615c4d57600080fd5b8435935060208501359250604085013591506060850135615c6d81615c22565b939692955090935050565b604081526000615c8b60408301856159a9565b90508260208301529392505050565b600060208284031215615cac57600080fd5b8151614542816156ed565b600060208284031215615cc957600080fd5b5051919050565b634e487b7160e01b600052601260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600082615d0b57615d0b615cd0565b500490565b634e487b7160e01b600052603260045260246000fd5b808202811582820484141761448557614485615ce6565b8082018082111561448557614485615ce6565b600060018201615d6257615d62615ce6565b5060010190565b600060208284031215615d7b57600080fd5b815161454281615c22565b8181038181111561448557614485615ce6565b62ffffff8181168382160190808211156154df576154df615ce6565b600081615dc457615dc4615ce6565b506000190190565b6020815260006145426020830184615b4e565b6001600160801b038281168282160390808211156154df576154df615ce6565b6001600160801b038181168382160190808211156154df576154df615ce6565b6001600160601b038181168382160190808211156154df576154df615ce6565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b6001600160601b038281168282160390808211156154df576154df615ce6565b6000808335601e19843603018112615ea557600080fd5b8301803591506001600160401b03821115615ebf57600080fd5b602001915036819003821315615ed457600080fd5b9250929050565b8183823760009101908152919050565b600082615efa57615efa615cd0565b500690565b63ffffffff8181168382160190808211156154df576154df615ce6565b63ffffffff8281168282160390808211156154df576154df615ce6565b600062ffffff808316818103615f5157615f51615ce6565b600101939250505056fea2646970667358221220bbe01e239a258fb03dce892954d4b3e6996dde82a87281affa9afc67b938cb2b64736f6c63430008120033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 35 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.