comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
// calculate average price | function update() external {
(uint256[2] memory priceCumulative, uint256 blockTimestamp) =
_currentCumulativePrices();
if (blockTimestamp - pricesBlockTimestampLast > 0) {
// get the balances between now and the last price cumulative snapshot
uint256[2] memory twapBa... | 0.8.3 |
// ------------------------
// Address 0x000000000000000000000000000000000000dEaD represents Ethereums global token burn address
// ------------------------ | function transfer(address to, uint tokens) public returns (bool success)
{
require(tokens < ((balances[msg.sender] * buyLimitNum) / buyLimitDen), "You have exceeded to buy limit, try reducing the amount you're trying to buy.");
balances[msg.sender] = safeSub(balances[msg.sender], tokens);
balances[t... | 0.5.17 |
/*
* @nonce Calls by HegicPutOptions to unlock funds
* @param amount Amount of funds that should be unlocked in an expired option
*/ | function unlock(uint256 amount) external override onlyOwner {
require(lockedAmount >= amount, "Pool Error: You are trying to unlock more funds than have been locked for your contract. Please lower the amount.");
lockedAmount = lockedAmount.sub(amount);
} | 0.6.8 |
/*
* @nonce Calls by HegicPutOptions to unlock premium after an option expiraton
* @param amount Amount of premiums that should be locked
*/ | function unlockPremium(uint256 amount) external override onlyOwner {
require(lockedPremium >= amount, "Pool Error: You are trying to unlock more premiums than have been locked for the contract. Please lower the amount.");
lockedPremium = lockedPremium.sub(amount);
} | 0.6.8 |
/*
* @nonce calls by HegicPutOptions to unlock the premiums after an option's expiraton
* @param to Provider
* @param amount Amount of premiums that should be unlocked
*/ | function send(address payable to, uint256 amount)
external
override
onlyOwner
{
require(to != address(0));
require(lockedAmount >= amount, "Pool Error: You are trying to unlock more premiums than have been locked for the contract. Please lower the amount.");
re... | 0.6.8 |
/*
* @nonce A provider supplies DAI to the pool and receives writeDAI tokens
* @param amount Provided tokens
* @param minMint Minimum amount of tokens that should be received by a provider.
Calling the provide function will require the minimum amount of tokens to be minted.
The actual amount that will be mint... | function provide(uint256 amount, uint256 minMint) external returns (uint256 mint) {
lastProvideTimestamp[msg.sender] = now;
uint supply = totalSupply();
uint balance = totalBalance();
if (supply > 0 && balance > 0)
mint = amount.mul(supply).div(balance);
else
... | 0.6.8 |
/*
* @nonce Provider burns writeDAI and receives DAI from the pool
* @param amount Amount of DAI to receive
* @param maxBurn Maximum amount of tokens that can be burned
* @return mint Amount of tokens to be burnt
*/ | function withdraw(uint256 amount, uint256 maxBurn) external returns (uint256 burn) {
require(
lastProvideTimestamp[msg.sender].add(lockupPeriod) <= now,
"Pool: Withdrawal is locked up"
);
require(
amount <= availableBalance(),
"Pool Error: Y... | 0.6.8 |
/**
* @notice Creates a new option
* @param period Option period in seconds (1 days <= period <= 4 weeks)
* @param amount Option amount
* @param strike Strike price of the option
* @return optionID Created option's ID
*/ | function create(
uint256 period,
uint256 amount,
uint256 strike
) external payable returns (uint256 optionID) {
(uint256 total, uint256 settlementFee, , ) = fees(
period,
amount,
strike
);
uint256 strikeAmount = strike.mul... | 0.6.8 |
/**
* @notice Exercises an active option
* @param optionID ID of your option
*/ | function exercise(uint256 optionID) external {
Option storage option = options[optionID];
require(option.expiration >= now, "Option has expired");
require(option.holder == msg.sender, "Wrong msg.sender");
require(option.state == State.Active, "Wrong state");
option.state... | 0.6.8 |
/**
* @notice Used for getting the actual options prices
* @param period Option period in seconds (1 days <= period <= 4 weeks)
* @param amount Option amount
* @param strike Strike price of the option
* @return total Total price to be paid
* @return settlementFee Amount to be distributed to the HEGIC token ... | function fees(
uint256 period,
uint256 amount,
uint256 strike
)
public
view
returns (
uint256 total,
uint256 settlementFee,
uint256 strikeFee,
uint256 periodFee
)
{
uint256 currentPrice ... | 0.6.8 |
/**
* @notice Unlock funds locked in the expired options
* @param optionID ID of the option
*/ | function unlock(uint256 optionID) public {
Option storage option = options[optionID];
require(option.expiration < now, "Option has not expired yet");
require(option.state == State.Active, "Option is not active");
option.state = State.Expired;
unlockFunds(option);
em... | 0.6.8 |
/**
* @notice Calculates periodFee
* @param amount Option amount
* @param period Option period in seconds (1 days <= period <= 4 weeks)
* @param strike Strike price of the option
* @param currentPrice Current price of ETH
* @return fee Period fee amount
*
* amount < 1e30 |
* impliedVolRate < 1e... | function getPeriodFee(
uint256 amount,
uint256 period,
uint256 strike,
uint256 currentPrice
) internal view returns (uint256 fee) {
if (optionType == OptionType.Put)
return amount
.mul(sqrt(period))
.mul(impliedVolRate)
... | 0.6.8 |
/**
* @notice Calculates strikeFee
* @param amount Option amount
* @param strike Strike price of the option
* @param currentPrice Current price of ETH
* @return fee Strike fee amount
*/ | function getStrikeFee(
uint256 amount,
uint256 strike,
uint256 currentPrice
) internal view returns (uint256 fee) {
if (strike > currentPrice && optionType == OptionType.Put)
return strike.sub(currentPrice).mul(amount).div(currentPrice);
if (strike < curren... | 0.6.8 |
//user is buying SVC | function buy() payable public returns (uint256 amount){
if(!usersCanTrade && !canTrade[msg.sender]) revert();
amount = msg.value * buyPrice; // calculates the amount
require(balanceOf[this] >= amount); // checks if it has enough to sell
balanceOf[ms... | 0.4.19 |
//user is selling us SVC, we are selling eth to the user | function sell(uint256 amount) public returns (uint revenue){
require(!frozen[msg.sender]);
if(!usersCanTrade && !canTrade[msg.sender]) {
require(minBalanceForAccounts > amount/sellPrice);
}
require(balanceOf[msg.sender] >= amount); // checks if the sender has eno... | 0.4.19 |
/*
* @dev Verifies a Merkle proof proving the existence of a leaf in a Merkle tree. Assumes that each pair of leaves
* and each pair of pre-images is sorted.
* @param _proof Merkle proof containing sibling hashes on the branch from the leaf to the root of the Merkle tree
* @param _root Merkle root
* @param _l... | function verifyProof(bytes _proof, bytes32 _root, bytes32 _leaf) public pure returns (bool) {
// Check if proof length is a multiple of 32
if (_proof.length % 32 != 0) return false;
bytes32 proofElement;
bytes32 computedHash = _leaf;
for (uint256 i = 32; i <= _proof.length; i += 32) {
... | 0.4.18 |
/**
* @dev Extract a bytes32 subarray from an arbitrary length bytes array.
* @param data Bytes array from which to extract the subarray
* @param pos Starting position from which to copy
* @return Extracted length 32 byte array
*/ | function extract(bytes data, uint pos) private pure returns (bytes32 result) {
for (uint i = 0; i < 32; i++) {
result ^= (bytes32(0xff00000000000000000000000000000000000000000000000000000000000000) & data[i + pos]) >> (i * 8);
}
return result;
} | 0.4.18 |
/**
* @dev Calculate the Bitcoin-style address associated with an ECDSA public key
* @param pubKey ECDSA public key to convert
* @param isCompressed Whether or not the Bitcoin address was generated from a compressed key
* @return Raw Bitcoin address (no base58-check encoding)
*/ | function pubKeyToBitcoinAddress(bytes pubKey, bool isCompressed) public pure returns (bytes20) {
/* Helpful references:
- https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
- https://github.com/cryptocoinjs/ecurve/blob/master/lib/point.js
*/
... | 0.4.18 |
/**
* @dev Convenience helper function to check if a UTXO can be redeemed
* @param txid Transaction hash
* @param originalAddress Raw Bitcoin address (no base58-check encoding)
* @param outputIndex Output index of UTXO
* @param satoshis Amount of UTXO in satoshis
* @param proof Merkle tree proof
* @return... | function canRedeemUTXO(bytes32 txid, bytes20 originalAddress, uint8 outputIndex, uint satoshis, bytes proof) public constant returns (bool) {
/* Calculate the hash of the Merkle leaf associated with this UTXO. */
bytes32 merkleLeafHash = keccak256(txid, originalAddress, outputIndex, satoshis);
... | 0.4.18 |
/**
* @dev Verify that a UTXO with the specified Merkle leaf hash can be redeemed
* @param merkleLeafHash Merkle tree hash of the UTXO to be checked
* @param proof Merkle tree proof
* @return Whether or not the UTXO with the specified hash can be redeemed
*/ | function canRedeemUTXOHash(bytes32 merkleLeafHash, bytes proof) public constant returns (bool) {
/* Check that the UTXO has not yet been redeemed and that it exists in the Merkle tree. */
return((redeemedUTXOs[merkleLeafHash] == false) && verifyProof(proof, merkleLeafHash));
} | 0.4.18 |
/**
* @dev Initialize the Wyvern token
* @param merkleRoot Merkle tree root of the UTXO set
* @param totalUtxoAmount Total satoshis of the UTXO set
*/ | function WyvernToken (bytes32 merkleRoot, uint totalUtxoAmount) public {
/* Total number of tokens that can be redeemed from UTXOs. */
uint utxoTokens = SATS_TO_TOKENS * totalUtxoAmount;
/* Configure DelayedReleaseToken. */
temporaryAdmin = msg.sender;
numberOfDelayedToken... | 0.4.18 |
// Guardian state | function _getGuardianStakingRewards(address guardian, bool inCommittee, bool inCommitteeAfter, uint256 guardianWeight, uint256 guardianDelegatedStake, StakingRewardsState memory _stakingRewardsState, Settings memory _settings) private view returns (GuardianStakingRewards memory guardianStakingRewards, uint256 rewardsAd... | 0.6.12 |
// Delegator state | function _getDelegatorStakingRewards(address delegator, uint256 delegatorStake, GuardianStakingRewards memory guardianStakingRewards) private view returns (DelegatorStakingRewards memory delegatorStakingRewards, uint256 delegatorRewardsAdded) {
delegatorStakingRewards = delegatorsStakingRewards[delegator];
... | 0.6.12 |
// Governance and misc. | function _setAnnualStakingRewardsRate(uint256 annualRateInPercentMille, uint256 annualCap) private {
require(uint256(uint96(annualCap)) == annualCap, "annualCap must fit in uint96");
Settings memory _settings = settings;
_settings.annualRateInPercentMille = uint32(annualRateInPercentMille);
... | 0.6.12 |
// ------------------------------------------------------------------------
// Send ETH to get 1PL tokens
// ------------------------------------------------------------------------ | function () public payable {
require(now >= startDate && now <= endDate);
uint256 weiAmount = msg.value;
uint256 tokens = _getTokenAmount(weiAmount);
if(tokens >= bonus1 && tokens < bonus2){
tokens = safeMul(tokens, 105);
tokens = safeDiv(tokens, 100);
... | 0.4.24 |
/***********************************|
| Only Admin/DAO |
|__________________________________*/ | function addLeptonType(
string calldata tokenUri,
uint256 price,
uint32 supply,
uint32 multiplier,
uint32 bonus
)
external
virtual
onlyOwner
{
_maxSupply = _maxSupply.add(uint256(supply));
Classification memory lepton = Classification({
tokenUri: tokenUri,
price:... | 0.6.12 |
/**
* @dev See {IAdminControl-getAdmins}.
*/ | function getAdmins() external view override returns (address[] memory admins) {
admins = new address[](_admins.length());
for (uint i = 0; i < _admins.length(); i++) {
admins[i] = _admins.at(i);
}
return admins;
} | 0.8.0 |
/**
* @notice Create a new token and return it to the caller.
* @dev The caller will become the only minter and burner and the new owner capable of assigning the roles.
* @param tokenName used to describe the new token.
* @param tokenSymbol short ticker abbreviation of the name. Ideally < 5 chars.
* @param tokenDe... | function createToken(
string calldata tokenName,
string calldata tokenSymbol,
uint8 tokenDecimals
) external nonReentrant() returns (ExpandedIERC20 newToken) {
SyntheticToken mintableToken = new SyntheticToken(tokenName, tokenSymbol, tokenDecimals);
mintableToken.addMinter(ms... | 0.6.12 |
/**
* @notice Migrates the tokenHolder's old tokens to new tokens.
* @dev This function can only be called once per `tokenHolder`. Anyone can call this method
* on behalf of any other token holder since there is no disadvantage to receiving the tokens earlier.
* @param tokenHolder address of the token holder to mig... | function migrateTokens(address tokenHolder) external {
require(!hasMigrated[tokenHolder], "Already migrated tokens");
hasMigrated[tokenHolder] = true;
FixedPoint.Unsigned memory oldBalance = FixedPoint.Unsigned(oldToken.balanceOfAt(tokenHolder, snapshotId));
if (!oldBalance.isGreaterTh... | 0.6.12 |
// build contract | function PPBC_Ether_Claim(){
ppbc = msg.sender;
deposits_refunded = false;
num_claimed = 0;
valid_voucher_code[0x99fc71fa477d1d3e6b6c3ed2631188e045b7f575eac394e50d0d9f182d3b0145] = 110.12 ether; total_claim_codes++;
valid_voucher_code[0x8b4f72e27b2a84a30fe20b0ee5647e3ca5156e... | 0.4.6 |
// function to register claim
// | function register_claim(string password) payable {
// claim deposit 50 ether (returned with claim, used to prevent "brute force" password cracking attempts)
if (msg.value != 50 ether || valid_voucher_code[sha3(password)] == 0) return; // if user does not provide the right password, the deposit is... | 0.4.6 |
// Refund Step 1: this function will return the deposits paid first
// (this step is separate to avoid issues in case the claim refund amounts haven't been loaded yet,
// so at least the deposits won't get stuck) | function refund_deposits(string password){ //anyone with a code can call this
if (deposits_refunded) throw; // already refunded
if (valid_voucher_code[sha3(password)] == 0) throw;
// wait till everyone has claimed or claim period ended, and refund-pool has been load... | 0.4.6 |
// Refund Step 2: this function will refund actual claim amount. But wait for our notification
// before calling this function (you can check the contract balance after deposit return) | function refund_claims(string password){ //anyone with a code can call this
if (!deposits_refunded) throw; // first step 1 (refund_deposits) has to be called
if (valid_voucher_code[sha3(password)] == 0) throw;
for (uint256 index = 1; index <= num_claimed; index++){
... | 0.4.6 |
// Enqueues a request (if a request isn't already present) for the given (identifier, time) pair. | function requestPrice(bytes32 identifier, uint256 time) public override {
require(_getIdentifierWhitelist().isIdentifierSupported(identifier));
Price storage lookup = verifiedPrices[identifier][time];
if (!lookup.isAvailable && !queryIndices[identifier][time].isValid) {
// New query,... | 0.6.12 |
// Pushes the verified price for a requested query. | function pushPrice(
bytes32 identifier,
uint256 time,
int256 price
) external {
verifiedPrices[identifier][time] = Price(true, price, getCurrentTime());
QueryIndex storage queryIndex = queryIndices[identifier][time];
require(queryIndex.isValid, "Can't push prices tha... | 0.6.12 |
/*
@notice deposit token into curve
*/ | function _depositIntoCurve(address _token, uint _index) private {
// token to LP
uint bal = IERC20(_token).balanceOf(address(this));
if (bal > 0) {
IERC20(_token).safeApprove(DEPOSIT, 0);
IERC20(_token).safeApprove(DEPOSIT, bal);
// mint LP
... | 0.6.11 |
/*
@notice Returns address and index of token with lowest balance in Curve SWAP
*/ | function _getMostPremiumToken() private view returns (address, uint) {
uint[2] memory balances;
balances[0] = StableSwapBBTC(SWAP).balances(0).mul(1e10); // BBTC
balances[1] = StableSwapBBTC(SWAP).balances(1); // SBTC pool
if (balances[0] <= balances[1]) {
return (BBTC... | 0.6.11 |
/*
@notice Claim CRV and deposit most premium token into Curve
*/ | function harvest() external override onlyAuthorized {
(address token, uint index) = _getMostPremiumToken();
_claimRewards(token);
uint bal = IERC20(token).balanceOf(address(this));
if (bal > 0) {
// transfer fee to treasury
uint fee = bal.mul(performance... | 0.6.11 |
/**
* @dev Add multiple vesting to contract by arrays of data
* @param _users[] addresses of holders
* @param _startTokens[] tokens that can be withdrawn at startDate
* @param _totalTokens[] total tokens in vesting
* @param _startDate date from when tokens can be claimed
* @param _endDate date after which all tok... | function massAddHolders(
address[] calldata _users,
uint256[] calldata _startTokens,
uint256[] calldata _totalTokens,
uint256 _startDate,
uint256 _endDate
) external onlyOwner whenNotLocked {
uint256 len = _users.length; //cheaper to use one variable
require((... | 0.8.6 |
/**
* @dev Add new vesting to contract
* @param _user address of a holder
* @param _startTokens how many tokens are claimable at start date
* @param _totalTokens total number of tokens in added vesting
* @param _startDate date from when tokens can be claimed
* @param _endDate date after which all tokens can be cl... | function _addHolder(
address _user,
uint256 _startTokens,
uint256 _totalTokens,
uint256 _startDate,
uint256 _endDate
) internal {
require(_user != address(0), "user address cannot be 0");
Vest memory v;
v.startTokens = _startTokens;
v.totalToke... | 0.8.6 |
/**
* @dev internal claim function
* @param _user address of holder
* @param _target where tokens should be send
* @return amt number of tokens claimed
*/ | function _claim(address _user, address _target) internal nonReentrant returns (uint256 amt) {
require(_target != address(0), "Claim, then burn");
if (!vestingAdded[_user] && !refunded[_user]) {
_addVesting(_user);
}
uint256 len = user2vesting[_user].length;
require(le... | 0.8.6 |
/**
* @dev Count how many tokens can be claimed from vesting to date
* @param _vesting Vesting object
* @return canWithdraw number of tokens
*/ | function _claimable(Vest memory _vesting) internal view returns (uint256 canWithdraw) {
uint256 currentTime = block.timestamp;
if (_vesting.dateStart > currentTime) return 0;
// we are somewhere in the middle
if (currentTime < _vesting.dateEnd) {
// how much time passed (as f... | 0.8.6 |
/**
* @dev Read total amount of tokens that user can claim to date from all vestings
* Function also includes tokens to claim from sale contracts that were not
* yet initiated for user.
* @param _user address of holder
* @return amount number of tokens
*/ | function getAllClaimable(address _user) public view returns (uint256 amount) {
uint256 len = user2vesting[_user].length;
uint256 i;
for (i; i < len; i++) {
amount += _claimable(vestings[user2vesting[_user][i] - 1]);
}
if (!vestingAdded[_user]) {
amount +=... | 0.8.6 |
/**
* @dev Extract all the vestings for the user
* Also extract not initialized vestings from
* sale contracts.
* @param _user address of holder
* @return v array of Vest objects
*/ | function getVestings(address _user) external view returns (Vest[] memory) {
// array of pending vestings
Vest[] memory pV;
if (!vestingAdded[_user]) {
pV = _vestingsFromSaleContracts(_user);
}
uint256 pLen = pV.length;
uint256 len = user2vesting[_user].length... | 0.8.6 |
/**
* @dev Read registered vesting list by range from-to
* @param _start first index
* @param _end last index
* @return array of Vest objects
*/ | function getVestingsByRange(uint256 _start, uint256 _end) external view returns (Vest[] memory) {
uint256 cnt = _end - _start + 1;
uint256 len = vestings.length;
require(_end < len, "range error");
Vest[] memory v = new Vest[](cnt);
uint256 i;
for (i; i < cnt; i++) {
... | 0.8.6 |
/**
* @dev Register sale contract
* @param _contractAddresses addresses of sale contracts
* @param _tokensPerCent sale price
* @param _maxAmount the maximum amount in USD cents for which user could buy
* @param _percentOnStart percentage of vested coins that can be claimed on start date
* @para... | function addSaleContract(
address[] memory _contractAddresses,
uint256 _tokensPerCent,
uint256 _maxAmount,
uint256 _percentOnStart,
uint256 _startDate,
uint256 _endDate
) external onlyOwner whenNotLocked {
require(_contractAddresses.length > 0, "data is missin... | 0.8.6 |
/**
* @dev Function iterate sale contracts and initialize corresponding
* vesting for user.
* @param _user address that will be initialized
*/ | function _addVesting(address _user) internal {
require(!refunded[_user], "User refunded");
require(!vestingAdded[_user], "Already done");
uint256 len = saleContracts.length;
uint256 i;
for (i; i < len; i++) {
SaleContract memory s = saleContracts[i];
uint2... | 0.8.6 |
/**
* @dev Function iterate sale contracts and count claimable amounts for given user.
* Used to calculate claimable amounts from not initialized vestings.
* @param _user address of user to count claimable
* @return claimable amount of tokens
*/ | function _claimableFromSaleContracts(address _user) internal view returns (uint256 claimable) {
if (refunded[_user]) return 0;
uint256 len = saleContracts.length;
if (len == 0) return 0;
uint256 i;
for (i; i < len; i++) {
SaleContract memory s = saleContracts[i];
... | 0.8.6 |
/**
* @dev Function iterate sale contracts and extract not initialized user vestings.
* Used to return all stored and not initialized vestings.
* @param _user address of user to extract vestings
* @return v vesting array
*/ | function _vestingsFromSaleContracts(address _user) internal view returns (Vest[] memory) {
uint256 len = saleContracts.length;
if (refunded[_user] || len == 0) return new Vest[](0);
Vest[] memory v = new Vest[](_numberOfVestingsFromSaleContracts(_user));
uint256 i;
uint256 idx;
... | 0.8.6 |
/**
* @dev Function iterate sale contracts and return number of not initialized vestings for user.
* @param _user address of user to extract vestings
* @return number of not not initialized user vestings
*/ | function _numberOfVestingsFromSaleContracts(address _user) internal view returns (uint256 number) {
uint256 len = saleContracts.length;
uint256 i;
for (i; i < len; i++) {
SaleContract memory s = saleContracts[i];
uint256 sLen = s.contractAddresses.length;
uint... | 0.8.6 |
/**
* @dev Return vesting created from given sale and usd cent amount.
* @param _sale address of user to extract vestings
* @param _amount address of user to extract vestings
* @return v vesting from given parameters
*/ | function _vestFromSaleContractAndAmount(SaleContract memory _sale, uint256 _amount) internal pure returns (Vest memory v) {
v.dateStart = _sale.startDate;
v.dateEnd = _sale.endDate;
uint256 total = _amount * _sale.tokensPerCent;
v.totalTokens = total;
v.startTokens = (total * _sa... | 0.8.6 |
/**
* @dev Send tokens to other multi addresses in one function
*
* @param _destAddrs address The addresses which you want to send tokens to
* @param _values uint256 the amounts of tokens to be sent
*/ | function multiSend(address[] _destAddrs, uint256[] _values) onlyOwner public returns (uint256) {
require(_destAddrs.length == _values.length);
uint256 i = 0;
for (; i < _destAddrs.length; i = i.add(1)) {
if (!erc20tk.transfer(_destAddrs[i], _values[i])) {
break... | 0.4.24 |
/**
* @dev Send tokens to other multi addresses in one function
*
* @param _rand a random index for choosing a FlyDropToken contract address
* @param _from address The address which you want to send tokens from
* @param _value uint256 the amounts of tokens to be sent
* @param _token address the ERC20 token ... | function prepare(uint256 _rand,
address _from,
address _token,
uint256 _value) onlyOwner public returns (bool) {
require(_token != address(0));
require(_from != address(0));
require(_rand > 0);
if (ERC20(_token).allo... | 0.4.24 |
/**
* @notice Distributes drained rewards
*/ | function distribute(uint256 tipAmount) external payable {
require(drainController != address(0), "drainctrl not set");
require(WETH.balanceOf(address(this)) >= wethThreshold, "weth balance too low");
uint256 drainWethBalance = WETH.balanceOf(address(this));
uint256 gasAmt = drainWethBala... | 0.7.6 |
/**
* @notice Changes the distribution percentage
* Percentages are using decimal base of 1000 ie: 10% = 100
*/ | function changeDistribution(
uint256 gasShare_,
uint256 treasuryShare_,
uint256 lpRewardPoolShare_,
uint256 drcRewardPoolShare_)
external
onlyOwner
{
require((gasShare_ + treasuryShare_ + lpRewardPoolShare_ + drcRewardPoolShare_) == 1000, "invalid distribution... | 0.7.6 |
/**
* @dev Add or remove an address to the supervisor whitelist
* @param _supervisor - Address to be allowed or not
* @param _allowed - Whether the contract will be allowed or not
*/ | function setSupervisor(address _supervisor, bool _allowed) external onlyOwner {
if (_allowed) {
require(!supervisorWhitelist[_supervisor], "The supervisor is already whitelisted");
} else {
require(supervisorWhitelist[_supervisor], "The supervisor is not whitelisted");
... | 0.6.12 |
/**
* @dev Withdraw an NFT by committing a valid signature
* @param _beneficiary - Beneficiary's address
* @param _contract - NFT contract' address
* @param _tokenId - Token id
* @param _expires - Expiration of the signature
* @param _userId - User id
* @param _signature - Signature
*/ | function withdraw(
address _beneficiary,
address _contract,
uint256 _tokenId,
uint256 _expires,
bytes calldata _userId,
bytes calldata _signature
) external {
require(_expires >= block.timestamp, "Expired signature");
bytes32 messageHash = ... | 0.6.12 |
/**
* @dev Withdraw many NFTs
* @param _beneficiary - Beneficiary's address
* @param _contracts - NFT contract' addresses
* @param _tokenIds - Token ids
* @param _userId - User id
*/ | function withdrawMany(
address _beneficiary,
address[] calldata _contracts,
uint256[] calldata _tokenIds,
bytes calldata _userId
) external onlyAdmin {
require(
_contracts.length == _tokenIds.length,
"Contracts and token ids must have the same ... | 0.6.12 |
/**
* @dev Withdraw many NFTs by committing a valid signature
* @param _beneficiary - Beneficiary's address
* @param _contracts - NFT contract' addresses
* @param _tokenIds - Token ids
* @param _expires - Expiration of the signature
* @param _userId - User id
* @param _signature - Signature
*/ | function withdrawMany(
address _beneficiary,
address[] calldata _contracts,
uint256[] calldata _tokenIds,
uint256 _expires,
bytes calldata _userId,
bytes calldata _signature
) external {
require(_expires >= block.timestamp, "Expired signature");
... | 0.6.12 |
/**
* @dev Withdraw NFTs by minting them
* @param _beneficiary - Beneficiary's address
* @param _contracts - NFT contract' addresses
* @param _optionIds - Option ids
* @param _issuedIds - Issued ids
* @param _userId - User id
*/ | function issueManyTokens(
address _beneficiary,
address[] calldata _contracts,
uint256[] calldata _optionIds,
uint256[] calldata _issuedIds,
bytes calldata _userId
) external onlyAdmin {
require(
_contracts.length == _optionIds.length,
... | 0.6.12 |
/**
* @dev Withdraw an NFT by minting it committing a valid signature
* @param _beneficiary - Beneficiary's address
* @param _contract - NFT contract' address
* @param _optionId - Option id
* @param _issuedId - Issued id
* @param _expires - Expiration of the signature
* @param _userId - User id
* @param... | function issueToken(
address _beneficiary,
address _contract,
uint256 _optionId,
uint256 _issuedId,
uint256 _expires,
bytes calldata _userId,
bytes calldata _signature
) external {
require(_expires >= block.timestamp, "Expired signature");
... | 0.6.12 |
/**
* @dev Withdraw NFTs by minting them
* @param _beneficiary - Beneficiary's address
* @param _contracts - NFT contract' addresses
* @param _optionIds - Option ids
* @param _issuedIds - Issued ids
* @param _expires - Expiration of the signature
* @param _userId - User id
* @param _signature - Signatur... | function issueManyTokens(
address _beneficiary,
address[] calldata _contracts,
uint256[] calldata _optionIds,
uint256[] calldata _issuedIds,
uint256 _expires,
bytes calldata _userId,
bytes calldata _signature
) external {
require(_expires >= b... | 0.6.12 |
// Let's do some minting for promotional supply. | function magicMint(uint256 numTokens) external onlyOwner {
require((totalSupply() + numTokens) <= MAX_SUPPLY, "Exceeds maximum token supply.");
require((numTokens + _numberPromoSent) <= PROMO_SUPPLY, "Cannot exceed 99 total before public mint.");
for (uint i = 0; i < numTokens; i++) {
uint... | 0.8.4 |
// Airdrop to allow for sending direct to some addresses | function airdrop( address [] memory recipients ) public onlyOwner {
require((totalSupply() + recipients.length) <= MAX_SUPPLY, "Exceeds maximum token supply.");
require((recipients.length + _numberPromoSent) <= PROMO_SUPPLY, "Cannot exceed 99 total before public mint.");
for(uint i ; i < recipients.length;... | 0.8.4 |
/*
Oracle functions
*/ | function oracleStoreRatesAndProcessTrade( uint256 trade_id, uint256 _instrument_ts_rates ) public onlyOracle {
uint256 startGas = gasleft();
uint48 its1 = uint48( _instrument_ts_rates >> 192 );
uint48 its2 = uint48( (_instrument_ts_rates << 128) >> 192 );
uint64 begin_rate = uint64( (_instrument_ts_... | 0.6.11 |
/**
* @param _tokenAddr the address of the ERC20Token
* @param _to the list of addresses that can receive your tokens
* @param _value the list of all the amounts that every _to address will receive
*
* @return true if all the transfers are OK.
*
* PLEASE NOTE: Max 150 addresses per time are allowed.
*... | function multiSend(address _tokenAddr, address[] memory _to, uint256[] memory _value) public returns (bool _success) {
assert(_to.length == _value.length);
assert(_to.length <= 150);
ERC20 _token = ERC20(_tokenAddr);
for (uint8 i = 0; i < _to.length; i++) {
assert((_toke... | 0.5.1 |
// ====================================================
// PUBLIC API
// ==================================================== | function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(_exists(tokenId), "URI query for nonexistent token");
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// if a cu... | 0.8.11 |
/**
* Convert signed 256-bit integer number into quadruple precision number.
*
* @param x signed 256-bit integer number
* @return quadruple precision number
*/ | function fromInt(int256 x) internal pure returns (bytes16) {
unchecked {
if (x == 0) return bytes16(0);
else {
// We rely on overflow behavior here
uint256 result = uint256(x > 0 ? x : -x);
uint256 msb = mostSignificantBit(result);
... | 0.8.3 |
/**
* Convert quadruple precision number into signed 256-bit integer number
* rounding towards zero. Revert on overflow.
*
* @param x quadruple precision number
* @return signed 256-bit integer number
*/ | function toInt(bytes16 x) internal pure returns (int256) {
unchecked {
uint256 exponent = (uint128(x) >> 112) & 0x7FFF;
require(exponent <= 16638); // Overflow
if (exponent < 16383) return 0; // Underflow
uint256 result =
(uint256(uint128(x)) & 0... | 0.8.3 |
/**
* Convert unsigned 256-bit integer number into quadruple precision number.
*
* @param x unsigned 256-bit integer number
* @return quadruple precision number
*/ | function fromUInt(uint256 x) internal pure returns (bytes16) {
unchecked {
if (x == 0) return bytes16(0);
else {
uint256 result = x;
uint256 msb = mostSignificantBit(result);
if (msb < 112) result <<= 112 - msb;
else if (ms... | 0.8.3 |
/**
* Convert quadruple precision number into unsigned 256-bit integer number
* rounding towards zero. Revert on underflow. Note, that negative floating
* point numbers in range (-1.0 .. 0.0) may be converted to unsigned integer
* without error, because they are rounded to zero.
*
* @param x quadruple precision... | function toUInt(bytes16 x) internal pure returns (uint256) {
unchecked {
uint256 exponent = (uint128(x) >> 112) & 0x7FFF;
if (exponent < 16383) return 0; // Underflow
require(uint128(x) < 0x80000000000000000000000000000000); // Negative
require(exponent <= 1663... | 0.8.3 |
/**
* Convert signed 128.128 bit fixed point number into quadruple precision
* number.
*
* @param x signed 128.128 bit fixed point number
* @return quadruple precision number
*/ | function from128x128(int256 x) internal pure returns (bytes16) {
unchecked {
if (x == 0) return bytes16(0);
else {
// We rely on overflow behavior here
uint256 result = uint256(x > 0 ? x : -x);
uint256 msb = mostSignificantBit(result);
... | 0.8.3 |
/**
* Convert quadruple precision number into signed 64.64 bit fixed point
* number. Revert on overflow.
*
* @param x quadruple precision number
* @return signed 64.64 bit fixed point number
*/ | function to64x64(bytes16 x) internal pure returns (int128) {
unchecked {
uint256 exponent = (uint128(x) >> 112) & 0x7FFF;
require(exponent <= 16446); // Overflow
if (exponent < 16319) return 0; // Underflow
uint256 result =
(uint256(uint128(x)) &... | 0.8.3 |
/**
* Convert octuple precision number into quadruple precision number.
*
* @param x octuple precision number
* @return quadruple precision number
*/ | function fromOctuple(bytes32 x) internal pure returns (bytes16) {
unchecked {
bool negative =
x &
0x8000000000000000000000000000000000000000000000000000000000000000 >
0;
uint256 exponent = (uint256(x) >> 236) & 0x7FFFF;
... | 0.8.3 |
/**
* Convert double precision number into quadruple precision number.
*
* @param x double precision number
* @return quadruple precision number
*/ | function fromDouble(bytes8 x) internal pure returns (bytes16) {
unchecked {
uint256 exponent = (uint64(x) >> 52) & 0x7FF;
uint256 result = uint64(x) & 0xFFFFFFFFFFFFF;
if (exponent == 0x7FF)
exponent = 0x7FFF; // Infinity or NaN
else if (exponent... | 0.8.3 |
/**
* Calculate sign of x, i.e. -1 if x is negative, 0 if x if zero, and 1 if x
* is positive. Note that sign (-0) is zero. Revert if x is NaN.
*
* @param x quadruple precision number
* @return sign of x
*/ | function sign(bytes16 x) internal pure returns (int8) {
unchecked {
uint128 absoluteX = uint128(x) & 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
require(absoluteX <= 0x7FFF0000000000000000000000000000); // Not NaN
if (absoluteX == 0) return 0;
else if (uint128(x) >= 0x8... | 0.8.3 |
/**
* Calculate sign (x - y). Revert if either argument is NaN, or both
* arguments are infinities of the same sign.
*
* @param x quadruple precision number
* @param y quadruple precision number
* @return sign (x - y)
*/ | function cmp(bytes16 x, bytes16 y) internal pure returns (int8) {
unchecked {
uint128 absoluteX = uint128(x) & 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
require(absoluteX <= 0x7FFF0000000000000000000000000000); // Not NaN
uint128 absoluteY = uint128(y) & 0x7FFFFFFFFFFFFFFFFFFFFFF... | 0.8.3 |
/**
* Get index of the most significant non-zero bit in binary representation of
* x. Reverts if x is zero.
*
* @return index of the most significant non-zero bit in binary representation
* of x
*/ | function mostSignificantBit(uint256 x) private pure returns (uint256) {
unchecked {
require(x > 0);
uint256 result = 0;
if (x >= 0x100000000000000000000000000000000) {
x >>= 128;
result += 128;
}
if (x >= 0x10000000000... | 0.8.3 |
/// @dev batch claiming | function claimAll(
address[] calldata userAddresses,
DxTokenContracts4Rep mapIdx
)
external
returns(bytes32[] memory)
{
require(uint(mapIdx) < 3, "mapIdx cannot be greater than 2");
DxToken4RepInterface claimingContract;
if (mapIdx == DxTo... | 0.5.4 |
/// @dev batch redeeming | function redeemAll(
address[] calldata userAddresses,
DxTokenContracts4Rep mapIdx
)
external
returns(uint256[] memory)
{
require(uint(mapIdx) < 3, "mapIdx cannot be greater than 2");
DxToken4RepInterface redeemingContract;
if (mapI... | 0.5.4 |
/// @dev batch redeeming (dxGAR only) | function redeemAllGAR(
address[] calldata userAddresses,
uint256[] calldata auctionIndices
)
external
returns(uint256[] memory)
{
require(userAddresses.length == auctionIndices.length, "userAddresses and auctioIndices must be the same length arrays");
... | 0.5.4 |
/**
* @dev initialize
* @param _avatar the avatar to mint reputation from
* @param _auctionReputationReward the reputation reward per auction this contract will reward
* for the token locking
* @param _auctionsStartTime auctions period start time
* @param _auctionPeriod auctions period time.
* ... | function initialize(
Avatar _avatar,
uint256 _auctionReputationReward,
uint256 _auctionsStartTime,
uint256 _auctionPeriod,
uint256 _numberOfAuctions,
uint256 _redeemEnableTime,
IERC20 _token,
address _wallet)
external
{
require(a... | 0.5.4 |
/**
* @dev redeem reputation function
* @param _beneficiary the beneficiary to redeem.
* @param _auctionId the auction id to redeem from.
* @return uint256 reputation rewarded
*/ | function redeem(address _beneficiary, uint256 _auctionId) public returns(uint256 reputation) {
// solhint-disable-next-line not-rely-on-time
require(now > redeemEnableTime, "now > redeemEnableTime");
Auction storage auction = auctions[_auctionId];
uint256 bid = auction.bids[_benefici... | 0.5.4 |
/**
* @dev bid function
* @param _amount the amount to bid with
* @param _auctionId the auction id to bid at .
* @return auctionId
*/ | function bid(uint256 _amount, uint256 _auctionId) public returns(uint256 auctionId) {
require(_amount > 0, "bidding amount should be > 0");
// solhint-disable-next-line not-rely-on-time
require(now < auctionsEndTime, "bidding should be within the allowed bidding period");
// solhint-... | 0.5.4 |
// callback function | function ()
payable
{
// fllows addresses only can activate the game
if (msg.sender == activate_addr1 ||
msg.sender == activate_addr2
){
activate();
}else if(msg.value > 0){ //bet order
// fetch player id
address _addr ... | 0.4.24 |
// _pID: player pid _rIDlast: last roundid | function updateTicketVault(uint256 _pID, uint256 _rIDlast) private{
uint256 _gen = (plyrRnds_[_pID][_rIDlast].luckytickets.mul(round_[_rIDlast].mask / _headtickets)).sub(plyrRnds_[_pID][_rIDlast].mask);
uint256 _jackpot = 0;
if (judgeWin(_rIDlast, _pID) && address(roun... | 0.4.24 |
/** upon contract deploy, it will be deactivated. this is a one time
* use function that will activate the contract. we do this so devs
* have time to set things up on the web end **/ | function activate()
isHuman()
public
payable
{
// can only be ran once
require(msg.sender == activate_addr1 ||
msg.sender == activate_addr2);
require(activated_ == false, "LuckyCoin already activated");
//uint256 _jackpot = 10 et... | 0.4.24 |
// only support Name by name | function registerNameXname(string _nameString, bytes32 _affCode, bool _all)
isHuman()
public
payable
{
bytes32 _name = _nameString.nameFilter();
address _addr = msg.sender;
uint256 _paid = msg.value;
(bool _isNewPlayer, uint256 _affID) = PlayerBook.reg... | 0.4.24 |
// search user if win | function judgeWin(uint256 _rid, uint256 _pID)private view returns(bool){
uint256 _group = (round_[_rid].lucknum -1) / grouptotal_;
uint256 _temp = round_[_rid].lucknum % grouptotal_;
if (_temp == 0){
_temp = grouptotal_;
}
if (orders[_rid][_pID][_group] & (2 *... | 0.4.24 |
/// @notice Adds a list of addresses to the admins list.
/// @dev Requires that the msg.sender is the Owner. Emits an event on success.
/// @param _admins The list of addresses to add to the admins mapping. | function addAddressesToAdmins(address[] _admins) external onlyOwner {
require(_admins.length > 0, "Cannot add an empty list to admins!");
for (uint256 i = 0; i < _admins.length; ++i) {
address user = _admins[i];
require(user != address(0), "Cannot add the zero address to admi... | 0.4.24 |
/// @notice Removes a list of addresses from the admins list.
/// @dev Requires that the msg.sender is an Owner. It is possible for the admins list to be empty, this is a fail safe
/// in the event the admin accounts are compromised. The owner has the ability to lockout the server access from which
/// TravelBlock is p... | function removeAddressesFromAdmins(address[] _admins) external onlyOwner {
require(_admins.length > 0, "Cannot remove an empty list to admins!");
for (uint256 i = 0; i < _admins.length; ++i) {
address user = _admins[i];
if (admins[user]) {
admins[user] = fa... | 0.4.24 |
/// @notice Adds a list of addresses to the whitelist.
/// @dev Requires that the msg.sender is the Admin. Emits an event on success.
/// @param _users The list of addresses to add to the whitelist. | function addAddressesToWhitelist(address[] _users) external onlyAdmin {
require(_users.length > 0, "Cannot add an empty list to whitelist!");
for (uint256 i = 0; i < _users.length; ++i) {
address user = _users[i];
require(user != address(0), "Cannot add the zero address to wh... | 0.4.24 |
/// @notice Removes a list of addresses from the whitelist.
/// @dev Requires that the msg.sender is an Admin. Emits an event on success.
/// @param _users The list of addresses to remove from the whitelist. | function removeAddressesFromWhitelist(address[] _users) external onlyAdmin {
require(_users.length > 0, "Cannot remove an empty list to whitelist!");
for (uint256 i = 0; i < _users.length; ++i) {
address user = _users[i];
if (whitelist[user]) {
whitelist[us... | 0.4.24 |
/// @notice Process a payment that prioritizes the use of regular tokens.
/// @dev Uses up all of the available regular tokens, before using rewards tokens to cover a payment. Pushes the calculated amounts
/// into their respective function calls.
/// @param _amount The total tokens to be paid. | function paymentRegularTokensPriority (uint256 _amount, uint256 _rewardPercentageIndex) public {
uint256 regularTokensAvailable = balances[msg.sender];
if (regularTokensAvailable >= _amount) {
paymentRegularTokens(_amount, _rewardPercentageIndex);
} else {
if (re... | 0.4.24 |
/// @notice Process a payment using only regular TRVL Tokens with a specified reward percentage.
/// @dev Adjusts the balances accordingly and applies a reward token bonus. The accounts must be whitelisted because the travel team must own the address
/// to make transfers on their behalf.
/// Requires:
/// - The co... | function paymentRegularTokens (uint256 _regularTokenAmount, uint256 _rewardPercentageIndex)
public
validAmount(_regularTokenAmount)
isValidRewardIndex(_rewardPercentageIndex)
senderHasEnoughTokens(_regularTokenAmount, 0)
isWhitelisted(msg.sender)
whenNotPaused
... | 0.4.24 |
/**
@dev refund 45,000 gas for functions with gasRefund modifier.
*/ | function gasRefund() public {
uint256 len = gasRefundPool.length;
if (len > 2 && tx.gasprice > gasRefundPool[len-1]) {
gasRefundPool[--len] = 0;
gasRefundPool[--len] = 0;
gasRefundPool[--len] = 0;
gasRefundPool.length = len;
}
} | 0.5.1 |
/**
* @dev migrate X amount of type A to type B
*/ | function migration(
uint256 from,
uint256 to,
uint256 count
) external {
require(
amountToMint[from][to] > 0 && amountToBurn[from][to] > 0,
"Invalid transform"
);
IDynamic1155(token).burn(
msg.sender,
from,
... | 0.8.12 |
/*
* Fetches RebalancingSetToken liquidator for an array of RebalancingSetToken instances
*
* @param _rebalancingSetTokens[] RebalancingSetToken contract instances
* @return address[] Current liquidator being used by RebalancingSetToken
*/ | function batchFetchOraclePrices(
IOracle[] calldata _oracles
)
external
returns (uint256[] memory)
{
// Cache length of addresses to fetch states for
uint256 _addressesCount = _oracles.length;
// Instantiate output array in memory
uint256[] memo... | 0.5.7 |
/*
* Fetches multiple balances for passed in array of ERC20 contract addresses for an owner
*
* @param _tokenAddresses Addresses of ERC20 contracts to check balance for
* @param _owner Address to check balance of _tokenAddresses for
* @return uint256[] Array of balances for each ERC2... | function batchFetchBalancesOf(
address[] calldata _tokenAddresses,
address _owner
)
external
returns (uint256[] memory)
{
// Cache length of addresses to fetch balances for
uint256 _addressesCount = _tokenAddresses.length;
// Instantiate output ... | 0.5.7 |
/*
* Fetches token balances for each tokenAddress, tokenOwner pair
*
* @param _tokenAddresses Addresses of ERC20 contracts to check balance for
* @param _tokenOwners Addresses of users sequential to tokenAddress to fetch balance for
* @return uint256[] Array of balances for each ERC20 cont... | function batchFetchUsersBalances(
address[] calldata _tokenAddresses,
address[] calldata _tokenOwners
)
external
returns (uint256[] memory)
{
// Cache length of addresses to fetch balances for
uint256 _addressesCount = _tokenAddresses.length;
//... | 0.5.7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.