comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
/**
@notice checks array to ensure against duplicate
@param _list address[]
@param _token address
@return bool
*/ | function listContains( address[] storage _list, address _token ) internal view returns ( bool ) {
for( uint i = 0; i < _list.length; i++ ) {
if( _list[ i ] == _token ) {
return true;
}
}
return false;
} | 0.7.5 |
/**
* @dev Set circuitBreak to freeze/unfreeze all handlers
* @param _emergency The boolean status of circuitBreaker (on/off)
* @return true (TODO: validate results)
*/ | function setCircuitBreaker(bool _emergency) onlyBreaker external override returns (bool)
{
for (uint256 handlerID = 0; handlerID < tokenHandlerLength; handlerID++)
{
proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));
// use delegate call v... | 0.6.12 |
/**
* @dev Reward the user (msg.sender) with the reward token after calculating interest.
* @return true (TODO: validate results)
*/ | function interestUpdateReward() external override returns (bool)
{
uint256 thisBlock = block.number;
uint256 interestRewardUpdated = dataStorageInstance.getInterestRewardUpdated();
uint256 delta = thisBlock - interestRewardUpdated;
if (delta == 0)
{
return false;
}
dataStorageInstance.setIn... | 0.6.12 |
/* TODO: comment */ | function _claimHandlerRewardAmount(uint256 handlerID, address payable userAddr) internal returns (uint256) {
bytes memory data;
proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(handlerID));
tokenHandler.siProxy(
abi.encodeWithSelector(
SIInterface
... | 0.6.12 |
/**
* @dev Transfer reward tokens to a user
* @param userAddr The address of recipient
* @param _amount The amount of the reward token
* @return true (TODO: validate results)
*/ | function _rewardTransfer(address payable userAddr, uint256 _amount) internal returns (bool)
{
IERC20 _rewardERC20 = rewardErc20Instance;
if(address(_rewardERC20) != address(0x0)) {
uint256 beforeBalance = _rewardERC20.balanceOf(userAddr);
_rewardERC20.transfer(userAddr, _amount);
require(_amount =... | 0.6.12 |
/**
* @dev Epilogue of _determineRewardParams for code-size savings
* @param _dataStorage interface of Manager Data Storage
* @param userAddr User Address for Reward token transfer
* @param _delta The inactive period (delta) since the last action happens
* @param _globalRewardPerBlock Reward per block
... | function _epilogueOfDetermineRewardParams(
managerDataStorageInterfaceForManager _dataStorage,
address payable userAddr,
uint256 _delta,
uint256 _globalRewardPerBlock,
uint256 _globalRewardDecrement,
uint256 _globalRewardTotalAmount
) internal returns (bool) {
// Set the reward model parameters... | 0.6.12 |
/**
* @dev Update rewards paramters of token handlers.
* @param userAddr The address of operator
* @return true (TODO: validate results)
*/ | function _calcRewardParams(address payable userAddr) internal returns (bool)
{
uint256 handlerLength = tokenHandlerLength;
bytes memory data;
uint256[] memory handlerAlphaRateBaseAsset = new uint256[](handlerLength);
uint256[] memory chainAlphaRateBaseAsset;
uint256 handlerID;
uint256 alphaRateBaseG... | 0.6.12 |
/**
* @dev Calculate the alpha-score for the handler (in USD price)
* @param _handlerID The handler ID
* @return The alpha-score of the handler
*/ | function _getAlphaBaseAsset(uint256 _handlerID) internal view returns (uint256)
{
bytes memory data;
proxyContractInterface tokenHandler = proxyContractInterface(dataStorageInstance.getTokenHandlerAddr(_handlerID));
// TODO merge call
(, data) = tokenHandler.handlerViewProxy(
abi.encodeWithSelecto... | 0.6.12 |
/// @dev Calculate the wallet address for the given owner and Switcheo TradeHub address
/// @param _ownerAddress the Ethereum address which the user has control over, i.e. can sign msgs with
/// @param _swthAddress the hex value of the user's Switcheo TradeHub address
/// @param _bytecodeHash the hash of the wallet con... | function getWalletAddress(
address _ownerAddress,
bytes calldata _swthAddress,
bytes32 _bytecodeHash
)
external
view
returns (address)
{
bytes32 salt = _getSalt(
_ownerAddress,
_swthAddress
);
bytes32 ... | 0.6.12 |
/// @dev Add a contract as an extension
/// @param _argsBz the serialized ExtensionTxArgs
/// @param _fromChainId the originating chainId
/// @return true if success | function addExtension(
bytes calldata _argsBz,
bytes calldata /* _fromContractAddr */,
uint64 _fromChainId
)
external
onlyManagerContract
nonReentrant
returns (bool)
{
require(_fromChainId == counterpartChainId, "Invalid chain ID");
... | 0.6.12 |
/// @dev Remove a contract from the extensions mapping
/// @param _argsBz the serialized ExtensionTxArgs
/// @param _fromChainId the originating chainId
/// @return true if success | function removeExtension(
bytes calldata _argsBz,
bytes calldata /* _fromContractAddr */,
uint64 _fromChainId
)
external
onlyManagerContract
nonReentrant
returns (bool)
{
require(_fromChainId == counterpartChainId, "Invalid chain ID");
... | 0.6.12 |
/// @dev Marks an asset as registered by mapping the asset's address to
/// the specified _fromContractAddr and assetHash on Switcheo TradeHub
/// @param _argsBz the serialized RegisterAssetTxArgs
/// @param _fromContractAddr the associated contract address on Switcheo TradeHub
/// @param _fromChainId the originating c... | function registerAsset(
bytes calldata _argsBz,
bytes calldata _fromContractAddr,
uint64 _fromChainId
)
external
onlyManagerContract
nonReentrant
returns (bool)
{
require(_fromChainId == counterpartChainId, "Invalid chain ID");
... | 0.6.12 |
/// @dev Performs a deposit from a Wallet contract
/// @param _walletAddress address of the wallet contract, the wallet contract
/// does not receive ETH in this call, but _walletAddress still needs to be payable
/// since the wallet contract can receive ETH, there would be compile errors otherwise
/// @param _assetHas... | function lockFromWallet(
address payable _walletAddress,
address _assetHash,
bytes calldata _targetProxyHash,
bytes calldata _toAssetHash,
bytes calldata _feeAddress,
uint256[] calldata _values,
uint8 _v,
bytes32[] calldata _rs
)
exte... | 0.6.12 |
/// @dev Performs a deposit
/// @param _assetHash the asset to deposit
/// @param _targetProxyHash the associated proxy hash on Switcheo TradeHub
/// @param _toAddress the hex version of the Switcheo TradeHub address to deposit to
/// @param _toAssetHash the associated asset hash on Switcheo TradeHub
/// @param _feeAdd... | function lock(
address _assetHash,
bytes calldata _targetProxyHash,
bytes calldata _toAddress,
bytes calldata _toAssetHash,
bytes calldata _feeAddress,
uint256[] calldata _values
)
external
payable
nonReentrant
returns (bool)... | 0.6.12 |
/// @dev Performs a withdrawal that was initiated on Switcheo TradeHub
/// @param _argsBz the serialized TransferTxArgs
/// @param _fromContractAddr the associated contract address on Switcheo TradeHub
/// @param _fromChainId the originating chainId
/// @return true if success | function unlock(
bytes calldata _argsBz,
bytes calldata _fromContractAddr,
uint64 _fromChainId
)
external
onlyManagerContract
nonReentrant
returns (bool)
{
require(_fromChainId == counterpartChainId, "Invalid chain ID");
Transf... | 0.6.12 |
/// @dev Performs a transfer of funds, this is only callable by approved extension contracts
/// the `nonReentrant` guard is intentionally not added to this function, to allow for more flexibility.
/// The calling contract should be secure and have its own `nonReentrant` guard as needed.
/// @param _receivingAddress th... | function extensionTransfer(
address _receivingAddress,
address _assetHash,
uint256 _amount
)
external
returns (bool)
{
require(
extensions[msg.sender] == true,
"Invalid extension"
);
if (_assetHash == ETH_ASSET... | 0.6.12 |
/// @dev Marks an asset as registered by associating it to a specified Switcheo TradeHub proxy and asset hash
/// @param _assetHash the address of the asset to mark
/// @param _proxyAddress the associated proxy address on Switcheo TradeHub
/// @param _toAssetHash the associated asset hash on Switcheo TradeHub | function _markAssetAsRegistered(
address _assetHash,
bytes memory _proxyAddress,
bytes memory _toAssetHash
)
private
{
require(_proxyAddress.length == 20, "Invalid proxyAddress");
require(
registry[_assetHash] == bytes32(0),
"Asse... | 0.6.12 |
/// @dev Validates that an asset's registration matches the given params
/// @param _assetHash the address of the asset to check
/// @param _proxyAddress the expected proxy address on Switcheo TradeHub
/// @param _toAssetHash the expected asset hash on Switcheo TradeHub | function _validateAssetRegistration(
address _assetHash,
bytes memory _proxyAddress,
bytes memory _toAssetHash
)
private
view
{
require(_proxyAddress.length == 20, "Invalid proxyAddress");
bytes32 value = keccak256(abi.encodePacked(
_... | 0.6.12 |
/// @dev validates the asset registration and calls the CCM contract | function _lock(
address _fromAssetHash,
bytes memory _targetProxyHash,
bytes memory _toAssetHash,
bytes memory _toAddress,
uint256 _amount,
uint256 _feeAmount,
bytes memory _feeAddress
)
private
{
require(_targetProxyHash.length ... | 0.6.12 |
/// @dev validate the signature for lockFromWallet | function _validateLockFromWallet(
address _walletOwner,
address _assetHash,
bytes memory _targetProxyHash,
bytes memory _toAssetHash,
bytes memory _feeAddress,
uint256[] memory _values,
uint8 _v,
bytes32[] memory _rs
)
private
{
... | 0.6.12 |
/// @dev transfers funds from a Wallet contract into this contract
/// the difference between this contract's before and after balance must equal _amount
/// this is assumed to be sufficient in ensuring that the expected amount
/// of funds were transferred in | function _transferInFromWallet(
address payable _walletAddress,
address _assetHash,
uint256 _amount,
uint256 _callAmount
)
private
{
Wallet wallet = Wallet(_walletAddress);
if (_assetHash == ETH_ASSET_HASH) {
uint256 before = address(... | 0.6.12 |
/// @dev transfers funds from an address into this contract
/// for ETH transfers, we only check that msg.value == _amount, and _callAmount is ignored
/// for token transfers, the difference between this contract's before and after balance must equal _amount
/// these checks are assumed to be sufficient in ensuring tha... | function _transferIn(
address _assetHash,
uint256 _amount,
uint256 _callAmount
)
private
{
if (_assetHash == ETH_ASSET_HASH) {
require(msg.value == _amount, "ETH transferred does not match the expected amount");
return;
}
... | 0.6.12 |
/// @dev transfers funds from this contract to the _toAddress | function _transferOut(
address _toAddress,
address _assetHash,
uint256 _amount
)
private
{
if (_assetHash == ETH_ASSET_HASH) {
// we use `call` here since the _receivingAddress could be a contract
// see https://diligence.consensys.net/blo... | 0.6.12 |
/// @dev validates a signature against the specified user address | function _validateSignature(
bytes32 _message,
address _user,
uint8 _v,
bytes32 _r,
bytes32 _s
)
private
pure
{
bytes32 prefixedMessage = keccak256(abi.encodePacked(
"\x19Ethereum Signed Message:\n32",
_message
... | 0.6.12 |
/**
* @dev Mint function
*/ | function mint(
uint8 _quantity,
uint256 _fromTimestamp,
uint256 _toTimestamp,
uint8 _maxQuantity,
bytes calldata _signature
) external payable callerIsUser {
bytes32 messageHash = generateMessageHash(msg.sender, _fromTimestamp, _toTimestamp, _maxQuantity);
add... | 0.8.10 |
/**
* @dev mint to address
*/ | function mintTo(address[] memory _addresses) external {
require(msg.sender == sAddress, "Caller is not allowed to mint");
require(_addresses.length > 0, "At least one token should be minted");
require(sMintedTokens + _addresses.length <= sMintLimit, "Mint limit reached");
QueensAndKings... | 0.8.10 |
/**
* @dev Returns a random available token to be minted
*/ | function _getTokenToBeMinted(uint16 _totalMintedTokens) private returns (uint16) {
uint16 maxIndex = totalAvatars + sMintLimit - _totalMintedTokens;
uint16 random = _getRandomNumber(maxIndex, _totalMintedTokens);
uint16 tokenId = tokenMatrix[random];
if (tokenMatrix[random] == 0) {
... | 0.8.10 |
/**
* @dev Generates a pseudo-random number.
*/ | function _getRandomNumber(uint16 _upper, uint16 _totalMintedTokens) private view returns (uint16) {
uint16 random = uint16(
uint256(
keccak256(
abi.encodePacked(
_totalMintedTokens,
blockhash(block.number - 1),
... | 0.8.10 |
/**
* ROYALTY FUNCTIONS
*/ | function getRoyalties(uint256) external view returns (address payable[] memory recipients, uint256[] memory bps) {
if (_royaltyRecipient != address(0x0)) {
recipients = new address payable[](1);
recipients[0] = _royaltyRecipient;
bps = new uint256[](1);
bps[0] = _... | 0.8.7 |
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/ | function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal {
address oldImplementation = _getImplementation();
// Initial upgrade and setup call
_setImplementation(newImplementation);
if (data.length > 0 || forceCall) {
Addr... | 0.8.2 |
/**
* @dev update the default token Uri.
*
* @param _before token uri before part.
* @param _after token uri after part.
*
* Returns
* - bool
*/ | function updateDefaultUri(string memory _before, string memory _after) external onlyOwner returns (bool){
beforeUri = _before; // update the before uri for Badbeat
afterUri = _after; // update the after uri for Badbeat
return true;
} | 0.8.10 |
/**
* @dev creating new NFT on immutable x.
*
* @param tokens token details.
* @param signature signature to verify.
*
* Returns
* - bool
*
* Emits a {TransferEth} event.
*/ | function buyNFT(tokenDetails calldata tokens, bytes calldata signature) public payable returns(bool){
uint256 value = msg.value;
require(buyOnOff == true, "NFT minting is stopped");
bool status = SignatureCheckerUpgradeable.isValidSignatureNow(owner(), tokens.signKey, signature);
... | 0.8.10 |
/**
* @dev mintinf function by only IMX.
*
* @param user msg.sender.
* @param quantity number of token amount.
* @param mintingBlob bytes32
*
* Returns
* - bool
*
* Emits a {AssetMinted} event.
*/ | function mintFor(
address user,
uint256 quantity,
bytes calldata mintingBlob
) external onlyIMX {
require(quantity == 1, "Mintable: invalid quantity");
(uint256 id, bytes memory blueprint) = Minting.split(mintingBlob);
_mintFor(user, id, blueprint);
bl... | 0.8.10 |
/**
============================================
Internal Functions
@dev functions that can be called by inside contract
============================================
*/ | function calculateRewards(uint128 _mintingAmount, uint128 remainingBoost, uint128 remainingSupply) internal pure returns (uint128, uint128) {
uint128 boostRewards;
uint128 finalMintingReward;
uint128 removedBoost;
unchecked {
if (remainingBoost > _mintingAmount * 2) {
... | 0.8.13 |
/**
* @dev Constructor function - Set the inbest token address
* @param _startTime The time when InbestDistribution goes live
* @param _companyWallet The wallet to allocate Company tokens
*/ | function InbestDistribution(uint256 _startTime, address _companyWallet) public {
require(_companyWallet != address(0));
require(_startTime >= now);
require(AVAILABLE_TOTAL_SUPPLY == AVAILABLE_PRESALE_SUPPLY.add(AVAILABLE_COMPANY_SUPPLY));
startTime = _startTime;
companyWallet = _companyWallet;
... | 0.4.24 |
/**
* @dev Allow the owner or admins of the contract to assign a new allocation
* @param _recipient The recipient of the allocation
* @param _totalAllocated The total amount of IBST tokens available to the receipient (after vesting and cliff)
*/ | function setAllocation (address _recipient, uint256 _totalAllocated) public onlyOwnerOrAdmin {
require(_recipient != address(0));
require(startTime > now); //Allocations are allowed only before starTime
require(AVAILABLE_PRESALE_SUPPLY >= _totalAllocated); //Current allocation must be less than remaining... | 0.4.24 |
/**
* @dev Transfer a recipients available allocation to their address
* @param _recipient The address to withdraw tokens for
*/ | function transferTokens (address _recipient) public {
require(_recipient != address(0));
require(now >= startTime); //Tokens can't be transfered until start date
require(_recipient != companyWallet); // Tokens allocated to COMPANY can't be withdrawn.
require(now >= allocations[_recipient].endCliff); // ... | 0.4.24 |
/**
* @dev Transfer IBST tokens from Company allocation to reicipient address - Only owner and admins can execute
* @param _recipient The address to transfer tokens for
* @param _tokensToTransfer The amount of IBST tokens to transfer
*/ | function manualContribution(address _recipient, uint256 _tokensToTransfer) public onlyOwnerOrAdmin {
require(_recipient != address(0));
require(_recipient != companyWallet); // Company can't withdraw tokens for itself
require(_tokensToTransfer > 0); // The amount must be valid
require(now >= startTime);... | 0.4.24 |
/**
* @dev Mint edition to a wallet
* @param _to wallet receiving the edition(s).
* @param _mintAmount number of editions to mint.
*/ | function mint(address _to, uint256 _mintAmount) public payable {
require(!paused, "Minting is Paused.");
require(_mintAmount <= maxMintAmount, "Only 10 DieHardDinos are Allowed Per Transaction");
require(
tokenId + _mintAmount <= maxSupply,
"Dinosphere is at Max Capa... | 0.8.7 |
/// @dev Allows anyone to execute a confirmed transaction or ether withdraws until daily limit is reached.
/// @param transactionId Transaction ID. | function executeTransaction(uint transactionId)
public
ownerExists(msg.sender)
confirmed(transactionId, msg.sender)
notExecuted(transactionId)
{
Transaction storage txn = transactions[transactionId];
bool _confirmed = isConfirmed(transactionId);
if (_c... | 0.4.19 |
/// @dev Returns if amount is within daily limit and resets spentToday after one day.
/// @param amount Amount to withdraw.
/// @return Returns if amount is under daily limit. | function isUnderLimit(uint amount)
internal
returns (bool)
{
if (now > lastDay + 24 hours) {
lastDay = now;
spentToday = 0;
}
if (spentToday + amount > dailyLimit || spentToday + amount < spentToday)
return false;
return t... | 0.4.19 |
/**
* @notice Modify auction parameters
* @param parameter The name of the parameter modified
* @param data New value for the parameter
*/ | function modifyParameters(bytes32 parameter, uint256 data) external isAuthorized {
require(data > 0, "StakedTokenAuctionHouse/null-data");
require(contractEnabled == 1, "StakedTokenAuctionHouse/contract-not-enabled");
if (parameter == "bidIncrease") {
require(data > ONE, "StakedT... | 0.6.7 |
/**
* @notice Modify an address parameter
* @param parameter The name of the oracle contract modified
* @param addr New contract address
*/ | function modifyParameters(bytes32 parameter, address addr) external isAuthorized {
require(addr != address(0), "StakedTokenAuctionHouse/null-addr");
require(contractEnabled == 1, "StakedTokenAuctionHouse/contract-not-enabled");
if (parameter == "accountingEngine") accountingEngine = addr;
... | 0.6.7 |
/**
* @notice Start a new staked token auction
* @param amountToSell Amount of staked tokens to sell (wad)
*/ | function startAuction(
uint256 amountToSell,
uint256 systemCoinsRequested
) external isAuthorized returns (uint256 id) {
require(contractEnabled == 1, "StakedTokenAuctionHouse/contract-not-enabled");
require(auctionsStarted < uint256(-1), "StakedTokenAuctionHouse/overflow");
... | 0.6.7 |
/**
* @notice Restart an auction if no bids were submitted for it
* @param id ID of the auction to restart
*/ | function restartAuction(uint256 id) external {
require(id <= auctionsStarted, "StakedTokenAuctionHouse/auction-never-started");
require(bids[id].auctionDeadline < now, "StakedTokenAuctionHouse/not-finished");
require(bids[id].bidExpiry == 0, "StakedTokenAuctionHouse/bid-already-placed");
... | 0.6.7 |
/**
* @notice Submit a higher system coin bid for the same amount of staked tokens
* @param id ID of the auction you want to submit the bid for
* @param amountToBuy Amount of staked tokens to buy (wad)
* @param bid New bid submitted (rad)
*/ | function increaseBidSize(uint256 id, uint256 amountToBuy, uint256 bid) external {
require(contractEnabled == 1, "StakedTokenAuctionHouse/contract-not-enabled");
require(bids[id].bidExpiry > now || bids[id].bidExpiry == 0, "StakedTokenAuctionHouse/bid-already-expired");
require(bids[id].auctio... | 0.6.7 |
/**
* @notice Settle/finish an auction
* @param id ID of the auction to settle
*/ | function settleAuction(uint256 id) external {
require(contractEnabled == 1, "StakedTokenAuctionHouse/not-live");
require(both(bids[id].bidExpiry != 0, either(bids[id].bidExpiry < now, bids[id].auctionDeadline < now)), "StakedTokenAuctionHouse/not-finished");
// get the bid, the amount to se... | 0.6.7 |
/**
* @notice Terminate an auction prematurely
* @param id ID of the auction to terminate
*/ | function terminateAuctionPrematurely(uint256 id) external {
require(contractEnabled == 0, "StakedTokenAuctionHouse/contract-still-enabled");
require(bids[id].highBidder != address(0), "StakedTokenAuctionHouse/high-bidder-not-set");
// decrease amount of active auctions
activeStaked... | 0.6.7 |
// ------------------------------------------------------------------------
// 1 YAR Tokens per 1 ETH
// ------------------------------------------------------------------------ | function () public payable {
require(now >= startDate);
uint tokens;
if (now <= bonusEnds) {
tokens = msg.value * 12;
} else {
tokens = msg.value * 10;
}
balances[msg.sender] = safeAdd(balances[msg.sender], tokens);
_totalSupply = ... | 0.4.24 |
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/ | function _safeMint(
address to,
uint256 tokenId,
bytes memory _data
) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, _data),
"ERC721: transfer to non ERC721Receiver implementer"
);
... | 0.8.0 |
/**
* @param A The input array to search
* @param a The address to remove
*/ | function removeStorage(address[] storage A, address a)
internal
{
(uint256 index, bool isIn) = indexOf(A, a);
if (!isIn) {
revert("Address not in array.");
} else {
uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line woul... | 0.6.10 |
/**
* Returns the combination of the two arrays
* @param A The first array
* @param B The second array
* @return Returns A extended by B
*/ | function extend(address[] memory A, address[] memory B) internal pure returns (address[] memory) {
uint256 aLength = A.length;
uint256 bLength = B.length;
address[] memory newAddresses = new address[](aLength + bLength);
for (uint256 i = 0; i < aLength; i++) {
newAddress... | 0.6.10 |
/**
* Instructs the SetToken to transfer the ERC20 token to a recipient.
* The new SetToken balance must equal the existing balance less the quantity transferred
*
* @param _setToken SetToken instance to invoke
* @param _token ERC20 token to transfer
* @param _to The recipient ... | function strictInvokeTransfer(
ISetToken _setToken,
address _token,
address _to,
uint256 _quantity
)
internal
{
if (_quantity > 0) {
// Retrieve current balance of token for the SetToken
uint256 existingBalance = IERC20(_token).ba... | 0.6.10 |
/**
* @dev Performs the power on a specified value, reverts on overflow.
*/ | function safePower(
uint256 a,
uint256 pow
)
internal
pure
returns (uint256)
{
require(a > 0, "Value must be positive");
uint256 result = 1;
for (uint256 i = 0; i < pow; i++){
uint256 previousResult = result;
... | 0.6.10 |
/**
* Calculates the new default position unit and performs the edit with the new unit
*
* @param _setToken Address of the SetToken
* @param _component Address of the component
* @param _setTotalSupply Current SetToken supply
* @param _componentPreviousBalance Pre-ac... | function calculateAndEditDefaultPosition(
ISetToken _setToken,
address _component,
uint256 _setTotalSupply,
uint256 _componentPreviousBalance
)
internal
returns(uint256, uint256, uint256)
{
uint256 currentBalance = IERC20(_component).balanceOf(add... | 0.6.10 |
/**
* ONLY MANAGER: Remove stored component from array. Checks to see if there's a duplicate component and
* that module has not been previously used. Calls remove component which will remove first instance
* of component in the array and set used to true to make sure removeComponent() cannot be called again.
*... | function removeComponent() external onlyManagerAndValidSet(setToken) {
require(!used, "Module has been used");
address[] memory components = setToken.getComponents();
uint256 componentCount;
for (uint256 i = 0; i < components.length; i++) {
if (component == components[... | 0.6.10 |
// called by factory to set interest rate redirection for Aave tokens | function claim(address _token, address _to) external {
require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
require(_token != token0 && _token != token1, 'UniswapV2: FORBIDDEN'); // sufficient check
_safeTransfer(_token, _to, IERC20(_token).balanceOf(address(this)));
... | 0.5.16 |
// Withdraw staked tokens
// First withdraws unlocked tokens, then earned tokens. Withdrawing earned tokens
// incurs a 50% penalty which will be burnt | function withdrawEarning(uint256 amount) public {
require(amount > 0, "Cannot withdraw 0");
Balances storage bal = userBalances[msg.sender];
uint256 penaltyAmount = 0;
uint256 remaining = amount;
bal.earned = bal.earned.sub(remaining);
for (uint i = 0; ; i++) {
... | 0.6.12 |
// Final balance received and penalty balance paid by user upon calling exit | function withdrawableEarning(
address user
)
public
view
returns (uint256 amount, uint256 penaltyAmount, uint256 amountWithoutPenalty)
{
Balances storage bal = userBalances[user];
if (bal.earned > 0) {
uint256 length = _userEarnings[user].le... | 0.6.12 |
// Returns a boolean if this oracle can provide data for the requested pair, used during FNFT creation
// If the oracle does not exist, this will revert the transaction | function getPairHasOracle(address asset, address compareTo) public view override returns (bool) {
//First, check if standard ERC20 with decimals() method
uint decimals = ERC20(asset).decimals();
uint price = oracle.assetToAsset(asset, 10**decimals, compareTo, TWAP_PERIOD);
return true;
... | 0.8.4 |
// @dev Presale Mint
// @param tokenCount The tokens a user wants to purchase
// @param presaleMaxMint The max tokens a user can mint from the presale
// @param factionId Community: 0 and Theos: 1
// @param sig Server side signature authorizing user to use the presale | function mintPresale(
uint256 tokenCount,
uint256 presaleMaxMint,
uint256 factionId,
bytes memory sig
) external nonReentrant payable {
require(factionId == 0 || factionId == 1, "Faction is not valid");
require(_isPresaleActive, "Presale not active");
requir... | 0.8.0 |
// @dev Main sale mint
// @param tokensCount The tokens a user wants to purchase
// @param factionId Community: 0 and Theos: 1 | function mint(uint256 tokenCount, uint256 factionId)
external nonReentrant payable {
require(factionId == 0 || factionId == 1, "Faction is not valid");
require(_isSaleActive, "Sale not active");
require(tokenCount > 0, "Must mint at least 1 token");
require(tokenCount <= maxMintPerT... | 0.8.0 |
// @dev Private mint function reserved for company.
// 44 Community and 44 Theos are reserved.
// @param recipient The user receiving the tokens
// @param tokenCount The number of tokens to distribute
// @param factionId Community: 0 and Theos: 1 | function mintToAddress(address recipient, uint256 tokenCount, uint256 factionId)
external onlyOwner {
require(isSaleFinished(), "Sale has not concluded");
require(factionId == 0 || factionId == 1, "Faction does not exist");
require(tokenCount > 0, "You can only mint more than 0 tokens");
... | 0.8.0 |
/**
* @param _tokenId uint256 ID of new token
* @param _payoutPercentage uint256 payout percentage (divisible by 10)
*/ | function createPromoListing(uint256 _tokenId, uint256 _startingPrice, uint256 _payoutPercentage) onlyOwner() public {
uint256 countryId = _tokenId % COUNTRY_IDX;
address countryOwner;
uint256 price;
(countryOwner,,price,,) = countryContract.getCountryData(countryId);
require (countryOwner ... | 0.4.19 |
/**
* @dev createListing Adds new ERC721 Token
* @param _tokenId uint256 ID of new token
* @param _payoutPercentage uint256 payout percentage (divisible by 10)
* @param _owner address of new owner
*/ | function createListing(uint256 _tokenId, uint256 _startingPrice, uint256 _payoutPercentage, address _owner) onlyOwner() public {
// make sure price > 0
require(_startingPrice > 0);
// make sure token hasn't been used yet
require(cityData[_tokenId].price == 0);
// create new token
C... | 0.4.19 |
/**
* @dev Determines next price of token
* @param _price uint256 ID of current price
*/ | function getNextPrice (uint256 _price) private view returns (uint256 _nextPrice) {
if (_price < firstCap) {
return _price.mul(200).div(94);
} else if (_price < secondCap) {
return _price.mul(135).div(95);
} else if (_price < thirdCap) {
return _price.mul(118).div(96);
} else {
... | 0.4.19 |
/**
* @dev Transfer City from Previous Owner to New Owner
* @param _from previous owner address
* @param _to new owner address
* @param _tokenId uint256 ID of token
*/ | function transferCity(address _from, address _to, uint256 _tokenId) internal {
// check token exists
require(tokenExists(_tokenId));
// make sure previous owner is correct
require(cityData[_tokenId].owner == _from);
require(_to != address(0));
require(_to != address(this));
//... | 0.4.19 |
/**
* @dev Updates the payout for the cities the owner has
* @param _owner address of token owner
*/ | function updatePayout(address _owner) public {
uint256[] memory cities = ownedTokens[_owner];
uint256 owed;
for (uint256 i = 0; i < cities.length; i++) {
uint256 totalCityOwed = poolTotal * cityData[cities[i]].payout / 10000;
uint256 cityOwed = totalCityOwed.sub(cityData[cities[i]].with... | 0.4.19 |
/**
* @dev Return all city data
* @param _tokenId uint256 of token
*/ | function getCityData (uint256 _tokenId) external view
returns (address _owner, uint256 _price, uint256 _nextPrice, uint256 _payout, address _cOwner, uint256 _cPrice, uint256 _cPayout)
{
City memory city = cityData[_tokenId];
address countryOwner;
uint256 countryPrice;
uint256 countryPayout;
... | 0.4.19 |
/**
* @dev Approves another address to claim for the ownership of the given token ID
* @param _to address to be approved for the given token ID
* @param _tokenId uint256 ID of the token to be approved
*/ | function approve(address _to, uint256 _tokenId) public onlyOwnerOf(_tokenId) {
address owner = ownerOf(_tokenId);
require(_to != owner);
if (approvedFor(_tokenId) != 0 || _to != 0) {
tokenApprovals[_tokenId] = _to;
Approval(owner, _to, _tokenId);
}
} | 0.4.19 |
/**
* @dev Internal function to clear current approval and transfer the ownership of a given token ID
* @param _from address which you want to send tokens from
* @param _to address which you want to transfer the token to
* @param _tokenId uint256 ID of the token to be transferred
*/ | function clearApprovalAndTransfer(address _from, address _to, uint256 _tokenId) internal isNotContract(_to) {
require(_to != address(0));
require(_to != ownerOf(_tokenId));
require(ownerOf(_tokenId) == _from);
clearApproval(_from, _tokenId);
updateSinglePayout(_from, _tokenId);
removeTok... | 0.4.19 |
/// @notice Whitelist mint using the voucher | function whitelistMint(
NFTVoucher calldata voucher,
bytes calldata signature,
uint8 amount
) external payable {
MinterInfo storage minterInfo = _whitelistInfo[_msgSender()];
// if haven't redeemed then redeem first
if (minterInfo.stageId < stageInfo.stageId) {
... | 0.8.4 |
/// @notice Public mint | function publicMint(uint8 amount) external payable {
// check public mint stage
require(
stageInfo.stageId == PUBLIC_STAGE_ID,
"Public mint not started"
);
// check time
require(block.timestamp >= stageInfo.startTime, "Sale not started");
require(b... | 0.8.4 |
/// @dev Verify voucher | function _verify(NFTVoucher calldata voucher, bytes calldata signature)
private
view
{
bytes32 digest = _hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"NFTVoucher(address redeemer,uint8 stageId,uint8 amount)"
... | 0.8.4 |
/// @dev Go to next stage | function nextStage(StageInfo memory _stageInfo) external onlyOwner {
require(
_stageInfo.stageId >= stageInfo.stageId,
"Cannot set to previous stage"
);
require(_stageInfo.maxSupply <= MAX_SUPPLY, "Set exceed max supply");
require(_stageInfo.stageId <= PUBLIC_STAG... | 0.8.4 |
// This will not throw error on wrong input, but instead consume large and unknown amount of gas
// This should never occure as it's use with the ShapeShift deposit return value is checked before calling function | function parseAddr(string _a) internal returns (address){
bytes memory tmp = bytes(_a);
uint160 iaddr = 0;
uint160 b1;
uint160 b2;
for (uint i=2; i<2+2*20; i+=2){
iaddr *= 256;
b1 = uint160(tmp[i]);
b2 = uint160(tmp[i+1]);
... | 0.4.15 |
/**
* Callback function for use exclusively by Oraclize.
* @param myid The Oraclize id of the query.
* @param result The result of the query.
*/ | function __callback(bytes32 myid, string result) {
if (msg.sender != oraclize.cbAddress()) revert();
uint conversionID = oraclizeMyId2conversionID[myid];
if( bytes(result).length == 0 ) {
ConversionAborted(conversionID, "Oraclize return value was invalid, this is probably due... | 0.4.15 |
/**
* Cancel a cryptocurrency conversion.
* This should only be required to be called if Oraclize fails make a return call to __callback().
* @param conversionID The conversion ID of the cryptocurrency conversion, generated during engine().
*/ | function cancelConversion(uint conversionID) external {
Conversion memory conversion = conversions[conversionID];
if (conversion.amount > 0) {
require(msg.sender == conversion.returnAddress);
recoverable[msg.sender] += conversion.amount;
conversions[conversionI... | 0.4.15 |
/**
* Sets up a ShapeShift cryptocurrency conversion using Oraclize and the ShapeShift API. Must be sent more Ether than the Oraclize price.
* Returns a conversionID which can be used for tracking of the conversion.
* @param _coinSymbol The coinsymbol of the other blockchain to be used by ShapeShift. See engine()... | function engine(string _coinSymbol, string _toAddress, address _returnAddress) internal returns(uint conversionID) {
conversionID = conversionCount++;
if (
!isValidString(_coinSymbol, 6) || // Waves smbol is "waves"
!isValidString(_toAddress, 120) // Monero integrated add... | 0.4.15 |
/**
* Returns true if a given string contains only numbers and letters, and is below a maximum length.
* @param _string String to be checked.
* @param maxSize The maximum allowable sting character length. The address on the other blockchain that the converted cryptocurrency will be sent to.
*/ | function isValidString(string _string, uint maxSize) constant internal returns (bool allowed) {
bytes memory stringBytes = bytes(_string);
uint lengthBytes = stringBytes.length;
if (lengthBytes < 1 ||
lengthBytes > maxSize) {
return false;
}
for (... | 0.4.15 |
/**
* Returns a concatenation of seven bytes.
* @param b1 The first bytes to be concatenated.
* ...
* @param b7 The last bytes to be concatenated.
*/ | function concatBytes(bytes b1, bytes b2, bytes b3, bytes b4, bytes b5, bytes b6, bytes b7) internal returns (bytes bFinal) {
bFinal = new bytes(b1.length + b2.length + b3.length + b4.length + b5.length + b6.length + b7.length);
uint i = 0;
uint j;
for (j = 0; j < b1.length; j++) bF... | 0.4.15 |
/**
* Returns the ShapeShift shift API string that is needed to be sent to Oraclize.
* @param _coinSymbol The coinsymbol of the other blockchain to be used by ShapeShift. See engine() function for more details.
* @param _toAddress The address on the other blockchain that the converted cryptocurrency will be sent ... | function createShapeShiftConversionPost(string _coinSymbol, string _toAddress) internal returns (string sFinal) {
string memory s1 = ' {"withdrawal":"';
string memory s3 = '","pair":"eth_';
string memory s5 = '","returnAddress":"';
string memory s7 = '"}';
bytes memory bFi... | 0.4.15 |
/**
* Returns the bytes representation of a provided Ethereum address
* Authored by from https://github.com/axic
* @param _address Ethereum address to be cast to bytes
*/ | function addressToBytes(address _address) internal returns (bytes) {
uint160 tmp = uint160(_address);
// 40 bytes of space, but actually uses 64 bytes
string memory holder = " ";
bytes memory ret = bytes(holder);
// NOTE: this is wr... | 0.4.15 |
// function mint(uint256 count) external payable {
// require(isMintingOn , 'minting not started');
// require(count < MAX_MINT_COUNT, 'Max Mint per Txn exceeded');
// require(totalPublicSupply + count < MAX_SUPPLY, 'All testnets have already been minted!');
// require(tokenPrice * count == msg.value, '... | function mint(uint256 freeCount, uint256 paidCount) external payable {
require(isMintingOn, 'minting not started');
uint256 count = freeCount + paidCount;
// Total
require(count < MAX_MINT_COUNT, 'Max Mint per Txn exceeded');
// Free
require(
hasUserFre... | 0.8.7 |
/**
* Extract 256-bit worth of data from the bytes stream.
*/ | function slice32(bytes b, uint offset) constant returns (bytes32) {
bytes32 out;
for (uint i = 0; i < 32; i++) {
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
} | 0.4.18 |
/**
* Extract 16-bit worth of data from the bytes stream.
*/ | function slice2(bytes b, uint offset) constant returns (bytes2) {
bytes2 out;
for (uint i = 0; i < 2; i++) {
out |= bytes2(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
} | 0.4.18 |
/**
* Same as above, does not seem to cause any issue.
*/ | function getKYCPayload(bytes dataframe) public constant returns(address whitelistedAddress, uint128 customerId, uint32 minEth, uint32 maxEth) {
address _whitelistedAddress = dataframe.sliceAddress(0);
uint128 _customerId = uint128(dataframe.slice16(20));
uint32 _minETH = uint32(dataframe.slice4(36));
... | 0.4.18 |
// F1 - F10: OK
// C1 - C24: OK | function setBridge(address token, address bridge) external onlyOwner {
// Checks
require(
token != sushi && token != weth && token != bridge,
"SushiMaker: Invalid bridge"
);
// Effects
_bridges[token] = bridge;
emit LogBridgeSet(token, bridge);
... | 0.6.12 |
// F1 - F10: OK, see convert
// C1 - C24: OK
// C3: Loop is under control of the caller | function convertMultiple(
address[] calldata token0,
address[] calldata token1
) external onlyEOA() {
// TODO: This can be optimized a fair bit, but this is safer and simpler for now
uint256 len = token0.length;
for (uint256 i = 0; i < len; i++) {
_convert(token0[... | 0.6.12 |
// F1 - F10: OK
// C1 - C24: OK
// All safeTransfer, swap: X1 - X5: OK | function _swap(
address fromToken,
address toToken,
uint256 amountIn,
address to
) internal returns (uint256 amountOut) {
// Checks
// X1 - X5: OK
IUniswapV2Pair pair =
IUniswapV2Pair(factory.getPair(fromToken, toToken));
require(address(pa... | 0.6.12 |
//
// Contract common functions
// | function transfer(address _to, uint256 _value) public returns (bool) {
//
require(_to != address(0), "'_to' address has to be set");
require(_value <= balances[msg.sender], "Insufficient balance");
//
balances[msg.sender] = balances[msg.sender].sub(_value);
balances... | 0.5.0 |
/**
* Buy _num WHALE with $SOS using specified _maxExchangeRate to mitigate frontrunning.
* max exchange rate is a sqrt(sos/eth) Q64.96 value.
* Cost should be obtained with an offchain call to exchangeRate to prevent frontrunning.
*/ | function buy(uint256 _cost, uint256 _mintNum, uint256 _deadline) external override {
//Get the SOS to buy with
sos.safeTransferFrom(msg.sender, address(this), _cost*_mintNum);
address[] memory path = new address[](2);
path[0] = address(sos);
path[1] = address(weth);
... | 0.8.7 |
/**
* @dev Use this method if you want to incorporate the sender address in the contract address.
*/ | function deployFromContract(bytes32 salt, address deployer, bytes calldata bytecode)
external returns (address) {
bytes32 _data = keccak256(
abi.encodePacked(salt, EXTERNAL_HASH, deployer)
);
address deployed = Create2.deploy(0, _data, bytecode);
emit Deployed(deployed);
... | 0.6.6 |
/**
* Construct token changer
*
* @param _tokenLeft Ref to the 'left' token smart-contract
* @param _tokenRight Ref to the 'right' token smart-contract
* @param _rate The rate used when changing tokens
* @param _fee The percentage of tokens that is charged
* @param _decimals The amount of decimals used fo... | function TokenChanger(address _tokenLeft, address _tokenRight, uint _rate, uint _fee, uint _decimals, bool _paused, bool _burn) {
tokenLeft = IManagedToken(_tokenLeft);
tokenRight = IManagedToken(_tokenRight);
rate = _rate;
fee = _fee;
precision = _decimals > 0 ? 10**_decima... | 0.4.15 |
/**
* Converts tokens by burning the tokens received at the token smart-contact
* located at `_from` and by issuing tokens at the opposite token smart-contract
*
* @param _from The token smart-contract that received the tokens
* @param _sender The account that send the tokens (token owner)
* @param _value ... | function convert(address _from, address _sender, uint _value) internal {
require(!paused);
require(_value > 0);
uint amountToIssue;
if (_from == address(tokenLeft)) {
amountToIssue = _value * rate / precision;
tokenRight.issue(_sender, amountToIssue - calc... | 0.4.15 |
// bonus scheme during ICO, 1 ETH = 800 EDEX for 1st 20 days, 1 ETH = 727 EDEX for 2nd 20 days, 1 ETH = 667 EDEX for 3rd 20 days | function icoBottomIntegerPrice() public constant returns (uint256){
uint256 icoDuration = safeSub(block.number, icoStartBlock);
uint256 bottomInteger;
// icoDuration < 115,200 blocks = 20 days
if (icoDuration < 115200){
return currentPrice.bottomInteger;
}
... | 0.4.23 |
// "Public" Management - set address of base and reward tokens.
//
// Can only be done once (normally immediately after creation) by the fee collector.
//
// Used instead of a constructor to make deployment easier.
// | function init(ERC20 _baseToken, ERC20 _rwrdToken) public {
require(msg.sender == feeCollector);
require(address(baseToken) == 0);
require(address(_baseToken) != 0);
require(address(rwrdToken) == 0);
require(address(_rwrdToken) != 0);
// attempt to catch bad tokens:
require(_baseToken.... | 0.4.11 |
// Public Info View - what is being traded here, what are the limits?
// | function getBookInfo() public constant returns (
BookType _bookType, address _baseToken, address _rwrdToken,
uint _baseMinInitialSize, uint _cntrMinInitialSize,
uint _feeDivisor, address _feeCollector
) {
return (
BookType.ERC20EthV1,
address(baseToken),
address(rwrdT... | 0.4.11 |
// Public Funds View - get balances held by contract on behalf of the client,
// or balances approved for deposit but not yet claimed by the contract.
//
// Excludes funds in open orders.
//
// Helps a web ui get a consistent snapshot of balances.
//
// It would be nice to return the off-exchange ETH balance too but th... | function getClientBalances(address client) public constant returns (
uint bookBalanceBase,
uint bookBalanceCntr,
uint bookBalanceRwrd,
uint approvedBalanceBase,
uint approvedBalanceRwrd,
uint ownBalanceBase,
uint ownBalanceRwrd
) {
bookBalanceBase = balanceBase... | 0.4.11 |
// Public Funds Manipulation - deposit previously-approved base tokens.
// | function transferFromBase() public {
address client = msg.sender;
address book = address(this);
// we trust the ERC20 token contract not to do nasty things like call back into us -
// if we cannot trust the token then why are we allowing it to be traded?
uint amountBase = baseToken.allowance(cl... | 0.4.11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.