comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
/// Payout to taker | function payTaker(MakerBet storage makerBet, address taker) private returns (bool fullyWithdrawn) {
fullyWithdrawn = false;
uint payout = 0;
for (uint betIndex = 0; betIndex < makerBet.takerBetsCount; betIndex++) {
if (makerBet.takerBets[betIndex].taker == taker) {
... | 0.4.24 |
/// Payout to verifier | function payVerifier(MakerBet storage makerBet) private returns (bool fullyWithdrawn) {
fullyWithdrawn = false;
if (!makerBet.trustedVerifierFeeSent) {
makerBet.trustedVerifierFeeSent = true;
uint payout = 0;
if (makerBet.outcome == BetOutcome.MakerWin) {
... | 0.4.24 |
/* Math utilities */ | function mul(uint256 _a, uint256 _b) private pure returns(uint256 c) {
if (_a == 0) {
return 0;
}
c = _a * _b;
assert(c / _a == _b);
return c;
} | 0.4.24 |
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/ | function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow, so we distribute
return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
} | 0.6.12 |
/**
* Mints Bananass
*/ | function mintBanana(uint numberOfTokens) public payable {
require(saleIsActive, "Sale must be active to mint Bananas");
require(numberOfTokens <= maxBananaPurchase, "Can only mint 20 tokens at a time");
require(totalSupply().add(numberOfTokens) <= MAX_BANANAS, "Purchase would exceed max suppl... | 0.7.0 |
/// @notice Deposit LP tokens to Staking contract for Reward token allocation.
/// @param pid The index of the pool. See `poolInfo`.
/// @param amount LP token amount to deposit.
/// @param to The receiver of `amount` deposit benefit. | function deposit(
uint256 pid,
uint256 amount,
address to
) public {
PoolInfo memory pool = updatePool(pid);
UserInfo storage user = userInfo[pid][to];
// Effects
user.amount = user.amount.add(amount);
user.rewardDebt = user.rewardDebt.add(int256(amou... | 0.8.6 |
/// @notice Harvest proceeds for transaction sender to `to`.
/// @param pid The index of the pool. See `poolInfo`.
/// @param to Receiver of Token rewards. | function harvest(uint256 pid, address to) public {
PoolInfo memory pool = updatePool(pid);
UserInfo storage user = userInfo[pid][msg.sender];
int256 accumulatedRewards = int256(user.amount.mul(pool.accRewardPerShare) / ACC_PRECISION);
uint256 _pendingRewards = accumulatedRewards.sub(user... | 0.8.6 |
/**
* @dev Swaps ETH for wrapped stETH and deposits the resulting wstETH to the ZkSync bridge.
* First withdraws ETH from the bridge if there is a pending balance.
* @param _amountIn The amount of ETH to swap.
*/ | function swapEthForStEth(uint256 _amountIn) internal returns (uint256) {
// swap Eth for stEth on the Lido contract
ILido(stEth).submit{value: _amountIn}(lidoReferral);
// approve the wStEth contract to take the stEth
IERC20(stEth).approve(wStEth, _amountIn);
// wrap to wStEth an... | 0.8.3 |
/**
* Returns the amount of days passed with vesting
*/ | function getDays(uint256 afterDays) public view returns (uint256) {
uint256 releaseTime = getListingTime();
uint256 time = releaseTime.add(afterDays);
if (block.timestamp < time) {
return 0;
}
uint256 diff = block.timestamp.sub(time);
uint256 ds = diff.div(1... | 0.7.6 |
// Returns the amount of tokens unlocked by vesting so far | function getUnlockedVestingAmount(address sender) public view returns (uint256) {
if (!isStarted(0)) {
return 0;
}
uint256 dailyTransferableAmount = 0;
for (uint256 i=0; i<vestingWallets[sender].length; i++) {
if (vestingWallets[sender][i].tota... | 0.7.6 |
/// @notice Removes and returns the n-th logical element
/// @param self the data structure
/// @param index which element (zero indexed) to remove and return
/// @return popped the specified element | function popByIndex(Self storage self, uint256 index) internal returns (uint256 popped) {
popped = getByIndex(self, index);
uint256 lastIndex = self.length - 1; // will not underflow b/c prior get
if (index < lastIndex) {
uint256 lastElement = getByIndex(self, lastIndex);
... | 0.8.9 |
/// @notice Returns the n-th logical element
/// @param self the data structure
/// @param index which element (zero indexed) to get
/// @return element the specified element | function getByIndex(Self storage self, uint256 index) internal view returns (uint256 element) {
require(index < self.length, "Out of bounds");
return self.elements[index] == 0
? index + 1 // revert on overflow
: self.elements[index];
} | 0.8.9 |
/// @notice Adds a new entry to the end of the queue
/// @param self the data structure
/// @param beneficiary an address associated with the commitment
/// @param quantity how many to enqueue | function enqueue(Self storage self, address beneficiary, uint32 quantity) internal {
require(quantity > 0, "Quantity is missing");
self.elements[self.endIndex] = Element(
beneficiary,
uint64(block.number), // maturityBlock, hash thereof not yet known
quantity
... | 0.8.9 |
/// @notice Removes and returns the first element of the multi-queue; reverts if queue is empty
/// @param self the data structure
/// @return beneficiary an address associated with the commitment
/// @return maturityBlock when this commitment matured | function dequeue(Self storage self) internal returns (address beneficiary, uint64 maturityBlock) {
require(!_isEmpty(self), "Queue is empty");
beneficiary = self.elements[self.startIndex].beneficiary;
maturityBlock = self.elements[self.startIndex].maturityBlock;
if (self.elements[self.st... | 0.8.9 |
/**
* @notice Admin function to add iToken into supported markets
* Checks if the iToken already exsits
* Will `revert()` if any check fails
* @param _iToken The _iToken to add
* @param _collateralFactor The _collateralFactor of _iToken
* @param _borrowFactor The _borrowFactor of _iToken
* @param _supplyCapacity... | function _addMarket(
address _iToken,
uint256 _collateralFactor,
uint256 _borrowFactor,
uint256 _supplyCapacity,
uint256 _borrowCapacity,
uint256 _distributionFactor
) external override onlyOwner {
require(IiToken(_iToken).isSupported(), "Token is not supporte... | 0.6.12 |
/**
* @notice Sets liquidationIncentive
* @dev Admin function to set liquidationIncentive
* @param _newLiquidationIncentiveMantissa New liquidationIncentive scaled by 1e18
*/ | function _setLiquidationIncentive(uint256 _newLiquidationIncentiveMantissa)
external
override
onlyOwner
{
require(
_newLiquidationIncentiveMantissa >=
liquidationIncentiveMinMantissa &&
_newLiquidationIncentiveMantissa <=
li... | 0.6.12 |
/**
* @notice Sets the collateralFactor for a iToken
* @dev Admin function to set collateralFactor for a iToken
* @param _iToken The token to set the factor on
* @param _newCollateralFactorMantissa The new collateral factor, scaled by 1e18
*/ | function _setCollateralFactor(
address _iToken,
uint256 _newCollateralFactorMantissa
) external override onlyOwner {
_checkiTokenListed(_iToken);
require(
_newCollateralFactorMantissa <= collateralFactorMaxMantissa,
"Collateral factor invalid"
);
... | 0.6.12 |
/**
* @notice Sets the borrowFactor for a iToken
* @dev Admin function to set borrowFactor for a iToken
* @param _iToken The token to set the factor on
* @param _newBorrowFactorMantissa The new borrow factor, scaled by 1e18
*/ | function _setBorrowFactor(address _iToken, uint256 _newBorrowFactorMantissa)
external
override
onlyOwner
{
_checkiTokenListed(_iToken);
require(
_newBorrowFactorMantissa > 0 &&
_newBorrowFactorMantissa <= borrowFactorMaxMantissa,
"Borr... | 0.6.12 |
/**
* @notice Sets the pauseGuardian
* @dev Admin function to set pauseGuardian
* @param _newPauseGuardian The new pause guardian
*/ | function _setPauseGuardian(address _newPauseGuardian)
external
override
onlyOwner
{
address _oldPauseGuardian = pauseGuardian;
require(
_newPauseGuardian != address(0) &&
_newPauseGuardian != _oldPauseGuardian,
"Pause guardian address ... | 0.6.12 |
/**
* @notice pause/unpause entire protocol, including mint/redeem/borrow/seize/transfer
* @dev Admin function, only owner and pauseGuardian can call this
* @param _paused whether to pause or unpause
*/ | function _setProtocolPaused(bool _paused)
external
override
checkPauser(_paused)
{
EnumerableSetUpgradeable.AddressSet storage _iTokens = iTokens;
uint256 _len = _iTokens.length();
for (uint256 i = 0; i < _len; i++) {
address _iToken = _iTokens.at(i);
... | 0.6.12 |
/**
* @notice Sets Reward Distributor
* @dev Admin function to set reward distributor
* @param _newRewardDistributor new reward distributor
*/ | function _setRewardDistributor(address _newRewardDistributor)
external
override
onlyOwner
{
address _oldRewardDistributor = rewardDistributor;
require(
_newRewardDistributor != address(0) &&
_newRewardDistributor != _oldRewardDistributor,
... | 0.6.12 |
/**
* @notice Hook function before iToken `mint()`
* Checks if the account should be allowed to mint the given iToken
* Will `revert()` if any check fails
* @param _iToken The iToken to check the mint against
* @param _minter The account which would get the minted tokens
* @param _mintAmount The amount of underly... | function beforeMint(
address _iToken,
address _minter,
uint256 _mintAmount
) external override {
_checkiTokenListed(_iToken);
Market storage _market = markets[_iToken];
require(!_market.mintPaused, "Token mint has been paused");
// Check the iToken's supply ... | 0.6.12 |
/**
* @notice Hook function before iToken `redeem()`
* Checks if the account should be allowed to redeem the given iToken
* Will `revert()` if any check fails
* @param _iToken The iToken to check the redeem against
* @param _redeemer The account which would redeem iToken
* @param _redeemAmount The amount of iToke... | function beforeRedeem(
address _iToken,
address _redeemer,
uint256 _redeemAmount
) external override {
// _redeemAllowed below will check whether _iToken is listed
require(!markets[_iToken].redeemPaused, "Token redeem has been paused");
_redeemAllowed(_iToken, _rede... | 0.6.12 |
/**
* @notice Hook function before iToken `borrow()`
* Checks if the account should be allowed to borrow the given iToken
* Will `revert()` if any check fails
* @param _iToken The iToken to check the borrow against
* @param _borrower The account which would borrow iToken
* @param _borrowAmount The amount of under... | function beforeBorrow(
address _iToken,
address _borrower,
uint256 _borrowAmount
) external override {
_checkiTokenListed(_iToken);
Market storage _market = markets[_iToken];
require(!_market.borrowPaused, "Token borrow has been paused");
if (!hasBorrowed(_b... | 0.6.12 |
/// @notice A quantity of integers that were committed by anybody and are now mature are revealed
/// @param revealsLeft up to how many reveals will occur | function _reveal(uint32 revealsLeft) internal {
for (; revealsLeft > 0 && _commitQueue.isMature(); revealsLeft--) {
// Get one from queue
address recipient;
uint64 maturityBlock;
(recipient, maturityBlock) = _commitQueue.dequeue();
// Allocate randoml... | 0.8.9 |
/**
* @notice Hook function after iToken `repayBorrow()`
* Will `revert()` if any operation fails
* @param _iToken The iToken being repaid
* @param _payer The account which would repay
* @param _borrower The account which has borrowed
* @param _repayAmount The amount of underlying being repaied
*/ | function afterRepayBorrow(
address _iToken,
address _payer,
address _borrower,
uint256 _repayAmount
) external override {
_checkiTokenListed(_iToken);
// Remove _iToken from borrowed list if new borrow balance is 0
if (IiToken(_iToken).borrowBalanceStored(_bo... | 0.6.12 |
/**
* @notice Hook function before iToken `liquidateBorrow()`
* Checks if the account should be allowed to liquidate the given iToken
* for the borrower. Will `revert()` if any check fails
* @param _iTokenBorrowed The iToken was borrowed
* @param _iTokenCollateral The collateral iToken to be liqudate with
* @para... | function beforeLiquidateBorrow(
address _iTokenBorrowed,
address _iTokenCollateral,
address _liquidator,
address _borrower,
uint256 _repayAmount
) external override {
// Tokens must have been listed
require(
iTokens.contains(_iTokenBorrowed) &&
... | 0.6.12 |
/**
* @notice Hook function after iToken `liquidateBorrow()`
* Will `revert()` if any operation fails
* @param _iTokenBorrowed The iToken was borrowed
* @param _iTokenCollateral The collateral iToken to be seized
* @param _liquidator The account which would repay and seize
* @param _borrower The account which has... | function afterLiquidateBorrow(
address _iTokenBorrowed,
address _iTokenCollateral,
address _liquidator,
address _borrower,
uint256 _repaidAmount,
uint256 _seizedAmount
) external override {
_iTokenBorrowed;
_iTokenCollateral;
_liquidator;
... | 0.6.12 |
/**
* @notice Hook function before iToken `seize()`
* Checks if the liquidator should be allowed to seize the collateral iToken
* Will `revert()` if any check fails
* @param _iTokenCollateral The collateral iToken to be seize
* @param _iTokenBorrowed The iToken was borrowed
* @param _liquidator The account which ... | function beforeSeize(
address _iTokenCollateral,
address _iTokenBorrowed,
address _liquidator,
address _borrower,
uint256 _seizeAmount
) external override {
require(!seizePaused, "Seize has been paused");
// Markets must have been listed
require(
... | 0.6.12 |
/**
* @notice Hook function before iToken `transfer()`
* Checks if the transfer should be allowed
* Will `revert()` if any check fails
* @param _iToken The iToken to be transfered
* @param _from The account to be transfered from
* @param _to The account to be transfered to
* @param _amount The amount to be trans... | function beforeTransfer(
address _iToken,
address _from,
address _to,
uint256 _amount
) external override {
// _redeemAllowed below will check whether _iToken is listed
require(!transferPaused, "Transfer has been paused");
// Check account equity with this a... | 0.6.12 |
/**
* @notice Hook function before iToken `flashloan()`
* Checks if the flashloan should be allowed
* Will `revert()` if any check fails
* @param _iToken The iToken to be flashloaned
* @param _to The account flashloaned transfer to
* @param _amount The amount to be flashloaned
*/ | function beforeFlashloan(
address _iToken,
address _to,
uint256 _amount
) external override {
// Flashloan share the same pause state with borrow
require(!markets[_iToken].borrowPaused, "Token borrow has been paused");
_checkiTokenListed(_iToken);
_to;
... | 0.6.12 |
/// @notice Find the Plus Code representing `childCode` plus some more area if input is a valid Plus Code; otherwise
/// revert
/// @param childCode a Plus Code
/// @return parentCode the Plus Code representing the smallest area which contains the `childCode` area plus some
/// additional a... | function getParent(uint256 childCode) internal pure returns (uint256 parentCode) {
uint8 childCodeLength = getCodeLength(childCode);
if (childCodeLength == 2) {
revert("Code length 2 Plus Codes do not have parents");
}
if (childCodeLength == 4) {
return childCode ... | 0.8.9 |
/**
* @notice Calculate amount of collateral iToken to seize after repaying an underlying amount
* @dev Used in liquidation
* @param _iTokenBorrowed The iToken was borrowed
* @param _iTokenCollateral The collateral iToken to be seized
* @param _actualRepayAmount The amount of underlying token liquidator has repaie... | function liquidateCalculateSeizeTokens(
address _iTokenBorrowed,
address _iTokenCollateral,
uint256 _actualRepayAmount
) external view virtual override returns (uint256 _seizedTokenCollateral) {
/* Read oracle prices for borrowed and collateral assets */
uint256 _priceBorrowe... | 0.6.12 |
/**
* @notice Returns the markets list the account has entered
* @param _account The address of the account to query
* @return _accountCollaterals The markets list the account has entered
*/ | function getEnteredMarkets(address _account)
external
view
override
returns (address[] memory _accountCollaterals)
{
AccountData storage _accountData = accountsData[_account];
uint256 _len = _accountData.collaterals.length();
_accountCollaterals = new address... | 0.6.12 |
/**
* @notice Add markets to `msg.sender`'s markets list for liquidity calculations
* @param _iTokens The list of addresses of the iToken markets to be entered
* @return _results Success indicator for whether each corresponding market was entered
*/ | function enterMarkets(address[] calldata _iTokens)
external
override
returns (bool[] memory _results)
{
uint256 _len = _iTokens.length;
_results = new bool[](_len);
for (uint256 i = 0; i < _len; i++) {
_results[i] = _enterMarket(_iTokens[i], msg.sender);
... | 0.6.12 |
/**
* @notice Add the market to the account's markets list for liquidity calculations
* @param _iToken The market to enter
* @param _account The address of the account to modify
* @return True if entered successfully, false for non-listed market or other errors
*/ | function _enterMarket(address _iToken, address _account)
internal
returns (bool)
{
// Market not listed, skip it
if (!iTokens.contains(_iToken)) {
return false;
}
// add() will return false if iToken is in account's market list
if (accountsData[_a... | 0.6.12 |
/**
* @notice Remove markets from `msg.sender`'s collaterals for liquidity calculations
* @param _iTokens The list of addresses of the iToken to exit
* @return _results Success indicators for whether each corresponding market was exited
*/ | function exitMarkets(address[] calldata _iTokens)
external
override
returns (bool[] memory _results)
{
uint256 _len = _iTokens.length;
_results = new bool[](_len);
for (uint256 i = 0; i < _len; i++) {
_results[i] = _exitMarket(_iTokens[i], msg.sender);
... | 0.6.12 |
/// @dev Convert a Plus Code to an ASCII (and UTF-8) string
/// @param plusCode the Plus Code to format
/// @return the ASCII (and UTF-8) string showing the Plus Code | function toString(uint256 plusCode) internal pure returns(string memory) {
getCodeLength(plusCode);
bytes memory retval = new bytes(0);
while (plusCode > 0) {
retval = abi.encodePacked(uint8(plusCode % 2**8), retval);
plusCode >>= 8;
}
return string(retval... | 0.8.9 |
/**
* @notice Returns the asset list the account has borrowed
* @param _account The address of the account to query
* @return _borrowedAssets The asset list the account has borrowed
*/ | function getBorrowedAssets(address _account)
external
view
override
returns (address[] memory _borrowedAssets)
{
AccountData storage _accountData = accountsData[_account];
uint256 _len = _accountData.borrowed.length();
_borrowedAssets = new address[](_len);
... | 0.6.12 |
/**
* @notice Return all of the iTokens
* @return _alliTokens The list of iToken addresses
*/ | function getAlliTokens()
public
view
override
returns (address[] memory _alliTokens)
{
EnumerableSetUpgradeable.AddressSet storage _iTokens = iTokens;
uint256 _len = _iTokens.length();
_alliTokens = new address[](_len);
for (uint256 i = 0; i < _len; i... | 0.6.12 |
// Pick one ETH Winner when 5,000 cats are minted. | function _ethRaffle() private {
uint256 swag = 4959;
uint256 rd = randomizer() % 1000;
bytes32 txHash = keccak256(
abi.encode(
ownerOf(swag - 1000 + rd),
ownerOf(swag - 2000 + rd),
ownerOf(swag - 3000 + rd),
ownerOf(swag... | 0.7.3 |
// Pick one Tesla Winner when 9,999 cats are minted. | function _tesla() private {
require(totalSupply() == MAX_CATS);
uint256 swag = 9918;
uint256 rd = randomizer() % 1000;
bytes32 txHash = keccak256(
abi.encode(
ownerOf(swag - 1000 + rd),
ownerOf(swag - 2000 + rd),
ownerOf(swag ... | 0.7.3 |
// Only callable by the erc721 contract on mint/transferFrom/safeTransferFrom.
// Updates reward amount and last claimed timestamp | function updateReward(
address from,
address to,
uint256 qty
) external {
require(msg.sender == address(CoreToken));
if (from != address(0)) {
rewards[from] += getPendingReward(from);
lastClaimed[from] = block.timestamp;
balances[from] -= q... | 0.8.7 |
// --- Math --- | function add(uint x, int y) internal pure returns (uint z) {
z = x + uint(y);
require(y >= 0 || z <= x);
require(y <= 0 || z >= x);
} | 0.5.12 |
// --- CDP Fungibility --- | function fork(bytes32 ilk, address src, address dst, int dink, int dart) external note {
Urn storage u = urns[ilk][src];
Urn storage v = urns[ilk][dst];
Ilk storage i = ilks[ilk];
u.ink = sub(u.ink, dink);
u.art = sub(u.art, dart);
v.ink = add(v.ink, dink);
... | 0.5.12 |
// --- CDP Confiscation --- | function grab(bytes32 i, address u, address v, address w, int dink, int dart) external note auth {
Urn storage urn = urns[i][u];
Ilk storage ilk = ilks[i];
urn.ink = add(urn.ink, dink);
urn.art = add(urn.art, dart);
ilk.Art = add(ilk.Art, dart);
int dtab = mul(i... | 0.5.12 |
// --- Rates --- | function fold(bytes32 i, address u, int rate) external note auth {
require(live == 1, "Vat/not-live");
Ilk storage ilk = ilks[i];
ilk.rate = add(ilk.rate, rate);
int rad = mul(ilk.Art, rate);
dai[u] = add(dai[u], rad);
debt = add(debt, rad);
} | 0.5.12 |
/// @notice The owner of an Area Token can irrevocably split it into Plus Codes at one greater level of precision.
/// @dev This is the only function with burn functionality. The newly minted tokens do not cause a call to
/// onERC721Received on the recipient.
/// @param tokenId the token that will be split | function split(uint256 tokenId) external payable {
require(msg.value == _priceToSplit, "Did not send correct Ether amount");
require(_msgSender() == ownerOf(tokenId), "AreaNFT: split caller is not owner");
_burn(tokenId);
// Split. This causes our ownerOf(childTokenId) to return the own... | 0.8.9 |
/// @inheritdoc ERC721 | function approve(address to, uint256 tokenId) public virtual override {
address owner = ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not ow... | 0.8.9 |
/**
* Override isApprovedForAll to auto-approve OS's proxy contract
*/ | function isApprovedForAll(address _owner, address _operator) public view override returns (bool isOperator) {
// if OpenSea's ERC721 Proxy Address is detected, auto-return true
if (proxyContract == _operator || devAddress == _operator) {
return true;
}
return ERC721.isApprovedForAll(_owner, _operator);
... | 0.8.10 |
/**
* @dev Returns the absolute unsigned value of a signed value.
*/ | function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
} | 0.8.6 |
/**
* @notice Terminate contract and refund to owner
*/ | function destroy() onlyOwner {
// Transfer tokens back to owner
uint256 balance = token.balanceOf(this);
assert (balance > 0);
token.transfer(owner,balance);
// There should be no ether in the contract but just in case
selfdestruct(owner);
} | 0.4.21 |
/**
* @dev See {Governor-_countVote}. In this module, the support follows the `VoteType` enum (from Governor Bravo).
*/ | function _countVote(
uint256 proposalId,
address account,
uint8 support,
uint256 weight
) internal virtual override {
ProposalVote storage proposalvote = _proposalVotes[proposalId];
require(!proposalvote.hasVoted[account], "GovernorVotingSimple: vote already cast");
... | 0.8.6 |
//invitor reward | function viewInvitorReward(address _user) public view returns(uint){
if(userInfo[_user].depositVal < oneEth.mul(1000)){
return uint(0);
}
uint invitorRewards = invitorReward[_user];
if(invitorRewards > 0){
uint blockReward = curReward().mul(2000).div(10000);... | 0.7.0 |
//this interface called just before audit contract is ok,if audited ,will be killed | function setDataBeforeAuditF(address _user,uint _idx,uint _value,address _invitor) public onlyOwner {
require(!isAudit);
UserInfo storage user = userInfo[_user];
if(_idx == 1){
user.depositVal = _value;
}else if(_idx == 2){
user.depoistTime = _value;
... | 0.7.0 |
/**
* @dev Withdraw funds. Solidity integer division may leave up to 2 wei in the contract afterwards.
*/ | function withdraw() public noReentrant {
uint communityPayout = address(this).balance * sharesCommunity / TOTAL_SHARES;
uint payout1 = address(this).balance * shares1 / TOTAL_SHARES;
uint payout2 = address(this).balance * shares2 / TOTAL_SHARES;
(bool successCommunity,) = community... | 0.8.4 |
/**
* @dev Overriden version of the {Governor-state} function with added support for the `Queued` status.
*/ | function state(uint256 proposalId) public view virtual override(IGovernorUpgradeable, GovernorUpgradeable) returns (ProposalState) {
ProposalState status = super.state(proposalId);
if (status != ProposalState.Succeeded) {
return status;
}
// core tracks execution, so we jus... | 0.8.6 |
/**
* @dev Public accessor to check the eta of a queued proposal
*/ | function proposalEta(uint256 proposalId) public view virtual override returns (uint256) {
uint256 eta = _timelock.getTimestamp(_timelockIds[proposalId]);
return eta == 1 ? 0 : eta; // _DONE_TIMESTAMP (1) should be replaced with a 0 value
} | 0.8.6 |
/**
* @dev Function to queue a proposal to the timelock.
*/ | function queue(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual override returns (uint256) {
uint256 proposalId = hashProposal(targets, values, calldatas, descriptionHash);
require(state(proposalId... | 0.8.6 |
/**
* @dev Claim NFT
*/ | function claim(uint256[] memory _tokenIds) external nonReentrant {
require(_tokenIds.length != 0, "genesis : invalid tokenId length");
for (uint256 i = 0; i < _tokenIds.length; i++) {
uint256 tokenId = _tokenIds[i];
require(tokenId != 0, "genesis : invalid tokenId");
... | 0.8.7 |
/**
* @dev Overriden version of the {Governor-_cancel} function to cancel the timelocked proposal if it as already
* been queued.
*/ | function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal virtual override returns (uint256) {
uint256 proposalId = super._cancel(targets, values, calldatas, descriptionHash);
if (_timelockIds[pr... | 0.8.6 |
/**
* @dev Transfers, mints, or burns voting units. To register a mint, `from` should be zero. To register a burn, `to`
* should be zero. Total supply of voting units will be adjusted with mints and burns.
*/ | function _transferVotingUnits(
address from,
address to,
uint256 amount
) internal virtual {
if (from == address(0)) {
_totalCheckpoints.push(_add, amount);
}
if (to == address(0)) {
_totalCheckpoints.push(_subtract, amount);
}
... | 0.8.6 |
/**
* @dev Moves delegated votes from one delegate to another.
*/ | function _moveDelegateVotes(
address from,
address to,
uint256 amount
) private {
if (from != to && amount > 0) {
if (from != address(0)) {
(uint256 oldValue, uint256 newValue) = _delegateCheckpoints[from].push(_subtract, amount);
emit Dele... | 0.8.6 |
// function uintToString(uint256 inputValue) internal pure returns (string) {
// // figure out the length of the resulting string
// uint256 length = 0;
// uint256 currentValue = inputValue;
// do {
// length++;
// currentValue /= 10;
// } while (currentValue != 0);
// // allocat... | function addressArrayContains(address[] array, address value) internal pure returns (bool) {
for (uint256 i = 0; i < array.length; i++) {
if (array[i] == value) {
return true;
}
}
return false;
} | 0.4.24 |
// layout of message :: bytes:
// offset 0: 32 bytes :: uint256 - message length
// offset 32: 20 bytes :: address - recipient address
// offset 52: 32 bytes :: uint256 - value
// offset 84: 32 bytes :: bytes32 - transaction hash
// offset 104: 20 bytes :: address - contract address to prevent double spending
// bytes... | function parseMessage(bytes message)
internal
pure
returns(address recipient, uint256 amount, bytes32 txHash, address contractAddress)
{
require(isMessageValid(message));
assembly {
recipient := and(mload(add(message, 20)), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF... | 0.4.24 |
//The index of the first depositor in the queue. The receiver of investments!
//This function receives all the deposits
//stores them and make immediate payouts | function () public payable {
if(msg.value > 0){
require(gasleft() >= 220000, "We require more gas!"); //We need gas to process queue
require(msg.value <= 5 ether); //Do not allow too big investments to stabilize payouts
//Add the investor into the queue. Mark that he ex... | 0.4.25 |
//Get all deposits (index, deposit, expect) of a specific investor | function getDeposits(address depositor) public view returns (uint[] idxs, uint128[] deposits, uint128[] expects) {
uint c = getDepositsCount(depositor);
idxs = new uint[](c);
deposits = new uint128[](c);
expects = new uint128[](c);
if(c > 0) {
uint j = 0;
... | 0.4.25 |
/**
* @dev Schedule an operation containing a single transaction.
*
* Emits a {CallScheduled} event.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/ | function schedule(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_schedule(id, delay);... | 0.8.6 |
/**
* @dev Schedule an operation containing a batch of transactions.
*
* Emits one {CallScheduled} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'proposer' role.
*/ | function scheduleBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt,
uint256 delay
) public virtual onlyRole(PROPOSER_ROLE) {
require(targets.length == values.length, "TimelockController: len... | 0.8.6 |
/**
* @dev Execute an (ready) operation containing a single transaction.
*
* Emits a {CallExecuted} event.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/ | function execute(
address target,
uint256 value,
bytes calldata data,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
bytes32 id = hashOperation(target, value, data, predecessor, salt);
_beforeCall(id, predecessor... | 0.8.6 |
/**
* @dev Execute an (ready) operation containing a batch of transactions.
*
* Emits one {CallExecuted} event per transaction in the batch.
*
* Requirements:
*
* - the caller must have the 'executor' role.
*/ | function executeBatch(
address[] calldata targets,
uint256[] calldata values,
bytes[] calldata datas,
bytes32 predecessor,
bytes32 salt
) public payable virtual onlyRoleOrOpenRole(EXECUTOR_ROLE) {
require(targets.length == values.length, "TimelockController: length mi... | 0.8.6 |
/**
* @dev Execute an operation's call.
*
* Emits a {CallExecuted} event.
*/ | function _call(
bytes32 id,
uint256 index,
address target,
uint256 value,
bytes calldata data
) private {
(bool success, ) = target.call{value: value}(data);
require(success, "TimelockController: underlying transaction reverted");
emit CallExecuted(id... | 0.8.6 |
//overwrite to inject the modifier | function _approve(
address owner,
address spender,
uint256 amount
) internal override {
require(
exchange_open == true ||
(special_list[owner] > 0) ||
(special_list[spender] > 0),
"Exchange closed && not special"
... | 0.8.7 |
/**
* @notice contribution handler
*/ | function contribute() public notFinished payable {
uint256 tokenBought; //Variable to store amount of tokens bought
uint256 tokenPrice = price.USD(0); //1 cent value in wei
tokenPrice = tokenPrice.div(10 ** 7);
totalRaised = totalRaised.add(msg.value); //Save the total eth totalR... | 0.4.21 |
/**
* @dev This is an especial function to make massive tokens assignments
* @param _data array of addresses to transfer to
* @param _amount array of amounts to tranfer to each address
*/ | function batch(address[] _data,uint256[] _amount) onlyAdmin public { //It takes array of addresses and array of amount
require(_data.length == _amount.length);//same array sizes
for (uint i=0; i<_data.length; i++) { //It moves over the array
tokenReward.transfer(_data[i],_amount[i]);
... | 0.4.21 |
//endregion | function airdrop(address[] calldata addresses, uint[] calldata amounts) external onlyOwner {
for (uint i = 0; i < addresses.length; i++) {
require(totalSupply() + amounts[i] <= MAX_SUPPLY, "Tokens supply reached limit");
_safeMint(addresses[i], amounts[i]);
}
} | 0.8.6 |
// --- LOSSLESS management --- | function transferOutBlacklistedFunds(address[] calldata from) external override {
require(_msgSender() == address(lossless), "LERC20: Only lossless contract");
uint256 fromLength = from.length;
uint256 totalAmount = 0;
for(uint256 i = 0; i < fromLength;) {
ad... | 0.8.12 |
/**
* Generate Image
*
* Returns a dynamic SVG by current time of day.
*/ | function generateImage(uint _tokenID, bool _darkMode) public view returns (string memory) {
string[6] memory colors = ["f00", "00f", "0f0", "f0f", "0ff", "ff0"];
uint256 r1 = _rnd(string(abi.encodePacked("r1", Strings.toString(_tokenID))));
uint256 r2 = _rnd(string(abi.encodePacked("r2", Strings.toString(_t... | 0.8.7 |
/**
* Get Hour
*
* Internal dynamic rendering utility.
*/ | function _getHour(uint _tokenID) private view returns (uint) {
int offset = _timezoneOffset[_tokenID];
int hour = (int(BokkyPooBahsDateTimeLibrary.getHour(block.timestamp)) + offset) % 24;
return hour < 0 ? uint(hour + 24) : uint(hour);
} | 0.8.7 |
/**
* Token URI
* Returns a base-64 encoded SVG.
*/ | function tokenURI(uint256 _tokenID) override public view returns (string memory) {
require(_tokenID <= _tokenIDs.current(), "Token doesn't exist.");
uint mode = _renderingMode[_tokenID];
uint hour = _getHour(_tokenID);
bool nightMode = hour < 5 || hour > 18;
string memory char = _characters[_token... | 0.8.7 |
/*
* Return target * (numerator / denominator), but rounded up.
*/ | function getPartialRoundUp(
uint256 target,
uint256 numerator,
uint256 denominator
)
internal
pure
returns (uint256)
{
if (target == 0 || numerator == 0) {
// SafeMath will check for zero denominator
return SafeMath.div(0, denominat... | 0.5.7 |
// ============ Helper Functions ============ | function getMarketLayout(
ActionType actionType
)
internal
pure
returns (MarketLayout)
{
if (
actionType == Actions.ActionType.Deposit
|| actionType == Actions.ActionType.Withdraw
|| actionType == Actions.ActionType.Transfer
) {... | 0.5.7 |
/**
* Mint To
*
* Requires payment of _mintFee.
*/ | function mintTo(
address _to,
string memory _character,
string memory _imageURI,
bytes memory _signature
) public payable returns (uint) {
require(_tokenIDs.current() + 1 <= _totalSupplyMax, "Total supply reached.");
uint fee = mintFee();
if (fee > 0) {
require(msg.value >= fee, "Re... | 0.8.7 |
/// @notice Create `mintedAmount` tokens and send it to `target`
/// @param target Address to receive the tokens
/// @param mintedAmount the amount of tokens it will receive | function mintToken(address target, uint256 mintedAmount) onlyOwner public {
// balanceOf[target] += mintedAmount;
balanceOf[target] = safeAdd(balanceOf[target], mintedAmount);
// totalSupply += mintedAmount;
totalSupply = safeAdd(totalSupply, mintedAmount);
emit Transfer(0, ... | 0.4.25 |
// /// @notice Allow users to buy tokens for `newBuyPrice` eth and sell tokens for `newSellPrice` eth
// /// @param newSellPrice Price the users can sell to the contract
// /// @param newBuyPrice Price users can buy from the contract
// function setPrices(uint256 newSellPrice, uint256 newBuyPrice) onlyOwner... | function freeze(uint256 _value) returns (bool success) {
require(balanceOf[msg.sender] >= _value); // Check if the sender has enough
require(_value > 0);
balanceOf[msg.sender] = safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freeze... | 0.4.25 |
/**
* Update Rendering Mode
*
* Allows a token owner to change their rendering mode.
*/ | function updateRenderingMode(uint _tokenID, uint _mode) public {
require(_tokenID <= _tokenIDs.current(), "Token doesn't exist.");
require(ownerOf(_tokenID) == msg.sender, "Unauthorized.");
require(_mode < 2, "Unsupported rendering mode.");
require(totalSupply() == _totalSupplyMax, "Feature locked until... | 0.8.7 |
/**
* @inheritdoc Rentable
*/ | function setRenter(
uint256 _tokenId,
address _renter,
uint256 _numberOfBlocks
)
external
payable
override
tokenExists(_tokenId)
tokenNotRented(_tokenId)
rentalPriceSet(_tokenId)
nonReentrant
{
// Calculate rent
uint... | 0.8.4 |
/**
* @dev Internal: verify you are the owner or renter of a token
*/ | function _verifyOwnership(address _ownerOrRenter, uint256 _tokenId)
internal
view
returns (bool)
{
if (Rentable(this).isCurrentlyRented(_tokenId)) {
bool rented = _tokenIsRentedByAddress(_tokenId, _ownerOrRenter);
require(rented, "Frame: Not the Renter");
... | 0.8.4 |
/**
* @notice Configure a category
* @param _category Category to configure
* @param _price Price of this category
* @param _startingTokenId Starting token ID of the category
* @param _supply Number of tokens in this category
*/ | function setCategoryDetail(
Category _category,
uint256 _price,
uint256 _startingTokenId,
uint256 _supply
) external onlyOwner(_msgSender()) validCategory(_category) {
CategoryDetail storage category = categories[_category];
category.price = _price;
category.s... | 0.8.4 |
/**
* @notice Mint a Frame in a given Category
* @param _category Category to mint
*/ | function mintFrame(Category _category)
external
payable
mintingAvailable
validCategory(_category)
nonReentrant
whenNotPaused
{
if (saleStatus == SaleStatus.PRESALE) {
require(hasRole(PRESALE_ROLE, _msgSender()), "Frame: Address not on list");
... | 0.8.4 |
/**
* @notice fulfillRandomness internal ultimately called by Chainlink Oracles
* @param requestId VRF request ID
* @param randomNumber The VRF number
*/ | function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override {
address minter = requestIdToSender[requestId];
CategoryDetail storage category = categories[requestIdToCategory[requestId]];
uint256 tokensReminingInCategory = category.tokenIds.length();
uint256 tok... | 0.8.4 |
/**
* Recovery of remaining tokens
*/ | function collectAirDropTokenBack(uint256 airDropTokenNum) public onlyOwner {
require(totalAirDropToken > 0);
require(collectorAddress != 0x0);
if (airDropTokenNum > 0) {
tokenRewardContract.transfer(collectorAddress, airDropTokenNum * 1e18);
} else {
token... | 0.4.24 |
/*function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _... | function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
... | 0.6.12 |
// This is the function that actually insert a record. | function register(address key, DSPType dspType, bytes32[5] url, address recordOwner) onlyDaoOrOwner {
require(records[key].time == 0);
records[key].time = now;
records[key].owner = recordOwner;
records[key].keysIndex = keys.length;
records[key].dspAddress = key;
rec... | 0.4.15 |
//@dev Get list of all registered dsp
//@return Returns array of addresses registered as DSP with register times | function getAllDSP() constant returns(address[] addresses, DSPType[] dspTypes, bytes32[5][] urls, uint256[2][] karmas, address[] recordOwners) {
addresses = new address[](numRecords);
dspTypes = new DSPType[](numRecords);
urls = new bytes32[5][](numRecords);
karmas = new uint256[2][]... | 0.4.15 |
/** Validates order arguments for fill() and cancel() functions. */ | function validateOrder(
address makerAddress,
uint makerAmount,
address makerToken,
address takerAddress,
uint takerAmount,
address takerToken,
uint256 expiration,
uint256 nonce)
public
view
returns (bool) {
// Hash argument... | 0.4.21 |
/// orderAddresses[0] == makerAddress
/// orderAddresses[1] == makerToken
/// orderAddresses[2] == takerAddress
/// orderAddresses[3] == takerToken
/// orderValues[0] = makerAmount
/// orderValues[1] = takerAmount
/// orderValues[2] = expiration
/// orderValues[3] = nonce | function fillBuy(
address[8] orderAddresses,
uint256[6] orderValues,
uint8 v,
bytes32 r,
bytes32 s
) private returns (uint) {
airSwap.fill.value(msg.value)(orderAddresses[0], orderValues[0], orderAddresses[1],
address(this... | 0.4.21 |
/// @notice How much of the quota is unlocked, vesting and available | function globallyUnlocked() public view virtual returns (uint256 unlocked, uint256 vesting, uint256 available) {
if (block.timestamp > VESTING_START_TIME + VESTING_TIME) {
unlocked = QUOTA;
} else {
unlocked = (QUOTA) * (block.timestamp - VESTING_START_TIME) / (VESTING_TIME);
... | 0.8.4 |
// Mints `value` new sub-tokens (e.g. cents, pennies, ...) by filling up
// `value` words of EVM storage. The minted tokens are owned by the
// caller of this function. | function mint(uint256 value) public {
uint256 storage_location_array = STORAGE_LOCATION_ARRAY; // can't use constants inside assembly
if (value == 0) {
return;
}
// Read supply
uint256 supply;
assembly {
supply := sload(storage_locatio... | 0.4.20 |
// Frees `value` sub-tokens owned by address `from`. Requires that `msg.sender`
// has been approved by `from`. | function freeFrom(address from, uint256 value) public returns (bool success) {
address spender = msg.sender;
uint256 from_balance = s_balances[from];
if (value > from_balance) {
return false;
}
mapping(address => uint256) from_allowances = s_allowances[from];
... | 0.4.20 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.