Unnamed: 0 int64 0 7.36k | comments stringlengths 3 35.2k | code_string stringlengths 1 527k | code stringlengths 1 527k | __index_level_0__ int64 0 88.6k |
|---|---|---|---|---|
9 | // Some deliberately invalid address to initialize the secret signer with. Forces maintainers to invoke setSecretSigner before processing any bets. | address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
| address constant DUMMY_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
| 28,836 |
246 | // Exit a pool - redeem pool tokens for a specific amount of underlying assetsAsset must be present in the pool self - ConfigurableRightsPool instance calling the library bPool - Core BPool the CRP is wrapping tokenOut - which token the caller wants to receive tokenAmountOut - amount of underlying asset tokens to receive maxPoolAmountIn - maximum pool tokens to be redeemedreturn exitFee - calculated exit feereturn poolAmountIn - amount of pool tokens redeemed / | function exitswapExternAmountOut(
IConfigurableRightsPool self,
IBPool bPool,
address tokenOut,
uint256 tokenAmountOut,
uint256 maxPoolAmountIn
| function exitswapExternAmountOut(
IConfigurableRightsPool self,
IBPool bPool,
address tokenOut,
uint256 tokenAmountOut,
uint256 maxPoolAmountIn
| 40,348 |
34 | // Module for contrast handling AddressValidator. / | contract UsingValidator {
AddressValidator private _validator;
/**
* Create a new AddressValidator contract when initialize.
*/
constructor() public {
_validator = new AddressValidator();
}
/**
* Returns the set AddressValidator address.
*/
function addressValidator() internal view returns (AddressValidator) {
return _validator;
}
}
| contract UsingValidator {
AddressValidator private _validator;
/**
* Create a new AddressValidator contract when initialize.
*/
constructor() public {
_validator = new AddressValidator();
}
/**
* Returns the set AddressValidator address.
*/
function addressValidator() internal view returns (AddressValidator) {
return _validator;
}
}
| 64,049 |
659 | // bytes4(keccak256("RoundingError(uint256,uint256,uint256)")) | bytes4 internal constant ROUNDING_ERROR_SELECTOR =
0x339f3de2;
| bytes4 internal constant ROUNDING_ERROR_SELECTOR =
0x339f3de2;
| 15,200 |
12 | // ============ Delegation logic ============ | address public logic;
| address public logic;
| 26,025 |
78 | // Calculate the price and make sure they have sent enough | require(msg.value >= prices[madePerPeriod[period]], 'You need to send at least the price');
| require(msg.value >= prices[madePerPeriod[period]], 'You need to send at least the price');
| 8,667 |
157 | // Calculates bridge swap fee based on the destination chain's token transfer. This means the fee should be calculated based on the chain that the nodes emit a tx on tokenAddress address of the destination token to query token config for chainID destination chain ID to query the token config for amount in native token decimalsreturn Fee calculated in token decimals / | function calculateSwapFee(
string memory tokenAddress,
uint256 chainID,
uint256 amount
| function calculateSwapFee(
string memory tokenAddress,
uint256 chainID,
uint256 amount
| 24,610 |
43 | // Method used for oracle funding / | function () public payable {}
}
| function () public payable {}
}
| 21,704 |
132 | // Initializes the staking contract with a first set of parameters/_rewardsDistribution Address owning the rewards token/_rewardToken ERC20 token given as reward/_stakingToken ERC20 token used for staking/_rewardsDuration Duration of the staking contract | constructor(
address _rewardsDistribution,
address _rewardToken,
address _stakingToken,
uint256 _rewardsDuration
| constructor(
address _rewardsDistribution,
address _rewardToken,
address _stakingToken,
uint256 _rewardsDuration
| 11,065 |
201 | // Sets a mocked timestamp value, used only for testing purposes/ | function mockSetTimestamp(uint256 _timestamp) external {
mockedTimestamp = _timestamp;
}
| function mockSetTimestamp(uint256 _timestamp) external {
mockedTimestamp = _timestamp;
}
| 19,077 |
6 | // SETUP OWNER ADDRESS VARIABLE | address payable public owner;
event Received(address, uint256);
event GasUsed(uint256);
| address payable public owner;
event Received(address, uint256);
event GasUsed(uint256);
| 29,342 |
228 | // normalizeFishAmount(msg.sender); | transactionSystem.cancelSellOrder(msg.sender, _orderId);
| transactionSystem.cancelSellOrder(msg.sender, _orderId);
| 54,323 |
30 | // Market Place implementation. / | contract MarketPlace {
// ---------- Structs ----------
struct Owner {
address addr;
string name;
Store[] stores;
}
// ---------- Variables ----------
// The variable "testing" should be removed before going to production!!!
// It has been added here so the tests can run, but should not be allowed in production.
bool private testing = false;
bool private stopped = false;
mapping (address => uint8) administrators;
mapping (address => Owner) ownersByAddress;
mapping (uint256 => Owner) ownersIndex;
uint256 numOwners;
mapping (string => Store) storesByName;
mapping (uint256 => Store) storesIndex;
uint256 numStores;
// ---------- Modifiers ----------
modifier onlyAdministrators() {
require(testing || administrators[msg.sender] != address(0));
_;
}
modifier onlyStoreOwners () {
require(testing || ownersByAddress[msg.sender].addr != address(0));
_;
}
modifier stopInEmergency { if (!stopped) _; }
modifier onlyInEmergency { if (stopped) _; }
// ---------- Constructor ----------
constructor() public {
administrators[msg.sender] = 1;
}
// ---------- Identity ----------
function isAdministrator() public view returns (bool) {
return administrators[msg.sender] != address(0);
}
function isStoreOwner() public view returns (bool) {
return ownersByAddress[msg.sender].addr != address(0);
}
function toggleContractActive() public onlyAdministrators {
stopped = !stopped;
}
function setTesting(bool _testing) public {
testing = _testing;
}
// ---------- Store owners ----------
/** @dev Adds a new store owner - only administrators can perform this task.
* @param storeOwner the owner of the store.
* @param name the name of the owner.
*/
function addStoreOwner(address storeOwner, string name) public stopInEmergency onlyAdministrators {
require(testing || ownersByAddress[storeOwner].addr == address(0));
Owner memory owner = Owner(storeOwner, name, new Store[](0));
ownersByAddress[storeOwner] = owner;
ownersIndex[numOwners++] = owner;
}
/** @dev Returns the total number of store owners.
* @return the total number of store owners
*/
function getNumStoreOwners() public view returns (uint256) {
return numOwners;
}
/** @dev Returns a specific store owner.
* @param storeOwnerIndex the id of the store owner
* @return the address and name of the store owner
*/
function getStoreOwner(uint256 storeOwnerIndex) public view returns (address, string) {
require(storeOwnerIndex < numOwners);
Owner memory owner = ownersIndex[storeOwnerIndex];
return (owner.addr, owner.name);
}
// ---------- Stores ----------
/** @dev Adds a new store - only store owners can perform this task.
* @param storeName the name of the store.
*/
function addStore (string storeName) public stopInEmergency onlyStoreOwners {
address storeOwner = msg.sender;
require(testing || ownersByAddress[storeOwner].addr != address(0));
require(testing || storesByName [storeName] == address(0));
Store store = new Store(storeName);
ownersByAddress[storeOwner].stores.push(store);
storesIndex[numStores++] = store;
storesByName[storeName] = store;
}
/** @dev Returns the number of stores for the current store owner (msg.sender).
* @return the total number of stores for the current owner
*/
function getNumStoresForOwner() public view returns (uint256) {
if (ownersByAddress[msg.sender].addr == address(0)) {
return 0;
}
return ownersByAddress[msg.sender].stores.length;
}
/** @dev Returns a specific store belonging to the current store owner (msg.sender).
* @param storeIndex the id of the store
* @return the name of the store
*/
function getStoreForOwner(uint256 storeIndex) public view returns (string) {
require(ownersByAddress[msg.sender].addr != address(0));
return ownersByAddress[msg.sender].stores[storeIndex].name();
}
/** @dev Returns the total number of all stores available in the market place (all owners combined).
* @return the total number of stores
*/
function getNumStores() public view returns (uint256) {
return numStores;
}
/** @dev Returns a specific store among all the stores available in the market place (all owners combined).
* @return the names of the store
*/
function getStore(uint256 storeIndex) public view returns (string) {
require(storeIndex < numStores);
return storesIndex[storeIndex].name();
}
// ---------- Products ----------
/** @dev Adds a new product to a store - only store owners can perform this task.
* @param storeName the name of the store
* @param productName the name of the product
* @param price the price of the product
* @param quantity the quantity of the product
*/
function addProduct(string storeName, string productName, uint256 price, uint256 quantity) public stopInEmergency onlyStoreOwners {
require(testing || storesByName[storeName] != address(0));
storesByName[storeName].addProduct(productName, price, quantity);
}
/** @dev Returns the number of products in a specific store.
* @return the number of products in the store
*/
function getNumProducts(string storeName) public view returns (uint256) {
require(storesByName[storeName] != address(0));
return storesByName[storeName].getNumProducts();
}
/** @dev Returns a specific product in a store.
* @param storeName the name of the store
* @param productIndex the id of the product
* @return the name of the store, price and quantity of the product
*/
function getProduct(string storeName, uint256 productIndex) public view returns (string, uint256, uint256) {
require(storesByName[storeName] != address(0));
return storesByName[storeName].getProduct(productIndex);
}
// ---------- Sales ----------
/** @dev Executes a buy order of a specific product.
* @param storeName the name of the store
* @param productIndex the id of the product
* @param quantity the quantity of products to purchase
*/
function buy(string storeName, uint256 productIndex, uint256 quantity) public stopInEmergency {
require(storesByName[storeName] != address(0));
storesByName[storeName].sell(msg.sender, productIndex, quantity);
}
}
| contract MarketPlace {
// ---------- Structs ----------
struct Owner {
address addr;
string name;
Store[] stores;
}
// ---------- Variables ----------
// The variable "testing" should be removed before going to production!!!
// It has been added here so the tests can run, but should not be allowed in production.
bool private testing = false;
bool private stopped = false;
mapping (address => uint8) administrators;
mapping (address => Owner) ownersByAddress;
mapping (uint256 => Owner) ownersIndex;
uint256 numOwners;
mapping (string => Store) storesByName;
mapping (uint256 => Store) storesIndex;
uint256 numStores;
// ---------- Modifiers ----------
modifier onlyAdministrators() {
require(testing || administrators[msg.sender] != address(0));
_;
}
modifier onlyStoreOwners () {
require(testing || ownersByAddress[msg.sender].addr != address(0));
_;
}
modifier stopInEmergency { if (!stopped) _; }
modifier onlyInEmergency { if (stopped) _; }
// ---------- Constructor ----------
constructor() public {
administrators[msg.sender] = 1;
}
// ---------- Identity ----------
function isAdministrator() public view returns (bool) {
return administrators[msg.sender] != address(0);
}
function isStoreOwner() public view returns (bool) {
return ownersByAddress[msg.sender].addr != address(0);
}
function toggleContractActive() public onlyAdministrators {
stopped = !stopped;
}
function setTesting(bool _testing) public {
testing = _testing;
}
// ---------- Store owners ----------
/** @dev Adds a new store owner - only administrators can perform this task.
* @param storeOwner the owner of the store.
* @param name the name of the owner.
*/
function addStoreOwner(address storeOwner, string name) public stopInEmergency onlyAdministrators {
require(testing || ownersByAddress[storeOwner].addr == address(0));
Owner memory owner = Owner(storeOwner, name, new Store[](0));
ownersByAddress[storeOwner] = owner;
ownersIndex[numOwners++] = owner;
}
/** @dev Returns the total number of store owners.
* @return the total number of store owners
*/
function getNumStoreOwners() public view returns (uint256) {
return numOwners;
}
/** @dev Returns a specific store owner.
* @param storeOwnerIndex the id of the store owner
* @return the address and name of the store owner
*/
function getStoreOwner(uint256 storeOwnerIndex) public view returns (address, string) {
require(storeOwnerIndex < numOwners);
Owner memory owner = ownersIndex[storeOwnerIndex];
return (owner.addr, owner.name);
}
// ---------- Stores ----------
/** @dev Adds a new store - only store owners can perform this task.
* @param storeName the name of the store.
*/
function addStore (string storeName) public stopInEmergency onlyStoreOwners {
address storeOwner = msg.sender;
require(testing || ownersByAddress[storeOwner].addr != address(0));
require(testing || storesByName [storeName] == address(0));
Store store = new Store(storeName);
ownersByAddress[storeOwner].stores.push(store);
storesIndex[numStores++] = store;
storesByName[storeName] = store;
}
/** @dev Returns the number of stores for the current store owner (msg.sender).
* @return the total number of stores for the current owner
*/
function getNumStoresForOwner() public view returns (uint256) {
if (ownersByAddress[msg.sender].addr == address(0)) {
return 0;
}
return ownersByAddress[msg.sender].stores.length;
}
/** @dev Returns a specific store belonging to the current store owner (msg.sender).
* @param storeIndex the id of the store
* @return the name of the store
*/
function getStoreForOwner(uint256 storeIndex) public view returns (string) {
require(ownersByAddress[msg.sender].addr != address(0));
return ownersByAddress[msg.sender].stores[storeIndex].name();
}
/** @dev Returns the total number of all stores available in the market place (all owners combined).
* @return the total number of stores
*/
function getNumStores() public view returns (uint256) {
return numStores;
}
/** @dev Returns a specific store among all the stores available in the market place (all owners combined).
* @return the names of the store
*/
function getStore(uint256 storeIndex) public view returns (string) {
require(storeIndex < numStores);
return storesIndex[storeIndex].name();
}
// ---------- Products ----------
/** @dev Adds a new product to a store - only store owners can perform this task.
* @param storeName the name of the store
* @param productName the name of the product
* @param price the price of the product
* @param quantity the quantity of the product
*/
function addProduct(string storeName, string productName, uint256 price, uint256 quantity) public stopInEmergency onlyStoreOwners {
require(testing || storesByName[storeName] != address(0));
storesByName[storeName].addProduct(productName, price, quantity);
}
/** @dev Returns the number of products in a specific store.
* @return the number of products in the store
*/
function getNumProducts(string storeName) public view returns (uint256) {
require(storesByName[storeName] != address(0));
return storesByName[storeName].getNumProducts();
}
/** @dev Returns a specific product in a store.
* @param storeName the name of the store
* @param productIndex the id of the product
* @return the name of the store, price and quantity of the product
*/
function getProduct(string storeName, uint256 productIndex) public view returns (string, uint256, uint256) {
require(storesByName[storeName] != address(0));
return storesByName[storeName].getProduct(productIndex);
}
// ---------- Sales ----------
/** @dev Executes a buy order of a specific product.
* @param storeName the name of the store
* @param productIndex the id of the product
* @param quantity the quantity of products to purchase
*/
function buy(string storeName, uint256 productIndex, uint256 quantity) public stopInEmergency {
require(storesByName[storeName] != address(0));
storesByName[storeName].sell(msg.sender, productIndex, quantity);
}
}
| 19,134 |
41 | // owner is allowed to send tokens even when locked | emit Transfer(address(0), owner, initialSupply);
| emit Transfer(address(0), owner, initialSupply);
| 20,401 |
29 | // _setRouter is a helper function to allow changing the router contract addressAllows updating the router address. Future proofing for potential Router upgradesNOTE: it is advisable to wrap this around a function that uses, for example, OpenZeppelin'sonlyOwner modifier_router address of the deployed Router smart contract / | function _setRouter(address _router) internal returns (bool) {
require(_router != address(0), "router cannot be the zero address");
router = IRouter(_router);
return true;
}
| function _setRouter(address _router) internal returns (bool) {
require(_router != address(0), "router cannot be the zero address");
router = IRouter(_router);
return true;
}
| 6,479 |
33 | // This contract interacts with USDC, Dai, and Dharma Dai. | ERC20Interface internal constant _USDC = ERC20Interface(
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 // mainnet
);
ERC20Interface internal constant _DAI = ERC20Interface(
0x6B175474E89094C44Da98b954EedeAC495271d0F // mainnet
);
ERC20Interface internal constant _ETHERIZER = ERC20Interface(
0x723B51b72Ae89A3d0c2a2760f0458307a1Baa191
| ERC20Interface internal constant _USDC = ERC20Interface(
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 // mainnet
);
ERC20Interface internal constant _DAI = ERC20Interface(
0x6B175474E89094C44Da98b954EedeAC495271d0F // mainnet
);
ERC20Interface internal constant _ETHERIZER = ERC20Interface(
0x723B51b72Ae89A3d0c2a2760f0458307a1Baa191
| 35,639 |
45 | // A descriptive name for a collection of NFTs in this contract | function name() external view returns (string memory _name);
| function name() external view returns (string memory _name);
| 43,369 |
9 | // Generates a random nr within uint256 range, almost impossible to fail at this,/ but to be on the safe, we try 10 times; else revert | function _createRequestId(uint16 chainId) private returns (uint256 random) {
uint8 attempts;
while (attempts < 10) {
random = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, _nonce))) % type(uint256).max;
_nonce++;
if (!_requestIds[chainId].contains(random)) {
_requestIds[chainId].add(random);
return random;
}
attempts++;
}
revert("failed to generate request id");
}
| function _createRequestId(uint16 chainId) private returns (uint256 random) {
uint8 attempts;
while (attempts < 10) {
random = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, _nonce))) % type(uint256).max;
_nonce++;
if (!_requestIds[chainId].contains(random)) {
_requestIds[chainId].add(random);
return random;
}
attempts++;
}
revert("failed to generate request id");
}
| 32,680 |
123 | // Prevent overflow when multiplying INT256_MIN with -1 https:github.com/RequestNetwork/requestNetwork/issues/43 | require(!(a == - 2**255 && b == -1) && !(b == - 2**255 && a == -1));
int256 c = a * b;
require((b == 0) || (c / b == a));
return c;
| require(!(a == - 2**255 && b == -1) && !(b == - 2**255 && a == -1));
int256 c = a * b;
require((b == 0) || (c / b == a));
return c;
| 11,972 |
133 | // This is a 1D bitmap, with max size of 256 elements, limiting us to 256 chainsIds. | uint256 claimedBitMap;
| uint256 claimedBitMap;
| 66,853 |
241 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that the target address contains contract code and also asserts for success in the low-level call. |
bytes memory returndata = address(token).functionCall(data, "call fail");
if ((returndata.length != 0) && !abi.decode(returndata, (bool))) {
revert IErrors.OperationDidNotSucceed();
}
|
bytes memory returndata = address(token).functionCall(data, "call fail");
if ((returndata.length != 0) && !abi.decode(returndata, (bool))) {
revert IErrors.OperationDidNotSucceed();
}
| 11,411 |
184 | // Only factory can call this function. | require(msg.sender == factory, "unauthorized caller");
| require(msg.sender == factory, "unauthorized caller");
| 19,902 |
3 | // Allows batched call to self (this contract)./calls An array of inputs for each call./revertOnFail If True then reverts after a failed call and stops doing further calls. F1: External is ok here because this is the batch function, adding it to a batch makes no sense F2: Calls in the batch may be payable, delegatecall operates in the same context, so each call in the batch has access to msg.value C3: The length of the loop is fully under user control, so can't be exploited C7: Delegatecall is only used on the same contract, so it's safe | function batch(bytes[] calldata calls, bool revertOnFail) external payable {
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(calls[i]);
if (!success && revertOnFail) {
revert(_getRevertMsg(result));
}
}
}
| function batch(bytes[] calldata calls, bool revertOnFail) external payable {
for (uint256 i = 0; i < calls.length; i++) {
(bool success, bytes memory result) = address(this).delegatecall(calls[i]);
if (!success && revertOnFail) {
revert(_getRevertMsg(result));
}
}
}
| 35,441 |
201 | // Clear approvals | _approve(address(0), tokenId);
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(tokenId);
emit Transfer(owner, address(0), tokenId);
| _approve(address(0), tokenId);
_holderTokens[owner].remove(tokenId);
_tokenOwners.remove(tokenId);
emit Transfer(owner, address(0), tokenId);
| 39,238 |
344 | // Helper function that constructs a hashed debt order struct given the raw parametersof a debt order. / | function getDebtOrder(address[6] orderAddresses, uint[8] orderValues, bytes32[1] orderBytes32)
internal
view
returns (DebtOrder _debtOrder)
| function getDebtOrder(address[6] orderAddresses, uint[8] orderValues, bytes32[1] orderBytes32)
internal
view
returns (DebtOrder _debtOrder)
| 26,752 |
18 | // if(IWorld(_worldAddress).getPlatform() != mainData.platform) { revert Errors.IncorrectPlatformInWorld(); } | require(IWorld(_worldAddress).getPlatform() == mainData.platform,"IncorrectPlatformInWorld");
string memory worldId = IWorld(_worldAddress).getWorldId();
emit RegisterWorld(msg.sender, worldId, _worldAddress);
mainData.worlds[worldId].worldAddress = _worldAddress;
mainData.worlds[worldId].worldType = _worldType;
mainData.worldIds.push(worldId);
| require(IWorld(_worldAddress).getPlatform() == mainData.platform,"IncorrectPlatformInWorld");
string memory worldId = IWorld(_worldAddress).getWorldId();
emit RegisterWorld(msg.sender, worldId, _worldAddress);
mainData.worlds[worldId].worldAddress = _worldAddress;
mainData.worlds[worldId].worldType = _worldType;
mainData.worldIds.push(worldId);
| 19,628 |
10 | // ------------------------------------------------------------------------ Subtract a number from another number, checking for underflows ------------------------------------------------------------------------ | function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
| function sub(uint a, uint b) internal returns (uint) {
assert(b <= a);
return a - b;
}
| 9,560 |
1 | // Assert if the given `account` has been provided access to the unpauser role.account The account address being queriedreturn True if the given `account` has access to the unpauser role, otherwise false / | function isUnpauser(address account) external view returns (bool) {
return _isUnpauser(account);
}
| function isUnpauser(address account) external view returns (bool) {
return _isUnpauser(account);
}
| 32,881 |
44 | // And add the miner to the array list of submissions here | submittedHashes[newHash][nNodes].push(msg.sender);
| submittedHashes[newHash][nNodes].push(msg.sender);
| 4,480 |
7 | // 合约拥有者提取eth | function withdrawOwner(uint256 amount) public onlyRole(DEFAULT_ADMIN_ROLE) {
payable(msg.sender).transfer(amount);
emit Sold(amount);
}
| function withdrawOwner(uint256 amount) public onlyRole(DEFAULT_ADMIN_ROLE) {
payable(msg.sender).transfer(amount);
emit Sold(amount);
}
| 52,644 |
47 | // 充值repayAmount token到合约中,充值之前需要approve使用amountGet进行计算 | uint256 repayAmount = b.liability();
b.setBondParam("liability", 0);
| uint256 repayAmount = b.liability();
b.setBondParam("liability", 0);
| 13,464 |
23 | // Allows to change the number of required confirmations. Transaction has to be sent by wallet./_required Number of required confirmations. | function changeRequirement(uint _required)
public
onlyWallet
validRequirement(owners.length, _required)
| function changeRequirement(uint _required)
public
onlyWallet
validRequirement(owners.length, _required)
| 37,671 |
28 | // Deposits a MadByte amount into the MadNet blockchain to a BN address./ The Madbyte amount is deducted from the sender and it is burned by this/ contract. The created deposit Id is owned by the toX_ address./to0_ Part of the BN address/to1_ Part of the BN address/to2_ Part of the BN address/to3_ Part of the BN address/amount_ The amount of Madbytes to be deposited/ Return The deposit ID of the deposit created | function depositToBN(uint256 to0_, uint256 to1_, uint256 to2_, uint256 to3_, uint256 amount_) public returns (uint256) {
return _depositBN(to0_, to1_, to2_, to3_, amount_);
}
| function depositToBN(uint256 to0_, uint256 to1_, uint256 to2_, uint256 to3_, uint256 amount_) public returns (uint256) {
return _depositBN(to0_, to1_, to2_, to3_, amount_);
}
| 318 |
308 | // Return the entire set in an array WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designedto mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind thatthis function has an unbounded cost, and using it as part of a state-changing function may render the functionuncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. / | function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
| function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
| 4,307 |
4 | // usdt 的erc20 地址 | address public usdtToken = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
address public usdtMsUniContract = address(0xCaBD18918115B98e2fA0bDcB77A24AE6aB3d9c9c);
address public owner;
| address public usdtToken = address(0xdAC17F958D2ee523a2206206994597C13D831ec7);
address public usdtMsUniContract = address(0xCaBD18918115B98e2fA0bDcB77A24AE6aB3d9c9c);
address public owner;
| 7,783 |
15 | // The permit message signed for a single token allownce | struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
| struct PermitSingle {
// the permit data for a single token alownce
PermitDetails details;
// address permissioned on the allowed tokens
address spender;
// deadline on the permit signature
uint256 sigDeadline;
}
| 25,095 |
15 | // Function to withdraw all Ether from this contract. | function withdraw() public {
| function withdraw() public {
| 25,135 |
45 | // If the interest rate is still negative and we are not 48 hours after speedbump being set we revert | require(
localSpeedbump + _FORTY_EIGHT_HOURS < block.timestamp,
"E:Early"
);
| require(
localSpeedbump + _FORTY_EIGHT_HOURS < block.timestamp,
"E:Early"
);
| 25,544 |
87 | // IStarNFT Galaxy Protocol Interface for operating with StarNFTs. / | interface IStarNFT is IERC1155 {
/* ============ Events =============== */
// event PowahUpdated(uint256 indexed id, uint256 indexed oldPoints, uint256 indexed newPoints);
/* ============ Functions ============ */
function isOwnerOf(address, uint256) external view returns (bool);
function getNumMinted() external view returns (uint256);
// function starInfo(uint256) external view returns (uint128 powah, uint128 mintBlock, address originator);
// function quasarInfo(uint256) external view returns (uint128 mintBlock, IERC20 stakeToken, uint256 amount, uint256 campaignID);
// function superInfo(uint256) external view returns (uint128 mintBlock, IERC20[] memory stakeToken, uint256[] memory amount, uint256 campaignID);
// mint
function mint(address account, uint256 powah) external returns (uint256);
function mintBatch(address account, uint256 amount, uint256[] calldata powahArr) external returns (uint256[] memory);
function burn(address account, uint256 id) external;
function burnBatch(address account, uint256[] calldata ids) external;
// asset-backing mint
// function mintQuasar(address account, uint256 powah, uint256 cid, IERC20 stakeToken, uint256 amount) external returns (uint256);
// function burnQuasar(address account, uint256 id) external;
// asset-backing forge
// function mintSuper(address account, uint256 powah, uint256 campaignID, IERC20[] calldata stakeTokens, uint256[] calldata amounts) external returns (uint256);
// function burnSuper(address account, uint256 id) external;
// update
// function updatePowah(address owner, uint256 id, uint256 powah) external;
}
| interface IStarNFT is IERC1155 {
/* ============ Events =============== */
// event PowahUpdated(uint256 indexed id, uint256 indexed oldPoints, uint256 indexed newPoints);
/* ============ Functions ============ */
function isOwnerOf(address, uint256) external view returns (bool);
function getNumMinted() external view returns (uint256);
// function starInfo(uint256) external view returns (uint128 powah, uint128 mintBlock, address originator);
// function quasarInfo(uint256) external view returns (uint128 mintBlock, IERC20 stakeToken, uint256 amount, uint256 campaignID);
// function superInfo(uint256) external view returns (uint128 mintBlock, IERC20[] memory stakeToken, uint256[] memory amount, uint256 campaignID);
// mint
function mint(address account, uint256 powah) external returns (uint256);
function mintBatch(address account, uint256 amount, uint256[] calldata powahArr) external returns (uint256[] memory);
function burn(address account, uint256 id) external;
function burnBatch(address account, uint256[] calldata ids) external;
// asset-backing mint
// function mintQuasar(address account, uint256 powah, uint256 cid, IERC20 stakeToken, uint256 amount) external returns (uint256);
// function burnQuasar(address account, uint256 id) external;
// asset-backing forge
// function mintSuper(address account, uint256 powah, uint256 campaignID, IERC20[] calldata stakeTokens, uint256[] calldata amounts) external returns (uint256);
// function burnSuper(address account, uint256 id) external;
// update
// function updatePowah(address owner, uint256 id, uint256 powah) external;
}
| 61,833 |
220 | // Mints to the given recipient. Internal mint function / | function _mintToUser(address recipient, uint256 _mintAmount, uint256 maxMintSupply) private {
uint256 supply = totalSupply();
require(supply + _mintAmount <= maxMintSupply, "Cannot mint more than available");
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(recipient, supply + i);
}
}
| function _mintToUser(address recipient, uint256 _mintAmount, uint256 maxMintSupply) private {
uint256 supply = totalSupply();
require(supply + _mintAmount <= maxMintSupply, "Cannot mint more than available");
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(recipient, supply + i);
}
}
| 53,960 |
8 | // Modifier that requires the competitionId to be a valid/existing one. | modifier competitionIdCheck(uint _competitionId) {
//if (_competitionId >= competitions.length) throw;
_;
}
| modifier competitionIdCheck(uint _competitionId) {
//if (_competitionId >= competitions.length) throw;
_;
}
| 48,344 |
14 | // Already taken, undo. | revert();
| revert();
| 27,872 |
13 | // checking the sender should have enough coins | if(balanceOf[msg.sender] < value) throw;
| if(balanceOf[msg.sender] < value) throw;
| 14,156 |
114 | // Calculates total stake payout including rewards for a multi-day range g Cache of stored globals stakeSharesParam Param from stake to calculate bonuses for beginDay First day to calculate bonuses for endDay Last day (non-inclusive) of range to calculate bonuses forreturn Payout in Suns / | function _calcPayoutRewards(
GlobalsCache memory g,
uint256 stakeSharesParam,
uint256 beginDay,
uint256 endDay
)
private
view
returns (uint256 payout)
| function _calcPayoutRewards(
GlobalsCache memory g,
uint256 stakeSharesParam,
uint256 beginDay,
uint256 endDay
)
private
view
returns (uint256 payout)
| 17,516 |
62 | // P1Types dYdXLibrary for common types used in PerpetualV1 contracts. / | library P1Types {
// ============ Structs ============
/**
* @dev Used to represent the global index and each account's cached index.
* Used to settle funding paymennts on a per-account basis.
*/
struct Index {
uint32 timestamp;
bool isPositive;
uint128 value;
}
/**
* @dev Used to track the signed margin balance and position balance values for each account.
*/
struct Balance {
bool marginIsPositive;
bool positionIsPositive;
uint120 margin;
uint120 position;
}
/**
* @dev Used to cache commonly-used variables that are relatively gas-intensive to obtain.
*/
struct Context {
uint256 price;
uint256 minCollateral;
Index index;
}
/**
* @dev Used by contracts implementing the I_P1Trader interface to return the result of a trade.
*/
struct TradeResult {
uint256 marginAmount;
uint256 positionAmount;
bool isBuy; // From taker's perspective.
bytes32 traderFlags;
}
}
| library P1Types {
// ============ Structs ============
/**
* @dev Used to represent the global index and each account's cached index.
* Used to settle funding paymennts on a per-account basis.
*/
struct Index {
uint32 timestamp;
bool isPositive;
uint128 value;
}
/**
* @dev Used to track the signed margin balance and position balance values for each account.
*/
struct Balance {
bool marginIsPositive;
bool positionIsPositive;
uint120 margin;
uint120 position;
}
/**
* @dev Used to cache commonly-used variables that are relatively gas-intensive to obtain.
*/
struct Context {
uint256 price;
uint256 minCollateral;
Index index;
}
/**
* @dev Used by contracts implementing the I_P1Trader interface to return the result of a trade.
*/
struct TradeResult {
uint256 marginAmount;
uint256 positionAmount;
bool isBuy; // From taker's perspective.
bytes32 traderFlags;
}
}
| 14,585 |
64 | // Or just sub msg.value If it will be below zero - it will throw revert() require(msg.value >= requestPrice()); | uint256 value = msg.value;
for (uint256 i = 0; i < oracles.length; i++) {
OracleI oracle = OracleI(oracles[i]);
uint callPrice = oracle.getPrice();
| uint256 value = msg.value;
for (uint256 i = 0; i < oracles.length; i++) {
OracleI oracle = OracleI(oracles[i]);
uint callPrice = oracle.getPrice();
| 67,536 |
23 | // �Ѵ��������� 10^18 | uint256 _value = valueNeed.mul(raiseRatio);
require(_value <= balances[admin]);
balances[admin] = balances[admin].sub(_value);
balances[msg.sender] = balances[msg.sender].add(_value);
emit Transfer(admin, msg.sender, _value);
| uint256 _value = valueNeed.mul(raiseRatio);
require(_value <= balances[admin]);
balances[admin] = balances[admin].sub(_value);
balances[msg.sender] = balances[msg.sender].add(_value);
emit Transfer(admin, msg.sender, _value);
| 58,653 |
9 | // operation's parameters are packed into generic arrays. Execute methods of each executor contract expects its own params/entry point to submit a generic operation/identity (address) identity subject of the operation/executor (address) contract address extending OperationExecutor interface on which the operation will be executed/intParams () generic integer parameters for the operation/stringParams (string) generic string parameter for the operation/addressParams () generic address parameters for the operation/bytesParams () generic bytes parameters for the operation/ return(uint256) operation ID | function submitOperation(address identity, address executor, uint256[] memory intParams, string memory stringParams, address[] memory addressParams, bytes32[] memory bytesParams) public needsPermission(identity, executor) returns (uint256) {
operationsCount += 1;
operations[operationsCount] = Operation({
executed: false,
identity: identity,
confirmationsCount: 0,
executor: executor,
intParams: intParams,
stringParams: stringParams,
addressParams: addressParams,
bytesParams: bytesParams
});
emit Submission(identity, msg.sender, operationsCount, executor, lastOperationBlock[identity]);
lastOperationBlock[identity] = block.number;
confirm(operationsCount);
return operationsCount;
}
| function submitOperation(address identity, address executor, uint256[] memory intParams, string memory stringParams, address[] memory addressParams, bytes32[] memory bytesParams) public needsPermission(identity, executor) returns (uint256) {
operationsCount += 1;
operations[operationsCount] = Operation({
executed: false,
identity: identity,
confirmationsCount: 0,
executor: executor,
intParams: intParams,
stringParams: stringParams,
addressParams: addressParams,
bytesParams: bytesParams
});
emit Submission(identity, msg.sender, operationsCount, executor, lastOperationBlock[identity]);
lastOperationBlock[identity] = block.number;
confirm(operationsCount);
return operationsCount;
}
| 4,414 |
34 | // Implementation of the `IERC20` interface. This implementation is agnostic to the way tokens are created. This meansthat a supply mechanism has to be added in a derived contract using `_mint`.For a generic mechanism see `ERC20Mintable`. For a detailed writeup see our guide [How to implement supply We have followed general OpenZeppelin guidelines: functions revert insteadof returning `false` on failure. This behavior is nonetheless conventionaland does not conflict with the expectations of ERC20 applications. Additionally, an `Approval` event is emitted on calls to `transferFrom`.This allows applications to reconstruct the allowance for all accounts justby listening to said events. Other implementations of | contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See `IERC20.transfer`.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See `IERC20.transferFrom`.
*
* Emits an `Approval` event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of `ERC20`;
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to `transfer`, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a `Transfer` event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a `Transfer` event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a `Transfer` event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an `Approval` event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
}
| contract ERC20 is IERC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev See `IERC20.totalSupply`.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See `IERC20.balanceOf`.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See `IERC20.transfer`.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See `IERC20.allowance`.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See `IERC20.approve`.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See `IERC20.transferFrom`.
*
* Emits an `Approval` event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of `ERC20`;
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to `approve` that can be used as a mitigation for
* problems described in `IERC20.approve`.
*
* Emits an `Approval` event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to `transfer`, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a `Transfer` event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a `Transfer` event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "ERC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a `Transfer` event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "ERC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an `Approval` event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See `_burn` and `_approve`.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
}
| 807 |
4 | // Executor - A contract that can execute transactions Richard Meissner - @rmeissner / | contract Executor {
/**
* @notice Executes either a delegatecall or a call with provided parameters.
* @param to Destination address.
* @param value Ether value.
* @param data Data payload.
* @param operation Operation type.
* @return success boolean flag indicating if the call succeeded.
*/
function execute(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
uint256 txGas
) internal returns (bool success) {
if (operation == Enum.Operation.DelegateCall) {
// solhint-disable-next-line no-inline-assembly
assembly {
success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
}
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
}
}
}
}
| contract Executor {
/**
* @notice Executes either a delegatecall or a call with provided parameters.
* @param to Destination address.
* @param value Ether value.
* @param data Data payload.
* @param operation Operation type.
* @return success boolean flag indicating if the call succeeded.
*/
function execute(
address to,
uint256 value,
bytes memory data,
Enum.Operation operation,
uint256 txGas
) internal returns (bool success) {
if (operation == Enum.Operation.DelegateCall) {
// solhint-disable-next-line no-inline-assembly
assembly {
success := delegatecall(txGas, to, add(data, 0x20), mload(data), 0, 0)
}
} else {
// solhint-disable-next-line no-inline-assembly
assembly {
success := call(txGas, to, value, add(data, 0x20), mload(data), 0, 0)
}
}
}
}
| 9,847 |
49 | // If necessary, set the protocol fee collector field in the exchange. | if (shouldSetProtocolFeeCollector) {
testProtocolFees.setProtocolFeeCollector(address(this));
}
| if (shouldSetProtocolFeeCollector) {
testProtocolFees.setProtocolFeeCollector(address(this));
}
| 21,641 |
22 | // Update the saleEndTime at the end of the second sale so the refund guarantee starts from now | if (isFirstSaleActive && (currentSupply + mintNumber >= firstSaleSupply)) {
isFirstSaleActive = false;
} else if (isSecondSaleActive && (currentSupply + mintNumber >= maxSupply)) {
| if (isFirstSaleActive && (currentSupply + mintNumber >= firstSaleSupply)) {
isFirstSaleActive = false;
} else if (isSecondSaleActive && (currentSupply + mintNumber >= maxSupply)) {
| 48,589 |
3 | // The total amount of nights offered for booking | uint256 public totalNights;
| uint256 public totalNights;
| 52,081 |
77 | // ---------- Market Expiry ---------- / | function _selfDestruct(address payable beneficiary) internal {
uint _deposited = deposited;
if (_deposited != 0) {
_decrementDeposited(_deposited);
}
// Transfer the balance rather than the deposit value in case there are any synths left over
// from direct transfers.
IERC20 sUSD = _sUSD();
uint balance = sUSD.balanceOf(address(this));
if (balance != 0) {
sUSD.transfer(beneficiary, balance);
}
// Destroy the option tokens before destroying the market itself.
options.long.expire(beneficiary);
options.short.expire(beneficiary);
selfdestruct(beneficiary);
}
| function _selfDestruct(address payable beneficiary) internal {
uint _deposited = deposited;
if (_deposited != 0) {
_decrementDeposited(_deposited);
}
// Transfer the balance rather than the deposit value in case there are any synths left over
// from direct transfers.
IERC20 sUSD = _sUSD();
uint balance = sUSD.balanceOf(address(this));
if (balance != 0) {
sUSD.transfer(beneficiary, balance);
}
// Destroy the option tokens before destroying the market itself.
options.long.expire(beneficiary);
options.short.expire(beneficiary);
selfdestruct(beneficiary);
}
| 32,936 |
60 | // Calculate and transfer the 'target' amount. | uint256 toAmount = calculateAndTransferAmountToPostActionAddress(
order,
feeAmount
);
| uint256 toAmount = calculateAndTransferAmountToPostActionAddress(
order,
feeAmount
);
| 48,433 |
33 | // Burnable tokens mapped to targetTokens / | mapping(address => address) burnableTokens;
| mapping(address => address) burnableTokens;
| 61,677 |
126 | // token0 1 : token1 10 => 1:10, coinamount=amount10/1 | if (IUniswapV2Pair(pairContract).token1() == _coins[0].token) {
coinAmount = _getAmountOut(amount, reserve0, reserve1);
} else {
| if (IUniswapV2Pair(pairContract).token1() == _coins[0].token) {
coinAmount = _getAmountOut(amount, reserve0, reserve1);
} else {
| 23,626 |
134 | // RoxOnlyOwnerMethods Only Methods that can be called by the owner of the contract. / | contract RoxOnlyOwnerMethods is RoxBase {
/**
* @dev Sets the Approved value for contract address.
*/
function setApprovedContractAddress (address _contractAddress, bool _value) public onlyOwner {
ApprovedContractAddress[_contractAddress] = _value;
}
function kill() public onlyOwner {
selfdestruct(msg.sender);
}
/**
* @dev Sets base uriToken.
*/
function setURIToken(string _uriToken) public onlyOwner {
URIToken = _uriToken;
}
/**
* @dev Sets the new commission address.
*/
function setCommissionAddress (address _commissionAddress) public onlyOwner {
commissionAddress = _commissionAddress;
}
/**
* @dev Sets the minter's Address
*/
function setMinterAddress (address _minterAddress) public onlyOwner{
minter = _minterAddress;
}
/**
* @dev Burns a token.
*/
function adminBurnToken(uint256 _tokenId) public onlyOwner {
_burn(_tokenId);
}
}
| contract RoxOnlyOwnerMethods is RoxBase {
/**
* @dev Sets the Approved value for contract address.
*/
function setApprovedContractAddress (address _contractAddress, bool _value) public onlyOwner {
ApprovedContractAddress[_contractAddress] = _value;
}
function kill() public onlyOwner {
selfdestruct(msg.sender);
}
/**
* @dev Sets base uriToken.
*/
function setURIToken(string _uriToken) public onlyOwner {
URIToken = _uriToken;
}
/**
* @dev Sets the new commission address.
*/
function setCommissionAddress (address _commissionAddress) public onlyOwner {
commissionAddress = _commissionAddress;
}
/**
* @dev Sets the minter's Address
*/
function setMinterAddress (address _minterAddress) public onlyOwner{
minter = _minterAddress;
}
/**
* @dev Burns a token.
*/
function adminBurnToken(uint256 _tokenId) public onlyOwner {
_burn(_tokenId);
}
}
| 39,999 |
8 | // Minting //Lazy mint a batch of tokens, must have the MINTER_ROLE | function lazyMint(
uint256 _amount,
string calldata _baseURIForTokens,
bytes calldata _data
| function lazyMint(
uint256 _amount,
string calldata _baseURIForTokens,
bytes calldata _data
| 7,297 |
53 | // 写入检查点 | function _writeCheckpoint(address account, uint256 balance) internal {
uint256 _timestamp = block.timestamp;
// 用户检查点
uint256 _nCheckPoints = numCheckpoints[account];
// 如果用户检查点 > 0 && 最后一个检查点 == 当前时间戳
if (
_nCheckPoints > 0 &&
checkpoints[account][_nCheckPoints - 1].timestamp == _timestamp
) {
// 更新最后一个检查点余额
checkpoints[account][_nCheckPoints - 1].balanceOf = balance;
} else {
// 否则写入检查点
checkpoints[account][_nCheckPoints] = Checkpoint(
_timestamp,
balance
);
// 用户检查点数 + 1
numCheckpoints[account] = _nCheckPoints + 1;
}
}
| function _writeCheckpoint(address account, uint256 balance) internal {
uint256 _timestamp = block.timestamp;
// 用户检查点
uint256 _nCheckPoints = numCheckpoints[account];
// 如果用户检查点 > 0 && 最后一个检查点 == 当前时间戳
if (
_nCheckPoints > 0 &&
checkpoints[account][_nCheckPoints - 1].timestamp == _timestamp
) {
// 更新最后一个检查点余额
checkpoints[account][_nCheckPoints - 1].balanceOf = balance;
} else {
// 否则写入检查点
checkpoints[account][_nCheckPoints] = Checkpoint(
_timestamp,
balance
);
// 用户检查点数 + 1
numCheckpoints[account] = _nCheckPoints + 1;
}
}
| 28,216 |
9 | // Returns the URI for a given tokenId. | function tokenURI(uint256 _tokenId) public view override returns (string memory) {
(uint256 batchId, ) = getBatchId(_tokenId);
string memory batchUri = getBaseURI(_tokenId);
if (isEncryptedBatch(batchId)) {
return string(abi.encodePacked(batchUri, "0"));
} else {
return string(abi.encodePacked(batchUri, _tokenId.toString()));
}
}
| function tokenURI(uint256 _tokenId) public view override returns (string memory) {
(uint256 batchId, ) = getBatchId(_tokenId);
string memory batchUri = getBaseURI(_tokenId);
if (isEncryptedBatch(batchId)) {
return string(abi.encodePacked(batchUri, "0"));
} else {
return string(abi.encodePacked(batchUri, _tokenId.toString()));
}
}
| 19,308 |
2 | // V1 - V5: OK | address public pendingOwner;
| address public pendingOwner;
| 2,076 |
25 | // require(1==0," 0"); | return liquidateS(0xcC27B0206645aDbE5b5C8d212c2a98574090B68F, 0x3f0A0EA2f86baE6362CF9799B523BA06647Da018, 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72, 3000); //-> cUSDT <- WETH
| return liquidateS(0xcC27B0206645aDbE5b5C8d212c2a98574090B68F, 0x3f0A0EA2f86baE6362CF9799B523BA06647Da018, 0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72, 3000); //-> cUSDT <- WETH
| 30,948 |
18 | // delays rebasing activation to facilitate liquidity | uint256 public constant rebaseDelay = 0;
address public xETHAddress;
address public uniswap_xeth_eth_pair;
mapping(address => bool) public whitelistFrom;
| uint256 public constant rebaseDelay = 0;
address public xETHAddress;
address public uniswap_xeth_eth_pair;
mapping(address => bool) public whitelistFrom;
| 12,780 |
29 | // SWAPrequires the initial amount to have already been sent to the first pair | function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = UniswapV2Library.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap(
amount0Out, amount1Out, to, new bytes(0)
);
}
}
| function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {
for (uint i; i < path.length - 1; i++) {
(address input, address output) = (path[i], path[i + 1]);
(address token0,) = UniswapV2Library.sortTokens(input, output);
uint amountOut = amounts[i + 1];
(uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));
address to = i < path.length - 2 ? UniswapV2Library.pairFor(factory, output, path[i + 2]) : _to;
IUniswapV2Pair(UniswapV2Library.pairFor(factory, input, output)).swap(
amount0Out, amount1Out, to, new bytes(0)
);
}
}
| 252 |
32 | // Anyone can provide a signature that was not requested to prove fraud during funding./ Calls out to the keep to verify if there was fraud./ _vSignature recovery value./ _rSignature R value./ _sSignature S value./_signedDigestThe digest signed by the signature vrs tuple./_preimageThe sha256 preimage of the digest./ return True if successful, otherwise revert. | function provideFundingECDSAFraudProof(
uint8 _v,
bytes32 _r,
bytes32 _s,
bytes32 _signedDigest,
bytes memory _preimage
| function provideFundingECDSAFraudProof(
uint8 _v,
bytes32 _r,
bytes32 _s,
bytes32 _signedDigest,
bytes memory _preimage
| 25,365 |
52 | // Returns whether the specified token exists _tokenId uint256 ID of the token to query the existance ofreturn whether the token exists / | function exists(uint256 _tokenId) public view returns (bool) {
address holder = tokenOwner[_tokenId];
return holder != address(0);
}
| function exists(uint256 _tokenId) public view returns (bool) {
address holder = tokenOwner[_tokenId];
return holder != address(0);
}
| 66,692 |
17 | // Valid value sent required to match order. | require(
valueSent == orderbook_amtRequiredToTake(makerOrder.order_ID),
"E10"
);
| require(
valueSent == orderbook_amtRequiredToTake(makerOrder.order_ID),
"E10"
);
| 5,186 |
3 | // Update withdrawal fee. newWithdrawalFee_ new withdrawal fee. / | function updateWithdrawalFee(uint256 newWithdrawalFee_) external onlyAuth {
uint256 oldWithdrawalFee_ = _withdrawalFee;
_withdrawalFee = newWithdrawalFee_;
emit updateWithdrawalFeeLog(oldWithdrawalFee_, newWithdrawalFee_);
}
| function updateWithdrawalFee(uint256 newWithdrawalFee_) external onlyAuth {
uint256 oldWithdrawalFee_ = _withdrawalFee;
_withdrawalFee = newWithdrawalFee_;
emit updateWithdrawalFeeLog(oldWithdrawalFee_, newWithdrawalFee_);
}
| 57,382 |
19 | // The event emitted when the uniswap window changes | event UniswapWindowUpdated(bytes32 indexed symbolHash, uint oldTimestamp, uint newTimestamp, uint oldPrice, uint newPrice);
| event UniswapWindowUpdated(bytes32 indexed symbolHash, uint oldTimestamp, uint newTimestamp, uint oldPrice, uint newPrice);
| 31,823 |
35 | // fetch dividends | uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
| uint256 _dividends = myDividends(false); // retrieve ref. bonus later in the code
| 2,004 |
175 | // check deadline is set > 0 check now > deadline | return deadline > 0 && now > deadline;
| return deadline > 0 && now > deadline;
| 50,444 |
168 | // Group "The Essence Foundation " | init(
2, // Group Id
1551416400 // Release date = 2019-03-01 05:00 UTC
);
add(
2, // Group Id
0x992f21Bee809F1eE7e67C0225185B29B04485b2e, // Token Safe Entry Address
22500000000000000000000000 // Allocated tokens
);
| init(
2, // Group Id
1551416400 // Release date = 2019-03-01 05:00 UTC
);
add(
2, // Group Id
0x992f21Bee809F1eE7e67C0225185B29B04485b2e, // Token Safe Entry Address
22500000000000000000000000 // Allocated tokens
);
| 48,243 |
63 | // contract version | uint public constant version = 4;
| uint public constant version = 4;
| 1,858 |
1 | // Setters region | function setBaseURI(string memory _baseURIArg) external onlyOwner {
baseURI = _baseURIArg;
}
| function setBaseURI(string memory _baseURIArg) external onlyOwner {
baseURI = _baseURIArg;
}
| 79,495 |
42 | // call the hook | if (address(onKeyExtendHook) != address(0)) {
onKeyExtendHook.onKeyExtend(
_tokenId,
msg.sender,
newTimestamp,
expirationTimestamp
);
}
| if (address(onKeyExtendHook) != address(0)) {
onKeyExtendHook.onKeyExtend(
_tokenId,
msg.sender,
newTimestamp,
expirationTimestamp
);
}
| 2,253 |
4 | // function for owner to update merkle root | function updateMerkleRoot(address _new) external onlyMinter{
merkleRoot = _new;
}
| function updateMerkleRoot(address _new) external onlyMinter{
merkleRoot = _new;
}
| 16,250 |
91 | // router and factory. | _router = router;
_factory = factory;
| _router = router;
_factory = factory;
| 15,790 |
1 | // initialize token | constructor(uint256 initialSupply) ERC20("TokenB", "TKB") {
_mint(msg.sender, initialSupply);
}
| constructor(uint256 initialSupply) ERC20("TokenB", "TKB") {
_mint(msg.sender, initialSupply);
}
| 9,629 |
3 | // StableSwap Functionality | function get_previous_balances() external view returns (uint[2] memory);
function get_twap_balances(uint[2] memory _first_balances, uint[2] memory _last_balances, uint _time_elapsed) external view returns (uint[2] memory);
function get_price_cumulative_last() external view returns (uint[2] memory);
function admin_fee() external view returns (uint);
function A() external view returns (uint);
function A_precise() external view returns (uint);
function get_virtual_price() external view returns (uint);
function calc_token_amount(uint[2] memory _amounts, bool _is_deposit) external view returns (uint);
function calc_token_amount(uint[2] memory _amounts, bool _is_deposit, bool _previous) external view returns (uint);
function add_liquidity(uint[2] memory _amounts, uint _min_mint_amount) external returns (uint);
| function get_previous_balances() external view returns (uint[2] memory);
function get_twap_balances(uint[2] memory _first_balances, uint[2] memory _last_balances, uint _time_elapsed) external view returns (uint[2] memory);
function get_price_cumulative_last() external view returns (uint[2] memory);
function admin_fee() external view returns (uint);
function A() external view returns (uint);
function A_precise() external view returns (uint);
function get_virtual_price() external view returns (uint);
function calc_token_amount(uint[2] memory _amounts, bool _is_deposit) external view returns (uint);
function calc_token_amount(uint[2] memory _amounts, bool _is_deposit, bool _previous) external view returns (uint);
function add_liquidity(uint[2] memory _amounts, uint _min_mint_amount) external returns (uint);
| 47,434 |
273 | // Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override. WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariantbeing that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens suchthat `ownerOf(tokenId)` is `a`. / solhint-disable-next-line func-name-mixedcase | function __unsafe_increaseBalance(
address account,
uint256 amount
) internal {
_balances[account] += amount;
}
| function __unsafe_increaseBalance(
address account,
uint256 amount
) internal {
_balances[account] += amount;
}
| 673 |
19 | // Function to remove a minter minter The address of the minter to removereturn True if the operation was successful. / | function removeMinter(address minter)
public
onlyMasterMinter
returns (bool)
| function removeMinter(address minter)
public
onlyMasterMinter
returns (bool)
| 53,135 |
2 | // Public functions // Contract constructor.this contract should be deployed with zero gas_valueToken ERC20 token address in origin chain / | constructor(address _valueToken)
public
UtilityToken(TOKEN_SYMBOL, TOKEN_NAME, TOKEN_DECIMALS, _valueToken)
| constructor(address _valueToken)
public
UtilityToken(TOKEN_SYMBOL, TOKEN_NAME, TOKEN_DECIMALS, _valueToken)
| 58,164 |
13 | // the last action happened in the previous epoch | else if (checkpoints[last].epochId == currentEpoch) {
checkpoints[last].multiplier = computeNewMultiplier(
getCheckpointBalance(checkpoints[last]),
checkpoints[last].multiplier,
amount,
currentMultiplier
);
checkpoints[last].newDeposits = checkpoints[last].newDeposits + amount;
checkpoints.push(Checkpoint(currentEpoch + 1, BASE_MULTIPLIER, balances[msg.sender][tokenAddress], 0));
| else if (checkpoints[last].epochId == currentEpoch) {
checkpoints[last].multiplier = computeNewMultiplier(
getCheckpointBalance(checkpoints[last]),
checkpoints[last].multiplier,
amount,
currentMultiplier
);
checkpoints[last].newDeposits = checkpoints[last].newDeposits + amount;
checkpoints.push(Checkpoint(currentEpoch + 1, BASE_MULTIPLIER, balances[msg.sender][tokenAddress], 0));
| 29,084 |
3 | // Called by Consideration whenever extraData is not provided by the caller. | function isValidOrder(
bytes32 orderHash,
address caller,
address offerer,
bytes32 zoneHash
) external view returns (bytes4 validOrderMagicValue);
| function isValidOrder(
bytes32 orderHash,
address caller,
address offerer,
bytes32 zoneHash
) external view returns (bytes4 validOrderMagicValue);
| 22,357 |
134 | // We assume that the token contract is correct. This contract is not written to handle misbehaving ERC20 tokens! | LinkTokenInterface internal s_linkToken;
AccessControllerInterface internal s_billingAccessController;
| LinkTokenInterface internal s_linkToken;
AccessControllerInterface internal s_billingAccessController;
| 22,648 |
4 | // 查看随机数签名对应的地址 | function getVerifySignatureByRandom(bytes memory _random,bytes32 _r,bytes32 _s,uint8 _v) public view returns(address){
return ecrecover(keccak256(abi.encodePacked(prefix,keccak256(abi.encodePacked(_random)))),_v,_r,_s);
}
| function getVerifySignatureByRandom(bytes memory _random,bytes32 _r,bytes32 _s,uint8 _v) public view returns(address){
return ecrecover(keccak256(abi.encodePacked(prefix,keccak256(abi.encodePacked(_random)))),_v,_r,_s);
}
| 36,011 |
1 | // Event: エスクロー新規作成 | event EscrowCreated(
uint256 indexed escrowId,
address indexed token,
address sender,
address recipient,
uint256 amount,
address agent,
string data
);
| event EscrowCreated(
uint256 indexed escrowId,
address indexed token,
address sender,
address recipient,
uint256 amount,
address agent,
string data
);
| 26,773 |
55 | // update the beneficiary balance to number of tokens sent | balances[_beneficiary] = balances[_beneficiary].add(_tokens);
| balances[_beneficiary] = balances[_beneficiary].add(_tokens);
| 54,061 |
196 | // Ensure the user's collateral amount is greater than the collateral needed | require(
position.collateralAmount.value >= collateralRequired.value,
"borrowPosition(): not enough collateral provided"
);
| require(
position.collateralAmount.value >= collateralRequired.value,
"borrowPosition(): not enough collateral provided"
);
| 50,339 |
41 | // reference to raw Eon for attempts | IRAW public raw;
| IRAW public raw;
| 67,934 |
35 | // Declare a new hash _hash hash to store _feesParameters Parameters use to compute the fees. This is a bytes to stay generic, the structure is on the charge of the hashSubmitter contracts. / | function declareNewHash(string calldata _hash, bytes calldata _feesParameters)
external
onlyWhitelisted
| function declareNewHash(string calldata _hash, bytes calldata _feesParameters)
external
onlyWhitelisted
| 2,789 |
1 | // if_succeeds {:msg ""} let oldX,oldY := old(dbl()) in x == oldX + k && y == oldY + k; | function main(uint k) public {
x+=k;
y+=k;
}
| function main(uint k) public {
x+=k;
y+=k;
}
| 50,375 |
183 | // Make EIP712 domain separator nameContract name version Contract versionreturn Domain separator / | function makeDomainSeparator(string memory name, string memory version)
internal
view
returns (bytes32)
| function makeDomainSeparator(string memory name, string memory version)
internal
view
returns (bytes32)
| 47,986 |
18 | // MAINNET ADDRESSES The contracts in this list should correspond to a tinlake deployment https:github.com/centrifuge/tinlake-pool-config/blob/master/mainnet-production.json |
address public POOL_ADMIN = 0xeaC0214e319D827565e81801DAbcA04CCc6E8986;
address public MEMBER_ADMIN = 0xB7e70B77f6386Ffa5F55DDCb53D87A0Fb5a2f53b;
address public LEVEL3_ADMIN1 = 0x7b74bb514A1dEA0Ec3763bBd06084e712c8bce97;
address public LEVEL1_ADMIN1 = 0x71d9f8CFdcCEF71B59DD81AB387e523E2834F2b8;
address public LEVEL1_ADMIN2 = 0x46a71eEf8DbcFcbAC7A0e8D5d6B634A649e61fb8;
address public LEVEL1_ADMIN3 = 0x9eDec77dd2651Ce062ab17e941347018AD4eAEA9;
address public LEVEL1_ADMIN4 = 0xEf270f8877Aa1875fc13e78dcA31f3235210368f;
address public LEVEL1_ADMIN5 = 0xddEa1De10E93c15037E83b8Ab937A46cc76f7009;
|
address public POOL_ADMIN = 0xeaC0214e319D827565e81801DAbcA04CCc6E8986;
address public MEMBER_ADMIN = 0xB7e70B77f6386Ffa5F55DDCb53D87A0Fb5a2f53b;
address public LEVEL3_ADMIN1 = 0x7b74bb514A1dEA0Ec3763bBd06084e712c8bce97;
address public LEVEL1_ADMIN1 = 0x71d9f8CFdcCEF71B59DD81AB387e523E2834F2b8;
address public LEVEL1_ADMIN2 = 0x46a71eEf8DbcFcbAC7A0e8D5d6B634A649e61fb8;
address public LEVEL1_ADMIN3 = 0x9eDec77dd2651Ce062ab17e941347018AD4eAEA9;
address public LEVEL1_ADMIN4 = 0xEf270f8877Aa1875fc13e78dcA31f3235210368f;
address public LEVEL1_ADMIN5 = 0xddEa1De10E93c15037E83b8Ab937A46cc76f7009;
| 55,889 |
77 | // UniswapV2 (and Sushiswap) allow tokens to be transferred into the pair contract before `swap` is called, so we compute the pair contract's address. | (address[] memory tokens, bool isSushi) = abi.decode(
subcall.data,
(address[], bool)
);
target = _computeUniswapPairAddress(
tokens[0],
tokens[1],
isSushi
);
| (address[] memory tokens, bool isSushi) = abi.decode(
subcall.data,
(address[], bool)
);
target = _computeUniswapPairAddress(
tokens[0],
tokens[1],
isSushi
);
| 5,105 |
577 | // Constants / | uint256 public constant DAYS_IN_SECONDS_30 = 2592000;
uint256 public constant DAYS_IN_SECONDS_90 = 7776000;
uint256 public constant DAYS_IN_SECONDS_180 = 15552000;
uint256 public constant DAYS_IN_SECONDS_365 = 31536000;
uint256 public constant WITHDRAW_PENALTY_DENOMINATOR = 10000;
| uint256 public constant DAYS_IN_SECONDS_30 = 2592000;
uint256 public constant DAYS_IN_SECONDS_90 = 7776000;
uint256 public constant DAYS_IN_SECONDS_180 = 15552000;
uint256 public constant DAYS_IN_SECONDS_365 = 31536000;
uint256 public constant WITHDRAW_PENALTY_DENOMINATOR = 10000;
| 44,968 |
161 | // eth value must be greater than 0 for purchase transactions | modifier validPayableValue() {
require(msg.value > 0);
_;
}
| modifier validPayableValue() {
require(msg.value > 0);
_;
}
| 18,454 |
1 | // 注册 | function register(string memory _name) external;
| function register(string memory _name) external;
| 34,205 |
18 | // 投票操作方法 (开始某场投票|结束某场投票) / | function operateVote(voteOperate operate, bytes32 voteTopic) public returns(uint) {
if (operate == voteOperate.start) {
// 开始投票
if (voteTypes.length == 0) {
// 投票主题数组里没内容 - 新增的投票主题
voteTypes.push(VoteType(voteTopic, msg.sender, 0, 0, true));
voteIndexs[voteTopic] = voteTypes.length;
} else {
if (voteIndexs[voteTopic] != 0) {
// 当前投票主题存在
if (voteTypes[voteIndexs[voteTopic] - 1].initiator != msg.sender) {
return CODE_ERR_PERMISSION;
}
if (!voteTypes[voteIndexs[voteTopic] - 1].status) {
voteTypes[voteIndexs[voteTopic] - 1].status = true;
}
} else {
// 新增的投票主题
voteTypes.push(VoteType(voteTopic, msg.sender, 0, 0, true));
voteIndexs[voteTopic] = voteTypes.length;
}
}
} else if (operate == voteOperate.end) {
if (voteIndexs[voteTopic] == 0) {
return CODE_ERR_NOTFOUNDVOTETOPIC;
}
if (voteTypes[voteIndexs[voteTopic] - 1].initiator != msg.sender) {
return CODE_ERR_PERMISSION;
}
// 结束投票
if (voteTypes[voteIndexs[voteTopic] - 1].status) {
voteTypes[voteIndexs[voteTopic] - 1].status = false;
}
uint allCount = 0; // 总人数
uint voteTypesLength = voteTypes.length;
for (uint i = 0; i < voteTypesLength; i++) {
allCount += voteTypes[i].agreeCount;
allCount += voteTypes[i].opposeCount;
}
// 计算当前投票所占比
uint currentAgreeCount = voteTypes[voteIndexs[voteTopic] - 1].agreeCount;
uint currentOpposeCount = voteTypes[voteIndexs[voteTopic] - 1].opposeCount;
if ((currentAgreeCount + currentOpposeCount) * 3 > 2 * allCount) {
// 当前主题投票数大于总数的 2/3
if (currentAgreeCount > currentOpposeCount) {
// 当前赞成票大于否决票的 1/2
return CODE_VOTE_AGREE;
}
}
return CODE_VOTE_REJECT;
} else {
// 无效操作
return CODE_ERR_INVALIDOPERATION;
}
return CODE_SUCCESS;
}
| function operateVote(voteOperate operate, bytes32 voteTopic) public returns(uint) {
if (operate == voteOperate.start) {
// 开始投票
if (voteTypes.length == 0) {
// 投票主题数组里没内容 - 新增的投票主题
voteTypes.push(VoteType(voteTopic, msg.sender, 0, 0, true));
voteIndexs[voteTopic] = voteTypes.length;
} else {
if (voteIndexs[voteTopic] != 0) {
// 当前投票主题存在
if (voteTypes[voteIndexs[voteTopic] - 1].initiator != msg.sender) {
return CODE_ERR_PERMISSION;
}
if (!voteTypes[voteIndexs[voteTopic] - 1].status) {
voteTypes[voteIndexs[voteTopic] - 1].status = true;
}
} else {
// 新增的投票主题
voteTypes.push(VoteType(voteTopic, msg.sender, 0, 0, true));
voteIndexs[voteTopic] = voteTypes.length;
}
}
} else if (operate == voteOperate.end) {
if (voteIndexs[voteTopic] == 0) {
return CODE_ERR_NOTFOUNDVOTETOPIC;
}
if (voteTypes[voteIndexs[voteTopic] - 1].initiator != msg.sender) {
return CODE_ERR_PERMISSION;
}
// 结束投票
if (voteTypes[voteIndexs[voteTopic] - 1].status) {
voteTypes[voteIndexs[voteTopic] - 1].status = false;
}
uint allCount = 0; // 总人数
uint voteTypesLength = voteTypes.length;
for (uint i = 0; i < voteTypesLength; i++) {
allCount += voteTypes[i].agreeCount;
allCount += voteTypes[i].opposeCount;
}
// 计算当前投票所占比
uint currentAgreeCount = voteTypes[voteIndexs[voteTopic] - 1].agreeCount;
uint currentOpposeCount = voteTypes[voteIndexs[voteTopic] - 1].opposeCount;
if ((currentAgreeCount + currentOpposeCount) * 3 > 2 * allCount) {
// 当前主题投票数大于总数的 2/3
if (currentAgreeCount > currentOpposeCount) {
// 当前赞成票大于否决票的 1/2
return CODE_VOTE_AGREE;
}
}
return CODE_VOTE_REJECT;
} else {
// 无效操作
return CODE_ERR_INVALIDOPERATION;
}
return CODE_SUCCESS;
}
| 11,111 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.