comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
/**
* Slightly more gas efficient than balanceOf for merely returning ownership status.
*/ | function isFinnsOwner(address owner) public view virtual returns (bool) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
uint256 qty = _owners.length;
// Cannot realistically overflow, since we are using uint256
unchecked {
for (uint256 i = 0; i < qty; i... | 0.8.12 |
/**
* Returns array of tokens only from the last mint in descending order. Transfers
* will affect this, it's only useful right after minting.
* It is not recommended to call this function from another smart contract
* as it can become quite expensive -- call this function off chain instead.
*/ | function latestMinted(address owner) public view virtual returns (uint256[] memory) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
if (totalSupply() == 0) {
return new uint256[](0);
}
uint256 count;
uint256 start;
bool start... | 0.8.12 |
// Mint function for marketing reserve | function reserveMintMarketing(address _to, uint256 _reserveAmount) public contractOwner {
require(_reserveAmount > 0 && _reserveAmount <= marketingReserve, "Exceeds reserve remaining");
require(totalSupply() + _reserveAmount < HOF_MAX, "Exceeds supply");
marketingReserve -= _reserv... | 0.8.12 |
// Mint function for marketing reserve to multiple addresses | function reserveMintMarketingMass(address[] memory _to, uint256[] memory _reserveAmount) public contractOwner {
require(_to.length == _reserveAmount.length, "To and amount length mismatch");
require(_to.length > 0, "No tos");
uint256 totalReserve = 0;
for (uint256 i = 0; i < _to.l... | 0.8.12 |
//Mint for the hof minting drop | function mintFinns(uint256 numberOfTokens) public payable nonReentrant {
require(saleIsActive, "Sale Inactive");
require(numberOfTokens > 0 && numberOfTokens <= maxHofPurchase, "Exceeds transaction max");
require(totalSupply() + numberOfTokens < _mintLimit(), "Exceeds max supply");
r... | 0.8.12 |
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
* Dont call this function on chain from another smart contract, since it can become quite expensive
*/ | function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual returns (uint256 tokenId) {
if (index >= balanceOf(owner)) revert OwnerIndexOutOfBounds();
uint256 count;
uint256 qty = _owners.length;
// Cannot realistically overflow, since we are using uint256
unc... | 0.8.12 |
/**
* @dev Iterates through _owners array, returns balance of address
* It is not recommended to call this function from another smart contract
* as it can become quite expensive -- call this function off chain instead.
*/ | function balanceOf(address owner) public view virtual returns (uint256) {
if (owner == address(0)) revert BalanceQueryForZeroAddress();
uint256 count;
uint256 qty = _owners.length;
// Cannot realistically overflow, since we are using uint256
unchecked {
for (uint256 ... | 0.8.12 |
//Decompression demo program https://github.com/pixeluniverselab/sprite_decompression | function tokenURI(uint256 tokenId) public view override returns (string memory){
string memory compressedImage = Base64.encode(getSpriteImage(tokenId));
spriteAttribute memory spa = getSpriteAttribute(tokenId);
spriteBody memory spb = getSpriteBody(tokenId);
string memory spriteaAttar = string(abi.en... | 0.8.7 |
// Set up the tokenbankroll stuff | function setupBankrollInterface(address ZethrMainBankrollAddress) internal {
// Instantiate Zethr
Zethr = ZethrInterface(0xb9ab8eed48852de901c13543042204c6c569b811);
// Get the bankroll addresses from the main bankroll
UsedBankrollAddresses = ZethrMainBankroll(ZethrMainBankrollAddres... | 0.4.25 |
// Token fallback to bet or deposit from bankroll | function execute(address _from, uint _value, uint userDivRate, bytes _data) public fromBankroll gameIsActive returns (bool) {
TKN memory _tkn;
_tkn.sender = _from;
_tkn.value = _value;
uint8 chosenNumber = uint8(_data[0]);
_playerRollDice(chosenNumber, _tkn, userDivRate);
retur... | 0.4.25 |
// Only owner adjust contract balance variable (only used for max profit calc) | function updateContractBalance(uint newContractBalance) public
onlyOwner
{
contractBalance[2] = newContractBalance;
setMaxProfit(2);
contractBalance[5] = newContractBalance;
setMaxProfit(5);
contractBalance[10] = newContractBalance;
setMaxProfit(10);
contractBalance[15] = newCon... | 0.4.25 |
// Only owner address can set maxProfitAsPercentOfHouse | function ownerSetMaxProfitAsPercentOfHouse(uint newMaxProfitAsPercent) public
onlyOwner
{
// Restricts each bet to a maximum profit of 20% contractBalance
require(newMaxProfitAsPercent <= 200000);
maxProfitAsPercentOfHouse = newMaxProfitAsPercent;
setMaxProfit(2);
setMaxProfit(5);
se... | 0.4.25 |
/**
* @dev Claims DAO tokens.
*/ | function claimTokens() public {
require(!close, "DAOToken Close!");
require(!claimed[msg.sender], "DAOToken: Tokens already claimed.");
claimed[msg.sender] = true;
uint256 amount = ticketBooth.balanceOf(msg.sender, AssangeDAOProjectId);
require(amount > 0, "You do not donate Assa... | 0.8.2 |
// -----------------------------
// Loopring Broker Delegate | function brokerRequestAllowance(BrokerData.BrokerApprovalRequest memory request) public returns (bool) {
require(msg.sender == loopringDelegate);
BrokerData.BrokerOrder[] memory mergedOrders = new BrokerData.BrokerOrder[](request.orders.length);
uint numMergedOrders = 1;
mergedOr... | 0.5.13 |
// -----------------------------
// Versionable | function versionBeginUsage(
address owner,
address payable depositAddress,
address oldVersion,
bytes calldata additionalData
) external {
// Approve the DolomiteMarginProtocol as an operator for the deposit contract's dYdX account
IDepositContract(depositAddres... | 0.5.13 |
// TODO: test me | function mintDai(
// User params
uint256 _dart,
bytes calldata _btcAddr,
uint256 _minWbtcAmount,
// Darknode params
uint256 _amount, // Amount of renBTC.
bytes32 _nHash, // Nonce hash.
bytes calldata _sig // Minting signatu... | 0.5.12 |
/**
* adds Galleons and Pirates to the Fleet and Sea
* @param account the address of the staker
* @param tokenIds the IDs of the Galleons and Pirates to stake
*/ | function addManyToFleet(address account, uint16[] calldata tokenIds) external override
nonReentrant
onlyEOA
{
require(account == tx.origin, "account to sender mismatch");
for (uint i = 0; i < tokenIds.length; i++) {
if (_msgSender() != address(pirateGame)) { // do... | 0.8.10 |
/**
* adds a single Pirate to the Sea
* @param account the address of the staker
* @param tokenId the ID of the Pirate to add to the Sea
*/ | function _addPirateToSea(address account, uint256 tokenId) internal {
uint8 rank = _rankForPirate(tokenId);
totalRankStaked += rank; // Portion of earnings ranges from 8 to 5
seaIndices[tokenId] = sea[rank].length; // Store the location of the pirate in the Sea
sea[rank].push(Stake({... | 0.8.10 |
/**
* realize $CACAO earnings and optionally unstake tokens from the Fleet / Sea
* to unstake a Galleon it will require it has 2 days worth of $CACAO unclaimed
* @param tokenIds the IDs of the tokens to claim earnings from
* @param unstake whether or not to unstake ALL of the tokens listed in tokenIds
*/ | function claimManyFromFleetAndSea(uint16[] calldata tokenIds, bool unstake) external
whenNotPaused
_updateEarnings
nonReentrant
onlyEOA
{
uint256 owed = 0;
for (uint i = 0; i < tokenIds.length; i++) {
if (nftContract.isGalleon(tokenIds[i])) {
... | 0.8.10 |
/**
* realize $CACAO earnings for a single Pirate and optionally unstake it
* Pirates earn $CACAO proportional to their rank
* @param tokenId the ID of the Pirate to claim earnings from
* @param unstake whether or not to unstake the Pirate
* @return owed - the amount of $CACAO earned
*/ | function _claimPirateFromSea(uint256 tokenId, bool unstake) internal returns (uint256 owed) {
require(nftContract.ownerOf(tokenId) == address(this), "Doesn't own token");
uint8 rank = _rankForPirate(tokenId);
Stake memory stake = sea[rank][seaIndices[tokenId]];
require(stake.owner ==... | 0.8.10 |
/**
* add $CACAO to claimable pot for the Sea
* @param amount $CACAO to add to the pot
*/ | function _payPirateTax(uint256 amount) internal {
if (totalRankStaked == 0) { // if there's no staked pirates
unaccountedRewards += amount; // keep track of $CACAO due to pirates
return;
}
// makes sure to include any unaccounted $CACAO
cacaoPerRank += (amo... | 0.8.10 |
/**
* chooses a random Pirate thief when a newly minted token is stolen
* @param seed a random value to choose a Pirate from
* @return the owner of the randomly selected Pirate thief
*/ | function randomPirateOwner(uint256 seed) external view override returns (address) {
if (totalRankStaked == 0) {
return address(0x0);
}
uint256 bucket = (seed & 0xFFFFFFFF) % totalRankStaked; // choose a value from 0 to total rank staked
uint256 cumulative;
seed ... | 0.8.10 |
/**
* @notice Sets `amount` as the allowance of `spender` over the `owner` s tokens.
* @param owner The address of the caller.
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved
* @dev This internal function is equivalent to `approve`, and c... | function _approve(
address owner,
address spender,
uint96 amount
) internal virtual {
require(
owner != address(0),
"Ctx::_approve: approve from the zero address"
);
require(
spender != address(0),
"Ctx::_approve: approve to the zero address"
);
allowances[owne... | 0.7.5 |
/**
* @notice Atomically increases the allowance granted to `spender` by the caller.
* @param spender address
* @param addedValue uint256 raw
* @dev This is an alternative to {approve} that can be used as a mitigation for
* problems of Allowance Double-Spend Exploit.
* @dev Emits Approval event indicating the upd... | function increaseAllowance(address spender, uint256 addedValue)
public
virtual
returns (bool)
{
uint96 amount;
if (addedValue == uint256(-1)) {
amount = uint96(-1);
} else {
amount = safe96(
addedValue,
"Ctx::increaseAllowance: amount exceeds 96 bits"
);
}... | 0.7.5 |
/// @notice Update fees of the positions
/// @return baseLiquidity Fee of base position
/// @return limitLiquidity Fee of limit position | function zeroBurn() internal returns(uint128 baseLiquidity, uint128 limitLiquidity) {
/// update fees for inclusion
(baseLiquidity, , ) = _position(baseLower, baseUpper);
if (baseLiquidity > 0) {
pool.burn(baseLower, baseUpper, 0);
}
(limitLiquidity, , ) = _position(limitLower, l... | 0.7.6 |
/// @notice Pull liquidity tokens from liquidity and receive the tokens
/// @param shares Number of liquidity tokens to pull from liquidity
/// @return base0 amount of token0 received from base position
/// @return base1 amount of token1 received from base position
/// @return limit0 amount of token0 received from limi... | function pullLiquidity(
uint256 shares
) external onlyOwner returns(
uint256 base0,
uint256 base1,
uint256 limit0,
uint256 limit1
) {
zeroBurn();
(base0, base1) = _burnLiquidity(
baseLower,
baseUpper,
_liquidityForShares... | 0.7.6 |
/// @param shares Number of liquidity tokens to redeem as pool assets
/// @param to Address to which redeemed pool assets are sent
/// @param from Address from which liquidity tokens are sent
/// @return amount0 Amount of token0 redeemed by the submitted liquidity tokens
/// @return amount1 Amount of token1 redeemed by... | function withdraw(
uint256 shares,
address to,
address from
) nonReentrant external override returns (uint256 amount0, uint256 amount1) {
require(shares > 0, "shares");
require(to != address(0), "to");
/// update fees
zeroBurn();
/// Withdraw liquidi... | 0.7.6 |
/// @notice Compound pending fees
/// @return baseToken0Owed Pending fees of base token0
/// @return baseToken1Owed Pending fees of base token1
/// @return limitToken0Owed Pending fees of limit token0
/// @return limitToken1Owed Pending fees of limit token1 | function compound() external onlyOwner returns (
uint128 baseToken0Owed,
uint128 baseToken1Owed,
uint128 limitToken0Owed,
uint128 limitToken1Owed
) {
// update fees for compounding
zeroBurn();
(, baseToken0Owed,baseToken1Owed) = _position(baseLower, baseUpper);
(, lim... | 0.7.6 |
/// @notice Add tokens to base liquidity
/// @param amount0 Amount of token0 to add
/// @param amount1 Amount of token1 to add | function addBaseLiquidity(uint256 amount0, uint256 amount1) external onlyOwner {
uint128 baseLiquidity = _liquidityForAmounts(
baseLower,
baseUpper,
amount0 == 0 && amount1 == 0 ? token0.balanceOf(address(this)) : amount0,
amount0 == 0 && amount1 == 0 ? token1.bal... | 0.7.6 |
/// @notice Adds the liquidity for the given position
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param liquidity The amount of liquidity to mint
/// @param payer Payer Data
/// @return amount0 The amoun... | function _mintLiquidity(
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
address payer
) internal returns (uint256 amount0, uint256 amount1) {
if (liquidity > 0) {
(amount0, amount1) = pool.mint(
address(this),
tickLower,
... | 0.7.6 |
/// @notice Burn liquidity from the sender and collect tokens owed for the liquidity
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param liquidity The amount of liquidity to burn
/// @param to The addr... | function _burnLiquidity(
int24 tickLower,
int24 tickUpper,
uint128 liquidity,
address to,
bool collectAll
) internal returns (uint256 amount0, uint256 amount1) {
if (liquidity > 0) {
/// Burn liquidity
(uint256 owed0, uint256 owed1) = pool.burn... | 0.7.6 |
/// @notice Get the info of the given position
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @return liquidity The amount of liquidity of the position
/// @return tokensOwed0 Amount of token0 owed
/// @return tokensOwed1 Amount of token1 owed | function _position(int24 tickLower, int24 tickUpper)
internal
view
returns (
uint128 liquidity,
uint128 tokensOwed0,
uint128 tokensOwed1
)
{
bytes32 positionKey = keccak256(abi.encodePacked(address(this), tickLower, tickUpper));
(li... | 0.7.6 |
/// @notice Callback function of uniswapV3Pool mint | function uniswapV3MintCallback(
uint256 amount0,
uint256 amount1,
bytes calldata data
) external override {
require(msg.sender == address(pool));
address payer = abi.decode(data, (address));
if (payer == address(this)) {
if (amount0 > 0) token0.safeTransf... | 0.7.6 |
/// @notice Callback function of uniswapV3Pool swap | function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external override {
require(msg.sender == address(pool));
address payer = abi.decode(data, (address));
if (amount0Delta > 0) {
if (payer == address(this)) {
... | 0.7.6 |
/// @return total0 Quantity of token0 in both positions and unused in the Hypervisor
/// @return total1 Quantity of token1 in both positions and unused in the Hypervisor | function getTotalAmounts() public view override returns (uint256 total0, uint256 total1) {
(, uint256 base0, uint256 base1) = getBasePosition();
(, uint256 limit0, uint256 limit1) = getLimitPosition();
total0 = token0.balanceOf(address(this)).add(base0).add(limit0);
total1 = token1.balan... | 0.7.6 |
/// @return liquidity Amount of total liquidity in the base position
/// @return amount0 Estimated amount of token0 that could be collected by
/// burning the base position
/// @return amount1 Estimated amount of token1 that could be collected by
/// burning the base position | function getBasePosition()
public
view
returns (
uint128 liquidity,
uint256 amount0,
uint256 amount1
)
{
(uint128 positionLiquidity, uint128 tokensOwed0, uint128 tokensOwed1) = _position(
baseLower,
baseUpper
... | 0.7.6 |
/// @notice Get the amounts of the given numbers of liquidity tokens
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param liquidity The amount of liquidity tokens
/// @return Amount of token0 and token1 | function _amountsForLiquidity(
int24 tickLower,
int24 tickUpper,
uint128 liquidity
) internal view returns (uint256, uint256) {
(uint160 sqrtRatioX96, , , , , , ) = pool.slot0();
return
LiquidityAmounts.getAmountsForLiquidity(
sqrtRatioX96,
... | 0.7.6 |
// @return true if the transaction can buy tokens
// check for valid time period, min amount and within cap | function validPurchase() internal constant returns (bool) {
bool withinPeriod = startDate <= now && endDate >= now;
bool nonZeroPurchase = msg.value != 0;
bool minAmount = msg.value >= minimumParticipationAmount;
bool withinCap = weiRaised.add(msg.value) <= cap;
return withinPeriod && nonZero... | 0.4.20 |
// safety value to return ownership (anyone can invoke) | function returnOwnership(address forContract) public {
bytes memory payload = abi.encodeWithSignature("nominateNewOwner(address)", owner);
// solhint-disable avoid-low-level-calls
(bool success, ) = forContract.call(payload);
if (!success) {
// then try legacy way
... | 0.5.16 |
/**
* @notice return the full vesting schedule entries vest for a given user.
* @dev For DApps to display the vesting schedule for the
* inflationary supply over 5 years. Solidity cant return variable length arrays
* so this is returning pairs of data. Vesting Time at [0] and quantity at [1] and so on
*/ | function checkAccountSchedule(address account) public view returns (uint[520] memory) {
uint[520] memory _result;
uint schedules = _numVestingEntries(account);
for (uint i = 0; i < schedules; i++) {
uint[2] memory pair = getVestingScheduleEntry(account, i);
_result[i... | 0.5.16 |
/**
* @notice Send the fees to claiming address.
* @param account The address to send the fees to.
* @param sUSDAmount The amount of fees priced in sUSD.
*/ | function _payFees(address account, uint sUSDAmount) internal notFeeAddress(account) {
// Grab the sUSD Synth
ISynth sUSDSynth = issuer().synths(sUSD);
// NOTE: we do not control the FEE_ADDRESS so it is not possible to do an
// ERC20.approve() transaction to allow this feePool to c... | 0.5.16 |
/**
* @notice The total fees available in the system to be withdrawnn in sUSD
*/ | function totalFeesAvailable() external view returns (uint) {
uint totalFees = 0;
// Fees in fee period [0] are not yet available for withdrawal
for (uint i = 1; i < FEE_PERIOD_LENGTH; i++) {
totalFees = totalFees.add(_recentFeePeriodsStorage(i).feesToDistribute);
t... | 0.5.16 |
/**
* @notice The fees available to be withdrawn by a specific account, priced in sUSD
* @dev Returns two amounts, one for fees and one for SNX rewards
*/ | function feesAvailable(address account) public view returns (uint, uint) {
// Add up the fees
uint[2][FEE_PERIOD_LENGTH] memory userFees = feesByPeriod(account);
uint totalFees = 0;
uint totalRewards = 0;
// Fees & Rewards in fee period [0] are not yet available for with... | 0.5.16 |
/**
* @dev Sets the initial {converter} and {vest} contract addresses. Additionally, mints
* the Vader amount available for conversion as well as the team allocation that is meant
* to be vested to each respective contract.
*
* Emits a {ProtocolInitialized} event indicating all the supplied values of the func... | function setComponents(
IConverter _converter,
ILinearVesting _vest,
address[] calldata vesters,
uint192[] calldata amounts
) external onlyOwner {
require(
_converter != IConverter(_ZERO_ADDRESS) &&
_vest != ILinearVesting(_ZERO_ADDRESS),
... | 0.8.9 |
//pay in - just send ETH to contract address | receive() external payable {
require(!collectEnd, "Collect ended");
uint256 amount = msg.value + balances[msg.sender];
//if you want pay in more than 9 ETH - contact staff to KYC/AML
//and pay directly to owner address
//not KYC/AML-ed payments will be treated as a donation
... | 0.8.1 |
//end collecting - take ETH or fail and allow to withdraw | function end() external {
require(!collectEnd, "Collect ended");
collectEnd = true;
require(msg.sender == owner, "Only for owner");
if (totalCollected() < minETH) {
failed = true;
} else {
send(owner, address(this).balance);
}
} | 0.8.1 |
/** Sets the status of a given DAO. */ | function setDAOStatus(address daoAddress, uint256 index, uint256 status) external {
// Reentrancy guard.
require(_status == RE_NOT_ENTERED || _status == RE_FROZEN);
require(msg.sender == _manager, "Not manager");
// Validate the index as well.
require(_daoAddresses[index] ... | 0.6.12 |
/** Upgrades to the new DAO version. Can only be done when frozen. */ | function upgradeDAO(address daoAddress) external {
// Reentrancy guard.
require(_status == RE_FROZEN);
_status = RE_ENTERED;
// It must be a contract.
uint256 codeSize;
assembly { codeSize := extcodesize(daoAddress) }
require(codeSize > 0, "Not a contract... | 0.6.12 |
/** Returns the address of the DAO which deployed the Goald. */ | function getGoaldDAO(uint256 id) external view returns (address) {
require(id < _goaldCount, "ID too large");
uint256 addressesCount = _daoAddresses.length;
uint256 index;
uint256 goaldCount;
address goaldAddress;
for (; index < addressesCount; index ++) {
... | 0.6.12 |
/** Releases management to the DAO. */ | function initializeDAO() external {
// Reentrancy guard.
require(_status == RE_NOT_ENTERED);
_status = RE_ENTERED;
require(msg.sender == _manager, "Not manager");
require(_governanceStage == STAGE_ISSUANCE_CLAIMED, "Issuance unclaimed");
// B... | 0.6.12 |
/**
* Executes a function on the DAO. Only the manager can call this function. This DOES NOT guard against reentrancy. Do not use
* this unless reentrancy is needed or the call is made to an invlaid contract. Otherwise use `safeCallDAO()`. This code is
* duplicated in place of having an internal `_callDAO()` sinc... | function unsafeCallDAO(address daoAddress, bytes calldata encodedData) external returns (bytes memory) {
// Reentrancy guard. We check against both normal reentrancy and DAO call reentrancy.
require(_daoStatus == RE_NOT_ENTERED);
_daoStatus = RE_ENTERED;
require(msg.sender == _mana... | 0.6.12 |
/** This is overridden so we can update the reward balancees prior to the transfer completing. */ | function transfer(address recipient, uint256 amount) public override returns (bool) {
// Reentrancy guard.
require(_status == RE_NOT_ENTERED);
_status = RE_ENTERED;
// Preserve the original balances so we know if we need to change `_rewardHolders`. We need to call `pre()` and `post... | 0.6.12 |
/// @notice Create a token without setting uri
/// @dev It emits `NewAdapter` if `_erc20` is true
/// @param _supply The amount of token to create
/// @param _receiver Address that receives minted token
/// @param _settingOperator Address that can perform setTimeInterval
/// and set ERC20 Attribute
/// @param _needTim... | function createToken(
uint256 _supply,
address _receiver,
address _settingOperator,
bool _needTime,
bool _erc20
)
public
override
returns (uint256)
{
uint256 tokenId = _mint(_supply, _receiver, _settingOperator, _needTime, "");
if ... | 0.8.1 |
/// @notice Create a token with uri
/// @param _supply The amount of token to create
/// @param _receiver Address that receives minted token
/// @param _settingOperator Address that can perform setTimeInterval
/// and set ERC20 Attribute
/// @param _needTime Set to `true` if need to query holding time for token
/// @p... | function createToken(
uint256 _supply,
address _receiver,
address _settingOperator,
bool _needTime,
string calldata _uri,
bool _erc20
)
external
override
returns (uint256)
{
uint256 tokenId = createToken(_supply, _receiver, _setting... | 0.8.1 |
/// @notice Create both normal token and recording token without setting uri
/// @dev Recording token shares the same token ID with normal token
/// @param _supply The amount of token to create
/// @param _supplyOfRecording The amount of recording token to create
/// @param _receiver Address that receives minted token
... | function createTokenWithRecording(
uint256 _supply,
uint256 _supplyOfRecording,
address _receiver,
address _settingOperator,
bool _needTime,
address _recordingOperator,
bool _erc20
)
public
override
returns (uint256)
{
uint2... | 0.8.1 |
/// @notice Set starting time and ending time for token holding time calculation
/// @dev Starting time must be greater than time at the moment
/// @dev To save gas cost, here use uint128 to store time
/// @param _startTime Starting time in unix time format
/// @param _endTime Ending time in unix time format | function setTimeInterval(
uint256 _tokenId,
uint128 _startTime,
uint128 _endTime
)
external
override
{
require(_msgSender() == _settingOperators[_tokenId], "Not authorized");
require(_startTime >= block.timestamp, "Time smaller than now");
require(... | 0.8.1 |
/// @notice Set erc20 token attribute
/// @dev Throws if `msg.sender` is not authorized setting operator
/// @param _tokenId Corresponding token ID with erc20 adapter
/// @param _name Name of the token
/// @param _symbol Symbol of the token
/// @param _decimals Number of decimals to use | function setERC20Attribute(
uint256 _tokenId,
string memory _name,
string memory _symbol,
uint8 _decimals
)
external
override
{
require(_msgSender() == _settingOperators[_tokenId], "Not authorized");
require(_adapters[_tokenId] != address(0), "No a... | 0.8.1 |
/**
@dev upgrade an old converter to the latest version
will throw if ownership wasn't transferred to the upgrader before calling this function.
ownership of the new converter will be transferred back to the original owner.
fires the ConverterUpgrade event upon success.
@param _oldConverter old converter... | function upgrade(IBancorConverterExtended _oldConverter, bytes32 _version) public {
bool formerVersions = false;
if (_version == "0.4")
formerVersions = true;
acceptConverterOwnership(_oldConverter);
IBancorConverterExtended newConverter = createConverter(_oldConverter);... | 0.4.21 |
/**
@dev creates a new converter with same basic data as the original old converter
the newly created converter will have no connectors at this step.
@param _oldConverter old converter contract address
@return the new converter new converter contract address
*/ | function createConverter(IBancorConverterExtended _oldConverter) private returns(IBancorConverterExtended) {
IWhitelist whitelist;
ISmartToken token = _oldConverter.token();
uint32 maxConversionFee = _oldConverter.maxConversionFee();
address converterAdderess = bancorConverterFact... | 0.4.21 |
/**
@dev copies the connectors from the old converter to the new one.
note that this will not work for an unlimited number of connectors due to block gas limit constraints.
@param _oldConverter old converter contract address
@param _newConverter new converter contract address
@param _isLegacyVersion ... | function copyConnectors(IBancorConverterExtended _oldConverter, IBancorConverterExtended _newConverter, bool _isLegacyVersion)
private
{
uint256 virtualBalance;
uint32 weight;
bool isVirtualBalanceEnabled;
bool isPurchaseEnabled;
bool isSet;
uint16 con... | 0.4.21 |
/**
@dev copies the quick buy path from the old converter to the new one
@param _oldConverter old converter contract address
@param _newConverter new converter contract address
*/ | function copyQuickBuyPath(IBancorConverterExtended _oldConverter, IBancorConverterExtended _newConverter) private {
uint256 quickBuyPathLength = _oldConverter.getQuickBuyPathLength();
if (quickBuyPathLength <= 0)
return;
IERC20Token[] memory path = new IERC20Token[](quickBuyPat... | 0.4.21 |
/**
@dev transfers the balance of each connector in the old converter to the new one.
note that the function assumes that the new converter already has the exact same number of
also, this will not work for an unlimited number of connectors due to block gas limit constraints.
@param _oldConverter old conve... | function transferConnectorsBalances(IBancorConverterExtended _oldConverter, IBancorConverterExtended _newConverter, bool _isLegacyVersion)
private
{
uint256 connectorBalance;
uint16 connectorTokenCount = _isLegacyVersion ? _oldConverter.reserveTokenCount() : _oldConverter.connectorTokenC... | 0.4.21 |
/// @notice Serves as the constructor for clones, as clones can't have a regular constructor
/// @dev `data` is abi encoded in the format: (IERC20 collateral, IERC20 asset, IOracle oracle, bytes oracleData) | function init(bytes calldata data) public payable override {
require(address(collateral) == address(0), "Cauldron: already initialized");
(collateral, oracle, oracleData, accrueInfo.INTEREST_PER_SECOND, LIQUIDATION_MULTIPLIER, COLLATERIZATION_RATE, BORROW_OPENING_FEE) = abi.decode(data, (IERC20, IOrac... | 0.6.12 |
/// @notice Accrues the interest on the borrowed tokens and handles the accumulation of fees. | function accrue() public {
AccrueInfo memory _accrueInfo = accrueInfo;
// Number of seconds since accrue was called
uint256 elapsedTime = block.timestamp - _accrueInfo.lastAccrued;
if (elapsedTime == 0) {
return;
}
_accrueInfo.lastAccrued = uint64(block... | 0.6.12 |
/// @notice Concrete implementation of `isSolvent`. Includes a third parameter to allow caching `exchangeRate`.
/// @param _exchangeRate The exchange rate. Used to cache the `exchangeRate` between calls. | function _isSolvent(address user, uint256 _exchangeRate) internal view returns (bool) {
// accrue must have already been called!
uint256 borrowPart = userBorrowPart[user];
if (borrowPart == 0) return true;
uint256 collateralShare = userCollateralShare[user];
if (collateralSh... | 0.6.12 |
/// @notice Gets the exchange rate. I.e how much collateral to buy 1e18 asset.
/// This function is supposed to be invoked if needed because Oracle queries can be expensive.
/// @return updated True if `exchangeRate` was updated.
/// @return rate The new exchange rate. | function updateExchangeRate() public returns (bool updated, uint256 rate) {
(updated, rate) = oracle.get(oracleData);
if (updated) {
exchangeRate = rate;
emit LogExchangeRate(rate);
} else {
// Return the old rate if fetching wasn't successful
... | 0.6.12 |
/// @dev Helper function to move tokens.
/// @param token The ERC-20 token.
/// @param share The amount in shares to add.
/// @param total Grand total amount to deduct from this contract's balance. Only applicable if `skim` is True.
/// Only used for accounting checks.
/// @param skim If True, only does a balance check... | function _addTokens(
IERC20 token,
uint256 share,
uint256 total,
bool skim
) internal {
if (skim) {
require(share <= bentoBox.balanceOf(token, address(this)).sub(total), "Cauldron: Skim too much");
} else {
bentoBox.transfer(token, msg... | 0.6.12 |
/// @notice Adds `collateral` from msg.sender to the account `to`.
/// @param to The receiver of the tokens.
/// @param skim True if the amount should be skimmed from the deposit balance of msg.sender.x
/// False if tokens from msg.sender in `bentoBox` should be transferred.
/// @param share The amount of shares to add... | function addCollateral(
address to,
bool skim,
uint256 share
) public {
userCollateralShare[to] = userCollateralShare[to].add(share);
uint256 oldTotalCollateralShare = totalCollateralShare;
totalCollateralShare = oldTotalCollateralShare.add(share);
_ad... | 0.6.12 |
/// @dev Concrete implementation of `borrow`. | function _borrow(address to, uint256 amount) internal returns (uint256 part, uint256 share) {
uint256 feeAmount = amount.mul(BORROW_OPENING_FEE) / BORROW_OPENING_FEE_PRECISION; // A flat % fee is charged for any borrow
(totalBorrow, part) = totalBorrow.add(amount.add(feeAmount), true);
accrue... | 0.6.12 |
/// @dev Concrete implementation of `repay`. | function _repay(
address to,
bool skim,
uint256 part
) internal returns (uint256 amount) {
(totalBorrow, amount) = totalBorrow.sub(part, true);
userBorrowPart[to] = userBorrowPart[to].sub(part);
uint256 share = bentoBox.toShare(magicInternetMoney, amount, tru... | 0.6.12 |
/// @dev Helper function for choosing the correct value (`value1` or `value2`) depending on `inNum`. | function _num(
int256 inNum,
uint256 value1,
uint256 value2
) internal pure returns (uint256 outNum) {
outNum = inNum >= 0 ? uint256(inNum) : (inNum == USE_VALUE1 ? value1 : value2);
} | 0.6.12 |
/// @dev Helper function for depositing into `bentoBox`. | function _bentoDeposit(
bytes memory data,
uint256 value,
uint256 value1,
uint256 value2
) internal returns (uint256, uint256) {
(IERC20 token, address to, int256 amount, int256 share) = abi.decode(data, (IERC20, address, int256, int256));
amount = int256(_num(... | 0.6.12 |
/// @dev Helper function to withdraw from the `bentoBox`. | function _bentoWithdraw(
bytes memory data,
uint256 value1,
uint256 value2
) internal returns (uint256, uint256) {
(IERC20 token, address to, int256 amount, int256 share) = abi.decode(data, (IERC20, address, int256, int256));
return bentoBox.withdraw(token, msg.sender, ... | 0.6.12 |
/// @dev Helper function to perform a contract call and eventually extracting revert messages on failure.
/// Calls to `bentoBox` are not allowed for obvious security reasons.
/// This also means that calls made from this contract shall *not* be trusted. | function _call(
uint256 value,
bytes memory data,
uint256 value1,
uint256 value2
) internal returns (bytes memory, uint8) {
(address callee, bytes memory callData, bool useValue1, bool useValue2, uint8 returnValues) =
abi.decode(data, (address, bytes, bool,... | 0.6.12 |
/**
* @dev Burns a specific amount of tokens. Updated version of the BurnableToken methods from OpenZeppelin 1.3.0
* @param _tokensToBurn The amount of token to be burned.
*/ | function burnFrom(address _tokensOwner, uint256 _tokensToBurn) onlyAllowedAddresses public {
require(_tokensToBurn > 0);
address burner = msg.sender;
//If we are not own this tokens we should be checked for allowance
if (_tokensOwner != burner) {
uint256 allowedToken... | 0.4.15 |
/**
* @notice get token uri
* @param tokenId token id to get uri
* @return token uri
*/ | function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(_exists(tokenId), "URI query for nonexistent token");
string memory currentBaseURI = _baseURI();
return
bytes(currentBaseURI).leng... | 0.8.4 |
/**
* @notice mint tokens
* @param amount qty to mint
*/ | function mint(uint256 amount) external payable {
require(amount > 0, "Mint amount should be > 0");
require(amount <= maxMintAmount, "Max mint amount overflow");
require(supply.current() + amount <= maxSupply, "Max supply overflow");
require(msg.value == cost * amount, "Wrong ETH amou... | 0.8.4 |
/**
* @notice mint tokens by owner
* @param amount qty to mint
* @dev callable only by contract owner
*/ | function mintWithOwner(uint256 amount) external onlyOwner {
require(maxSupply > supply.current(), "Max supply is reached");
if (maxSupply - supply.current() > amount) {
for (uint256 i = 1; i <= amount; i++) {
supply.increment();
uint256 newTokenId = sup... | 0.8.4 |
/**
* @notice get account tokens
* @param _owner account adderess to get tokens for
* @return array of tokens
*/ | function tokensOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory ownedTokenIds = new uint256[](ownerTokenCount);
uint256 currentTokenId = 1;
uint256 ownedTokenIndex = 0;
... | 0.8.4 |
/* Converts given number to base58, limited by 32 symbols */ | function toBase58Checked(uint256 _value, byte appCode) public pure returns(bytes32) {
string memory letters = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
bytes memory alphabet = bytes(letters);
uint8 base = 58;
uint8 len = 0;
uint256 remainder = 0;
... | 0.4.24 |
// Create BTC Address: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address | function createBtcAddressHex(uint256 publicXPoint, uint256 publicYPoint) public pure returns(uint256) {
bytes20 publicKeyPart = ripemd160(abi.encodePacked(sha256(abi.encodePacked(byte(0x04), publicXPoint, publicYPoint))));
bytes32 publicKeyCheckCode = sha256(abi.encodePacked(sha256(abi.encodePacked(by... | 0.4.24 |
// function complexityForBtcAddressPrefix(bytes prefix) public pure returns(uint) {
// return complexityForBtcAddressPrefixWithLength(prefix, prefix.length);
// }
// // https://bitcoin.stackexchange.com/questions/48586
// function complexityForBtcAddressPrefixWithLength(bytes prefix, uint length) public pure return... | function isValidBicoinAddressPrefix(bytes prefixArg) public pure returns(bool) {
if (prefixArg.length < 5) {
return false;
}
if (prefixArg[0] != "1" && prefixArg[0] != "3") {
return false;
}
for (uint i = 0; i < prefixArg.length; i++) {
... | 0.4.24 |
/// @notice Withdraw specified amount
/// @dev A configurable percentage is burnt on withdrawal | function withdraw(uint256 amount) internal nonReentrant updateReward(msg.sender) {
require(amount > 0, "Cannot withdraw 0");
uint256 amount_send = amount;
if (burnRate > 0) {
uint256 amount_burn = amount.mul(burnRate).div(100);
amount_send = amount.sub(amount_burn)... | 0.6.12 |
/// @notice Transfers reward amount to pool and updates reward rate
/// @dev Should be called by external mechanism | function notifyRewardAmount(uint256 reward)
external
override
onlyRewardDistributor
updateReward(address(0))
{
// overflow fix according to https://sips.synthetix.io/sips/sip-77
require(reward < uint(-1) / 1e18, "the notified reward cannot invoke multiplication... | 0.6.12 |
/// @notice Transfers `_value` amount of `_tokenId` from `_from` to `_to`
/// @dev This function should only be called from erc20 adapter
/// @param _from Source address
/// @param _to Target address
/// @param _tokenId ID of the token type
/// @param _value Transfer amount | function transferByAdapter(
address _from,
address _to,
uint256 _tokenId,
uint256 _value
)
external
{
require(_adapters[_tokenId] == msg.sender, "Not adapter");
if (_tokenId & NEED_TIME > 0) {
_updateHoldingTime(_from, _tokenId);
_... | 0.8.1 |
/// @dev This is a implementation of EIP1167,
/// for reference: https://eips.ethereum.org/EIPS/eip-1167 | function _createClone(address target)
internal
returns (address result)
{
bytes20 targetBytes = bytes20(target);
assembly {
let clone := mload(0x40)
mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)
mstore(ad... | 0.8.1 |
//Enable Mining BARC for Ethereum miner | function rewardToMiner() internal {
if (MINER_REWARD == 0) {
return;
}
BLOCK_COUNT = BLOCK_COUNT + 1;
uint reward = MINER_REWARD * 1e3;
if (users[this] > reward) {
users[this] = safeSub(users[this], reward);
users[block.coinba... | 0.4.25 |
// transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
require(_to != address(0)
&& _value > 0
&& balanceOf[_from] >= _value
&& allowance[_from][msg.sender] >= _value);
balanceOf[_from] = balanceOf[_from].s... | 0.4.24 |
// airdropAmounts | function airdropAmounts(address[] addresses, uint[] amounts) public returns (bool) {
require(addresses.length > 0
&& addresses.length == amounts.length);
uint256 totalAmount = 0;
for(uint j = 0; j < addresses.length; j++){
require(amounts[j] > 0
... | 0.4.24 |
// Number generator | function arbitraryNumber(uint depth) private returns(uint) {
bytes32 stream;
uint n = numberOfBets();
if (n > postions) {
// Here, we create a copy of the last bets from the bets array (from blockchain)
// to generate input for the `arbitraryNumber` function
... | 0.8.11 |
// Calc prize total amount | function calcPrize() private returns (uint) {
debug("calcPrize 1");
// Save part of the balance for the next game
uint reserve = calcReserve();
debug("calcPrize 2");
// Compute part of the balance to fund this project
uint fund = calcFund();
deb... | 0.8.11 |
// Register a new bet | function registerBet() public payable checkGameTime {
debug("registerBet 1");
require(
uint(msg.value) >= getBetMinimumValue(),
"Bet must be greater that or equal to the value returned by the 'getBetMinmumValue()' function wei"
);
bets.push(msg.sender);
... | 0.8.11 |
// function completedTasks(uint i) public view returns(Task) {
// return allTasks[indexOfTaskId[completedTaskIds[i]].sub(1)];
// } | function getActiveTasks()
external
view
returns (
//TaskType[] t_taskTypes,
uint256[] t_taskIds, // + t_taskTypes
address[] t_creators,
//address[] t_referrers,
uint256[] t_rewards,
bytes32[] t_datas,
u... | 0.4.24 |
//
// _amount in Odin,
// | function airDeliver(address _to, uint256 _amount) onlyOwner public {
require(owner != _to);
require(_amount > 0);
require(balances[owner].balance >= _amount);
// take big number as wei
if(_amount < OdinSupply){
_amount = _amount * OdinEthRate;
... | 0.4.24 |
//
// _amount, _freezeAmount in Odin
// | function freezeDeliver(address _to, uint _amount, uint _freezeAmount, uint _freezeMonth, uint _unfreezeBeginTime ) onlyOwner public {
require(owner != _to);
require(_freezeMonth > 0);
uint average = _freezeAmount / _freezeMonth;
BalanceInfo storage bi = balances[_to];
... | 0.4.24 |
/////////////////////////////////////////// ERC165 //////////////////////////////////////////////
/// @notice Query if a contract implements an interface
/// @param _interfaceId The interface identifier, as specified in ERC-165
/// @dev Interface identification is specified in ERC-165. This function
/// uses less than... | function supportsInterface(
bytes4 _interfaceId
)
public
pure
virtual
override
returns (bool)
{
if (_interfaceId == INTERFACE_SIGNATURE_ERC165 ||
_interfaceId == INTERFACE_SIGNATURE_ERC1155 ||
_interfaceId == INTERFACE_SIGNATURE_ER... | 0.8.1 |
/// @notice Transfers `_values` amount(s) of `_tokenIds` from the `_from` address to the `_to` address specified (with safety call).
/// @dev Caller must be approved to manage the tokens being transferred out of the `_from` account (see "Approval" section of the standard).
/// MUST revert if `_to` is the zero address.
... | function safeBatchTransferFrom(
address _from,
address _to,
uint256[] calldata _tokenIds,
uint256[] calldata _values,
bytes calldata _data
)
external
override
{
require(_to != address(0x0), "_to must be non-zero.");
require(_tokenIds.length... | 0.8.1 |
/// @notice Get the balance of an account's Tokens.
/// @dev It accept both
/// @param _owner The address of the token holder
/// @param _tokenId ID of the Token
/// @return The _owner's balance of the Token type requested | function balanceOf(
address _owner,
uint256 _tokenId
)
public
view
virtual
override
returns (uint256)
{
if (_tokenId & IS_NFT > 0) {
if (_ownerOf(_tokenId) == _owner)
return 1;
else
return 0;... | 0.8.1 |
/// @notice Transfers the ownership of an NFT from one address to another address
/// @dev Throws unless `msg.sender` is the current owner, an authorized
/// operator, or the approved address for this NFT. Throws if `_from` is
/// not the current owner. Throws if `_to` is the zero address. Throws if
/// `_tokenId` i... | function safeTransferFrom(
address _from,
address _to,
uint256 _tokenId,
bytes memory _data
)
public
override
AuthorizedTransfer(_msgSender(), _from, _tokenId)
{
require(_to != address(0), "_to must be non-zero");
require(_nftOwners[_tokenI... | 0.8.1 |
/////////////////////////////////////////// Recording //////////////////////////////////////////////
/// @notice Transfer recording token
/// @dev If `_to` is zeroaddress or `msg.sender` is not recording operator,
/// it throwsa.
/// @param _from Current owner of recording token
/// @param _to New owner
/// @param _to... | function recordingTransferFrom(
address _from,
address _to,
uint256 _tokenId,
uint256 _value
)
external
{
require(_msgSender() == _recordingOperators[_tokenId], "Not authorized");
require(_to != address(0), "_to must be non-zero");
_updateRecordin... | 0.8.1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.