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 |
|---|---|---|---|---|
49 | // share 30% of the wrapped Ether as a profit sharing reward | notifyProfitInRewardToken(wethBalance);
uint256 remainingWethBalance = IERC20(weth).balanceOf(address(this));
IERC20(weth).safeApprove(uni, 0);
IERC20(weth).safeApprove(uni, remainingWethBalance.div(2));
| notifyProfitInRewardToken(wethBalance);
uint256 remainingWethBalance = IERC20(weth).balanceOf(address(this));
IERC20(weth).safeApprove(uni, 0);
IERC20(weth).safeApprove(uni, remainingWethBalance.div(2));
| 19,406 |
17 | // Once the owner loads the data, this is set to true, and the data is locked | bool public compressedDataLoaded;
| bool public compressedDataLoaded;
| 18,426 |
195 | // Calculate the new borrow amount | TypesV1.Par memory newPar = position.borrowedAmount.add(
TypesV1.Par({
sign: false,
value: borrowAmount.to128()
})
| TypesV1.Par memory newPar = position.borrowedAmount.add(
TypesV1.Par({
sign: false,
value: borrowAmount.to128()
})
| 32,826 |
26 | // Get total voters count . return total voters count./ | function getTotalVoters() external view returns (uint256) {
return voters.length;
}
| function getTotalVoters() external view returns (uint256) {
return voters.length;
}
| 22,086 |
253 | // Transfers `nftIndex` from `from` to `to`. | * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `nftIndex` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 nftIndex) internal virtual {
require(ownerOf(nftIndex) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, nftIndex);
// Clear approvals from the previous owner
_approve(address(0), nftIndex);
_holderTokens[from].remove(nftIndex);
_holderTokens[to].add(nftIndex);
_tokenOwners.set(nftIndex, to);
emit Transfer(from, to, nftIndex);
}
| * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `nftIndex` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 nftIndex) internal virtual {
require(ownerOf(nftIndex) == from, "ERC721: transfer of token that is not own");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, nftIndex);
// Clear approvals from the previous owner
_approve(address(0), nftIndex);
_holderTokens[from].remove(nftIndex);
_holderTokens[to].add(nftIndex);
_tokenOwners.set(nftIndex, to);
emit Transfer(from, to, nftIndex);
}
| 2,453 |
16 | // Returns true if the contract is frozen, and false otherwise. / | function isFrozen() public view returns (bool) {
return _frozen;
}
| function isFrozen() public view returns (bool) {
return _frozen;
}
| 41,354 |
416 | // Whether price of asset has been updated less than VALIDITY seconds ago/ofAsset Asset in registrar/ return isRecent Price information ofAsset is recent | function hasRecentPrice(address ofAsset)
view
pre_cond(assetIsRegistered(ofAsset))
returns (bool isRecent)
{
var ( , timestamp) = getPrice(ofAsset);
return (sub(now, timestamp) <= VALIDITY);
}
| function hasRecentPrice(address ofAsset)
view
pre_cond(assetIsRegistered(ofAsset))
returns (bool isRecent)
{
var ( , timestamp) = getPrice(ofAsset);
return (sub(now, timestamp) <= VALIDITY);
}
| 8,668 |
35 | // Set allowance for other address Allows `_spender` to spend no more than `_value` tokens in your behalf_spender The address authorized to spend_value the max amount they can spend/ | function approve(address _spender, uint256 _value) external returns (bool success) {
require(!safeguard);
/* AUDITOR NOTE:
Many dex and dapps pre-approve large amount of tokens to save gas for subsequent transaction. This is good use case.
On flip-side, some malicious dapp, may pre-approve large amount and then drain all token balance from user.
So following condition is kept in commented. It can be be kept that way or not based on client's consent.
*/
//require(_balanceOf[msg.sender] >= _value, "Balance does not have enough tokens");
_allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| function approve(address _spender, uint256 _value) external returns (bool success) {
require(!safeguard);
/* AUDITOR NOTE:
Many dex and dapps pre-approve large amount of tokens to save gas for subsequent transaction. This is good use case.
On flip-side, some malicious dapp, may pre-approve large amount and then drain all token balance from user.
So following condition is kept in commented. It can be be kept that way or not based on client's consent.
*/
//require(_balanceOf[msg.sender] >= _value, "Balance does not have enough tokens");
_allowance[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| 8,699 |
32 | // temporarily commented out to prevent 'out of gas' error during migration / /Eth payable fallback in case any Ether is accidentally sent / | // function () public payable {
// revert("Don't accept ETH");
// }
| // function () public payable {
// revert("Don't accept ETH");
// }
| 22,163 |
163 | // Helpers | function balanceOfWant() public view returns (uint _balance){
return want.balanceOf(address(this));
}
| function balanceOfWant() public view returns (uint _balance){
return want.balanceOf(address(this));
}
| 15,497 |
10 | // Visibility is `public` to enable it being called by other contracts for composition. | function renderTokenById(uint256 id) public view returns (string memory) {
string memory render = string(abi.encodePacked(
'<g id="tree" stroke="#',color[id].toColor(),'" fill="none">',
'<path d="M 0 90 A 90 90 0 1 1 40 80.62257748" stroke-width="10"/>',
'<path d="M 0 90 L 0 -80 M 0 50 L 64.701 -47.0515 M 0 50 L -64.701 -47.0515 M 0 10 L 49.8746 -64.812 M 0 10 L -49.8746 -64.812 M 0 -30 L 29.559 -74.3385 M 0 -30 L -29.559 -74.3385" stroke-width="',uint2str(leafiness[id]),'" />',
'</g>'
));
return render;
}
| function renderTokenById(uint256 id) public view returns (string memory) {
string memory render = string(abi.encodePacked(
'<g id="tree" stroke="#',color[id].toColor(),'" fill="none">',
'<path d="M 0 90 A 90 90 0 1 1 40 80.62257748" stroke-width="10"/>',
'<path d="M 0 90 L 0 -80 M 0 50 L 64.701 -47.0515 M 0 50 L -64.701 -47.0515 M 0 10 L 49.8746 -64.812 M 0 10 L -49.8746 -64.812 M 0 -30 L 29.559 -74.3385 M 0 -30 L -29.559 -74.3385" stroke-width="',uint2str(leafiness[id]),'" />',
'</g>'
));
return render;
}
| 46,217 |
54 | // reflecting sender and recipient balances | _rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
| _rOwned[sender] = _rOwned[sender].sub(rAmount);
_rOwned[recipient] = _rOwned[recipient].add(rTransferAmount);
| 39,578 |
4 | // Map of sale data hash to sale state | mapping(bytes32 => Sale) internal sales_;
| mapping(bytes32 => Sale) internal sales_;
| 62,315 |
4 | // ERC20 Events |
event Transfer(address indexed from, address indexed to, uint256 value);
|
event Transfer(address indexed from, address indexed to, uint256 value);
| 4,346 |
52 | // ============ Internal Functions ============ // Set or change of manager. _newManager New _manager address.return Boolean to indicate if the operation was successful or not. / | function _setManager(address _newManager) private returns (bool) {
address _previousManager = _manager;
require(_newManager != _previousManager, "Manageable/existing-manager-address");
_manager = _newManager;
emit ManagerTransferred(_previousManager, _newManager);
return true;
}
| function _setManager(address _newManager) private returns (bool) {
address _previousManager = _manager;
require(_newManager != _previousManager, "Manageable/existing-manager-address");
_manager = _newManager;
emit ManagerTransferred(_previousManager, _newManager);
return true;
}
| 42,336 |
3 | // donate to the campaign logic of the app | function donateToCampaign(uint256 _id) public payable{
uint256 amount = msg.value;
Campaign storage campaign = campaigns[_id];
campaign.donators.push(msg.sender);
campaign.donations.push(amount);
(bool sent,) = payable(campaign.owner).call{value:amount}("");
if(sent){
campaign.amountCollected = campaign.amountCollected + amount;
}
}
| function donateToCampaign(uint256 _id) public payable{
uint256 amount = msg.value;
Campaign storage campaign = campaigns[_id];
campaign.donators.push(msg.sender);
campaign.donations.push(amount);
(bool sent,) = payable(campaign.owner).call{value:amount}("");
if(sent){
campaign.amountCollected = campaign.amountCollected + amount;
}
}
| 26,356 |
23 | // Perform the swap with Uniswap V3 to the given token addresses and amounts. _totalAmountToSwap Total amount of erc20TokenOrigin to spend in swaps. _deadline The unix timestamp after a swap will fail. _swaps The array of the Swaps data. Swap ETH to ERC20. / | function performSwapV3ETH(
uint256 _totalAmountToSwap,
uint32 _deadline,
SwapV3[] calldata _swaps
| function performSwapV3ETH(
uint256 _totalAmountToSwap,
uint32 _deadline,
SwapV3[] calldata _swaps
| 28,015 |
10 | // Event for token purchase logging purchaser who paid for the tokens beneficiary who got the tokens value weis paid for purchase amount amount of tokens purchased / | event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
| event TokensPurchased(
address indexed purchaser,
address indexed beneficiary,
uint256 value,
uint256 amount
);
| 9,916 |
77 | // This would be token B as described above | Swap memory secondSwap = swapSequences[i][1];
IBPool poolSecondSwap = IBPool(secondSwap.pool);
intermediateTokenAmount = poolSecondSwap.calcInGivenOut(
poolSecondSwap.getBalance(secondSwap.tokenIn),
poolSecondSwap.getDenormalizedWeight(secondSwap.tokenIn),
poolSecondSwap.getBalance(secondSwap.tokenOut),
poolSecondSwap.getDenormalizedWeight(secondSwap.tokenOut),
secondSwap.swapAmount,
poolSecondSwap.swapFee()
);
| Swap memory secondSwap = swapSequences[i][1];
IBPool poolSecondSwap = IBPool(secondSwap.pool);
intermediateTokenAmount = poolSecondSwap.calcInGivenOut(
poolSecondSwap.getBalance(secondSwap.tokenIn),
poolSecondSwap.getDenormalizedWeight(secondSwap.tokenIn),
poolSecondSwap.getBalance(secondSwap.tokenOut),
poolSecondSwap.getDenormalizedWeight(secondSwap.tokenOut),
secondSwap.swapAmount,
poolSecondSwap.swapFee()
);
| 32,596 |
5 | // My Custom ERC1155 Conditional Minting This is an example repository that mints ERC1155 tokens if sender owns a specific ERC721. @custom:type eip-2535-facet@custom:category NFTs@custom:required-dependencies IERC1155MintableExtension / | contract MyERC1155ConditionalMint is OwnableInternal {
bytes32 internal constant STORAGE_SLOT = keccak256("v1.my-amazing-team.contracts.storage.MyERC1155ConditionalMint");
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
/**
* (1) Define state variables
*
* We must put all contract "state" variables in the Layout struct.
* This storage pattern enables modularization using the EIP-2325 Diamond Standard.
*
* To learn more about this pattern, see the following resources:
* - https://eips.ethereum.org/EIPS/eip-2325
* - https://eip2535diamonds.substack.com
*/
struct Layout {
address targetERC721ContractAddress;
uint256 maxAllowancePerERC721;
mapping(uint256 => uint256) tokensToMintedAmount;
}
/**
* (2) Define custom functions
*
* You can put privileged functions (using Ownable or role-based AccessControl) here.
*/
function setTargetERC721(address target) external onlyOwner {
layout().targetERC721ContractAddress = target;
}
function setMaxAllowancePerERC721(uint256 allowance) external onlyOwner {
layout().maxAllowancePerERC721 = allowance;
}
function claimByERC721(
uint256 ownedTokenId, // Token ID in ERC721 collection.
uint256 claimTokenId, // Token ID in ERC1155 to be minted.
uint256 count // How many of this ERC1155 token to mint?
) external {
Layout storage l = layout();
require(IERC721(l.targetERC721ContractAddress).ownerOf(ownedTokenId) == _msgSender(), "MAX_ALLOWANCE");
l.tokensToMintedAmount[ownedTokenId] += count;
require(l.tokensToMintedAmount[ownedTokenId] <= l.maxAllowancePerERC721, "MAX_ALLOWANCE");
IERC1155MintableExtension(address(this)).mintByFacet(_msgSender(), claimTokenId, count, "");
}
}
| contract MyERC1155ConditionalMint is OwnableInternal {
bytes32 internal constant STORAGE_SLOT = keccak256("v1.my-amazing-team.contracts.storage.MyERC1155ConditionalMint");
function layout() internal pure returns (Layout storage l) {
bytes32 slot = STORAGE_SLOT;
assembly {
l.slot := slot
}
}
/**
* (1) Define state variables
*
* We must put all contract "state" variables in the Layout struct.
* This storage pattern enables modularization using the EIP-2325 Diamond Standard.
*
* To learn more about this pattern, see the following resources:
* - https://eips.ethereum.org/EIPS/eip-2325
* - https://eip2535diamonds.substack.com
*/
struct Layout {
address targetERC721ContractAddress;
uint256 maxAllowancePerERC721;
mapping(uint256 => uint256) tokensToMintedAmount;
}
/**
* (2) Define custom functions
*
* You can put privileged functions (using Ownable or role-based AccessControl) here.
*/
function setTargetERC721(address target) external onlyOwner {
layout().targetERC721ContractAddress = target;
}
function setMaxAllowancePerERC721(uint256 allowance) external onlyOwner {
layout().maxAllowancePerERC721 = allowance;
}
function claimByERC721(
uint256 ownedTokenId, // Token ID in ERC721 collection.
uint256 claimTokenId, // Token ID in ERC1155 to be minted.
uint256 count // How many of this ERC1155 token to mint?
) external {
Layout storage l = layout();
require(IERC721(l.targetERC721ContractAddress).ownerOf(ownedTokenId) == _msgSender(), "MAX_ALLOWANCE");
l.tokensToMintedAmount[ownedTokenId] += count;
require(l.tokensToMintedAmount[ownedTokenId] <= l.maxAllowancePerERC721, "MAX_ALLOWANCE");
IERC1155MintableExtension(address(this)).mintByFacet(_msgSender(), claimTokenId, count, "");
}
}
| 36,391 |
44 | // Transfer ownership of an NFT -- THE CALLER IS RESPONSIBLE/TO CONFIRM THAT `_to` IS CAPABLE OF RECEIVING NFTS OR ELSE/THEY MAY BE PERMANENTLY LOST/Throws unless `msg.sender` is the current owner, an authorized/operator, or the approved address for this NFT. Throws if `_from` is/not the current owner. Throws if `_to` is the zero address. Throws if/`_tokenId` is not a valid NFT./_from The current owner of the NFT/_to The new owner/_tokenId The NFT to transfer | function transferFrom(
address _from,
address _to,
uint256 _tokenId
| function transferFrom(
address _from,
address _to,
uint256 _tokenId
| 2,259 |
100 | // split the liquidity | uint256 half = forLiquidity.div(2);
uint256 otherHalf = forLiquidity.sub(half);
| uint256 half = forLiquidity.div(2);
uint256 otherHalf = forLiquidity.sub(half);
| 5,985 |
80 | // Gets the current value of the position. The value is zero if you didn't make any deposits in the liquidity pool.return Returns the value of the position expressed in collateral tokens. / | function getCollateralValue () external view ifInitialized returns (uint256) {
uint256 currentBalance = IERC20(poolAddress).balanceOf(address(this));
uint256 exchangeRate = IClearPoolBase(poolAddress).getCurrentExchangeRate();
return (currentBalance * exchangeRate) / 1e18;
}
| function getCollateralValue () external view ifInitialized returns (uint256) {
uint256 currentBalance = IERC20(poolAddress).balanceOf(address(this));
uint256 exchangeRate = IClearPoolBase(poolAddress).getCurrentExchangeRate();
return (currentBalance * exchangeRate) / 1e18;
}
| 16,260 |
29 | // Smart contract library of mathematical functions operating with signed64.64-bit fixed point numbers.Signed 64.64-bit fixed point number isbasically a simple fraction whose numerator is signed 128-bit integer anddenominator is 2^64.As long as denominator is always the same, there is noneed to store it, thus in Solidity signed 64.64-bit fixed point numbers arerepresented by int128 type holding only the numerator. / | library ABDKMath64x64 {
/*
* Minimum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
/*
* Maximum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Convert signed 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromInt (int256 x) internal pure returns (int128) {
unchecked {
require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
return int128 (x << 64);
}
}
/**
* Convert signed 64.64 fixed point number into signed 64-bit integer number
* rounding down.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64-bit integer number
*/
function toInt (int128 x) internal pure returns (int64) {
unchecked {
return int64 (x >> 64);
}
}
/**
* Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromUInt (uint256 x) internal pure returns (int128) {
unchecked {
require (x <= 0x7FFFFFFFFFFFFFFF);
return int128 (int256 (x << 64));
}
}
/**
* Convert signed 64.64 fixed point number into unsigned 64-bit integer
* number rounding down. Revert on underflow.
*
* @param x signed 64.64-bit fixed point number
* @return unsigned 64-bit integer number
*/
function toUInt (int128 x) internal pure returns (uint64) {
unchecked {
require (x >= 0);
return uint64 (uint128 (x >> 64));
}
}
/**
* Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
* number rounding down. Revert on overflow.
*
* @param x signed 128.128-bin fixed point number
* @return signed 64.64-bit fixed point number
*/
function from128x128 (int256 x) internal pure returns (int128) {
unchecked {
int256 result = x >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Convert signed 64.64 fixed point number into signed 128.128 fixed point
* number.
*
* @param x signed 64.64-bit fixed point number
* @return signed 128.128 fixed point number
*/
function to128x128 (int128 x) internal pure returns (int256) {
unchecked {
return int256 (x) << 64;
}
}
/**
* Calculate x + y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function add (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x - y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sub (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding down. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function mul (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
* number and y is signed 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y signed 256-bit integer number
* @return signed 256-bit integer number
*/
function muli (int128 x, int256 y) internal pure returns (int256) {
unchecked {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
}
/**
* Calculate x * y rounding down, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y unsigned 256-bit integer number
* @return unsigned 256-bit integer number
*/
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (int256 (x)) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
}
/**
* Calculate x / y rounding towards zero. Revert on overflow or when y is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function div (int128 x, int128 y) internal pure returns (int128) {
unchecked {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x / y rounding towards zero, where x and y are signed 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x signed 256-bit integer number
* @param y signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divi (int256 x, int256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x; // We rely on overflow behavior here
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult); // We rely on overflow behavior here
}
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divu (uint256 x, uint256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
}
/**
* Calculate -x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function neg (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return -x;
}
}
/**
* Calculate |x|. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function abs (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
}
/**
* Calculate 1 / x rounding towards zero. Revert on overflow or when x is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function inv (int128 x) internal pure returns (int128) {
unchecked {
require (x != 0);
int256 result = int256 (0x100000000000000000000000000000000) / x;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function avg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
return int128 ((int256 (x) + int256 (y)) >> 1);
}
}
/**
* Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
* Revert on overflow or in case x * y is negative.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function gavg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 m = int256 (x) * int256 (y);
require (m >= 0);
require (m <
0x4000000000000000000000000000000000000000000000000000000000000000);
return int128 (sqrtu (uint256 (m)));
}
}
/**
* Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y uint256 value
* @return signed 64.64-bit fixed point number
*/
function pow (int128 x, uint256 y) internal pure returns (int128) {
unchecked {
bool negative = x < 0 && y & 1 == 1;
uint256 absX = uint128 (x < 0 ? -x : x);
uint256 absResult;
absResult = 0x100000000000000000000000000000000;
if (absX <= 0x10000000000000000) {
absX <<= 63;
while (y != 0) {
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x2 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x4 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x8 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
y >>= 4;
}
absResult >>= 64;
} else {
uint256 absXShift = 63;
if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }
uint256 resultShift = 0;
while (y != 0) {
require (absXShift < 64);
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
resultShift += absXShift;
if (absResult > 0x100000000000000000000000000000000) {
absResult >>= 1;
resultShift += 1;
}
}
absX = absX * absX >> 127;
absXShift <<= 1;
if (absX >= 0x100000000000000000000000000000000) {
absX >>= 1;
absXShift += 1;
}
y >>= 1;
}
require (resultShift < 64);
absResult >>= 64 - resultShift;
}
int256 result = negative ? -int256 (absResult) : int256 (absResult);
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate sqrt (x) rounding down. Revert if x < 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sqrt (int128 x) internal pure returns (int128) {
unchecked {
require (x >= 0);
return int128 (sqrtu (uint256 (int256 (x)) << 64));
}
}
/**
* Calculate binary logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function log_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
int256 msb = 0;
int256 xc = x;
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
int256 result = msb - 64 << 64;
uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
ux *= ux;
uint256 b = ux >> 255;
ux >>= 127 + b;
result += bit * int256 (b);
}
return int128 (result);
}
}
/**
* Calculate natural logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function ln (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
return int128 (int256 (
uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
}
}
/**
* Calculate binary exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= uint256 (int256 (63 - (x >> 64)));
require (result <= uint256 (int256 (MAX_64x64)));
return int128 (int256 (result));
}
}
/**
* Calculate natural exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return unsigned 64.64-bit fixed point number
*/
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
unchecked {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
assert (xh == hi >> 128);
result += xl / y;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
}
/**
* Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
* number.
*
* @param x unsigned 256-bit integer number
* @return unsigned 128-bit integer number
*/
function sqrtu (uint256 x) private pure returns (uint128) {
unchecked {
if (x == 0) return 0;
else {
uint256 xx = x;
uint256 r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x4) { r <<= 1; }
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
}
}
| library ABDKMath64x64 {
/*
* Minimum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MIN_64x64 = -0x80000000000000000000000000000000;
/*
* Maximum value signed 64.64-bit fixed point number may have.
*/
int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
/**
* Convert signed 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromInt (int256 x) internal pure returns (int128) {
unchecked {
require (x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF);
return int128 (x << 64);
}
}
/**
* Convert signed 64.64 fixed point number into signed 64-bit integer number
* rounding down.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64-bit integer number
*/
function toInt (int128 x) internal pure returns (int64) {
unchecked {
return int64 (x >> 64);
}
}
/**
* Convert unsigned 256-bit integer number into signed 64.64-bit fixed point
* number. Revert on overflow.
*
* @param x unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function fromUInt (uint256 x) internal pure returns (int128) {
unchecked {
require (x <= 0x7FFFFFFFFFFFFFFF);
return int128 (int256 (x << 64));
}
}
/**
* Convert signed 64.64 fixed point number into unsigned 64-bit integer
* number rounding down. Revert on underflow.
*
* @param x signed 64.64-bit fixed point number
* @return unsigned 64-bit integer number
*/
function toUInt (int128 x) internal pure returns (uint64) {
unchecked {
require (x >= 0);
return uint64 (uint128 (x >> 64));
}
}
/**
* Convert signed 128.128 fixed point number into signed 64.64-bit fixed point
* number rounding down. Revert on overflow.
*
* @param x signed 128.128-bin fixed point number
* @return signed 64.64-bit fixed point number
*/
function from128x128 (int256 x) internal pure returns (int128) {
unchecked {
int256 result = x >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Convert signed 64.64 fixed point number into signed 128.128 fixed point
* number.
*
* @param x signed 64.64-bit fixed point number
* @return signed 128.128 fixed point number
*/
function to128x128 (int128 x) internal pure returns (int256) {
unchecked {
return int256 (x) << 64;
}
}
/**
* Calculate x + y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function add (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) + y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x - y. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sub (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) - y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding down. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function mul (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 result = int256(x) * y >> 64;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x * y rounding towards zero, where x is signed 64.64 fixed point
* number and y is signed 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y signed 256-bit integer number
* @return signed 256-bit integer number
*/
function muli (int128 x, int256 y) internal pure returns (int256) {
unchecked {
if (x == MIN_64x64) {
require (y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF &&
y <= 0x1000000000000000000000000000000000000000000000000);
return -y << 63;
} else {
bool negativeResult = false;
if (x < 0) {
x = -x;
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint256 absoluteResult = mulu (x, uint256 (y));
if (negativeResult) {
require (absoluteResult <=
0x8000000000000000000000000000000000000000000000000000000000000000);
return -int256 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <=
0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int256 (absoluteResult);
}
}
}
}
/**
* Calculate x * y rounding down, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64 fixed point number
* @param y unsigned 256-bit integer number
* @return unsigned 256-bit integer number
*/
function mulu (int128 x, uint256 y) internal pure returns (uint256) {
unchecked {
if (y == 0) return 0;
require (x >= 0);
uint256 lo = (uint256 (int256 (x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64;
uint256 hi = uint256 (int256 (x)) * (y >> 128);
require (hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
hi <<= 64;
require (hi <=
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo);
return hi + lo;
}
}
/**
* Calculate x / y rounding towards zero. Revert on overflow or when y is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function div (int128 x, int128 y) internal pure returns (int128) {
unchecked {
require (y != 0);
int256 result = (int256 (x) << 64) / y;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate x / y rounding towards zero, where x and y are signed 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x signed 256-bit integer number
* @param y signed 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divi (int256 x, int256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
bool negativeResult = false;
if (x < 0) {
x = -x; // We rely on overflow behavior here
negativeResult = true;
}
if (y < 0) {
y = -y; // We rely on overflow behavior here
negativeResult = !negativeResult;
}
uint128 absoluteResult = divuu (uint256 (x), uint256 (y));
if (negativeResult) {
require (absoluteResult <= 0x80000000000000000000000000000000);
return -int128 (absoluteResult); // We rely on overflow behavior here
} else {
require (absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return int128 (absoluteResult); // We rely on overflow behavior here
}
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return signed 64.64-bit fixed point number
*/
function divu (uint256 x, uint256 y) internal pure returns (int128) {
unchecked {
require (y != 0);
uint128 result = divuu (x, y);
require (result <= uint128 (MAX_64x64));
return int128 (result);
}
}
/**
* Calculate -x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function neg (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return -x;
}
}
/**
* Calculate |x|. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function abs (int128 x) internal pure returns (int128) {
unchecked {
require (x != MIN_64x64);
return x < 0 ? -x : x;
}
}
/**
* Calculate 1 / x rounding towards zero. Revert on overflow or when x is
* zero.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function inv (int128 x) internal pure returns (int128) {
unchecked {
require (x != 0);
int256 result = int256 (0x100000000000000000000000000000000) / x;
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function avg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
return int128 ((int256 (x) + int256 (y)) >> 1);
}
}
/**
* Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down.
* Revert on overflow or in case x * y is negative.
*
* @param x signed 64.64-bit fixed point number
* @param y signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function gavg (int128 x, int128 y) internal pure returns (int128) {
unchecked {
int256 m = int256 (x) * int256 (y);
require (m >= 0);
require (m <
0x4000000000000000000000000000000000000000000000000000000000000000);
return int128 (sqrtu (uint256 (m)));
}
}
/**
* Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number
* and y is unsigned 256-bit integer number. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @param y uint256 value
* @return signed 64.64-bit fixed point number
*/
function pow (int128 x, uint256 y) internal pure returns (int128) {
unchecked {
bool negative = x < 0 && y & 1 == 1;
uint256 absX = uint128 (x < 0 ? -x : x);
uint256 absResult;
absResult = 0x100000000000000000000000000000000;
if (absX <= 0x10000000000000000) {
absX <<= 63;
while (y != 0) {
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x2 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x4 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
if (y & 0x8 != 0) {
absResult = absResult * absX >> 127;
}
absX = absX * absX >> 127;
y >>= 4;
}
absResult >>= 64;
} else {
uint256 absXShift = 63;
if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; }
if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; }
if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; }
if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; }
if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; }
if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; }
uint256 resultShift = 0;
while (y != 0) {
require (absXShift < 64);
if (y & 0x1 != 0) {
absResult = absResult * absX >> 127;
resultShift += absXShift;
if (absResult > 0x100000000000000000000000000000000) {
absResult >>= 1;
resultShift += 1;
}
}
absX = absX * absX >> 127;
absXShift <<= 1;
if (absX >= 0x100000000000000000000000000000000) {
absX >>= 1;
absXShift += 1;
}
y >>= 1;
}
require (resultShift < 64);
absResult >>= 64 - resultShift;
}
int256 result = negative ? -int256 (absResult) : int256 (absResult);
require (result >= MIN_64x64 && result <= MAX_64x64);
return int128 (result);
}
}
/**
* Calculate sqrt (x) rounding down. Revert if x < 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function sqrt (int128 x) internal pure returns (int128) {
unchecked {
require (x >= 0);
return int128 (sqrtu (uint256 (int256 (x)) << 64));
}
}
/**
* Calculate binary logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function log_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
int256 msb = 0;
int256 xc = x;
if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; }
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
int256 result = msb - 64 << 64;
uint256 ux = uint256 (int256 (x)) << uint256 (127 - msb);
for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) {
ux *= ux;
uint256 b = ux >> 255;
ux >>= 127 + b;
result += bit * int256 (b);
}
return int128 (result);
}
}
/**
* Calculate natural logarithm of x. Revert if x <= 0.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function ln (int128 x) internal pure returns (int128) {
unchecked {
require (x > 0);
return int128 (int256 (
uint256 (int256 (log_2 (x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128));
}
}
/**
* Calculate binary exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp_2 (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
uint256 result = 0x80000000000000000000000000000000;
if (x & 0x8000000000000000 > 0)
result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128;
if (x & 0x4000000000000000 > 0)
result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128;
if (x & 0x2000000000000000 > 0)
result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128;
if (x & 0x1000000000000000 > 0)
result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128;
if (x & 0x800000000000000 > 0)
result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128;
if (x & 0x400000000000000 > 0)
result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128;
if (x & 0x200000000000000 > 0)
result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128;
if (x & 0x100000000000000 > 0)
result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128;
if (x & 0x80000000000000 > 0)
result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128;
if (x & 0x40000000000000 > 0)
result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128;
if (x & 0x20000000000000 > 0)
result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128;
if (x & 0x10000000000000 > 0)
result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128;
if (x & 0x8000000000000 > 0)
result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128;
if (x & 0x4000000000000 > 0)
result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128;
if (x & 0x2000000000000 > 0)
result = result * 0x1000162E525EE054754457D5995292026 >> 128;
if (x & 0x1000000000000 > 0)
result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128;
if (x & 0x800000000000 > 0)
result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128;
if (x & 0x400000000000 > 0)
result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128;
if (x & 0x200000000000 > 0)
result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128;
if (x & 0x100000000000 > 0)
result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128;
if (x & 0x80000000000 > 0)
result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128;
if (x & 0x40000000000 > 0)
result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128;
if (x & 0x20000000000 > 0)
result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128;
if (x & 0x10000000000 > 0)
result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128;
if (x & 0x8000000000 > 0)
result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128;
if (x & 0x4000000000 > 0)
result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128;
if (x & 0x2000000000 > 0)
result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128;
if (x & 0x1000000000 > 0)
result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128;
if (x & 0x800000000 > 0)
result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128;
if (x & 0x400000000 > 0)
result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128;
if (x & 0x200000000 > 0)
result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128;
if (x & 0x100000000 > 0)
result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128;
if (x & 0x80000000 > 0)
result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128;
if (x & 0x40000000 > 0)
result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128;
if (x & 0x20000000 > 0)
result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128;
if (x & 0x10000000 > 0)
result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128;
if (x & 0x8000000 > 0)
result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128;
if (x & 0x4000000 > 0)
result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128;
if (x & 0x2000000 > 0)
result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128;
if (x & 0x1000000 > 0)
result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128;
if (x & 0x800000 > 0)
result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128;
if (x & 0x400000 > 0)
result = result * 0x100000000002C5C85FDF477B662B26945 >> 128;
if (x & 0x200000 > 0)
result = result * 0x10000000000162E42FEFA3AE53369388C >> 128;
if (x & 0x100000 > 0)
result = result * 0x100000000000B17217F7D1D351A389D40 >> 128;
if (x & 0x80000 > 0)
result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128;
if (x & 0x40000 > 0)
result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128;
if (x & 0x20000 > 0)
result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128;
if (x & 0x10000 > 0)
result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128;
if (x & 0x8000 > 0)
result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128;
if (x & 0x4000 > 0)
result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128;
if (x & 0x2000 > 0)
result = result * 0x1000000000000162E42FEFA39F02B772C >> 128;
if (x & 0x1000 > 0)
result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128;
if (x & 0x800 > 0)
result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128;
if (x & 0x400 > 0)
result = result * 0x100000000000002C5C85FDF473DEA871F >> 128;
if (x & 0x200 > 0)
result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128;
if (x & 0x100 > 0)
result = result * 0x100000000000000B17217F7D1CF79E949 >> 128;
if (x & 0x80 > 0)
result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128;
if (x & 0x40 > 0)
result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128;
if (x & 0x20 > 0)
result = result * 0x100000000000000162E42FEFA39EF366F >> 128;
if (x & 0x10 > 0)
result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128;
if (x & 0x8 > 0)
result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128;
if (x & 0x4 > 0)
result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128;
if (x & 0x2 > 0)
result = result * 0x1000000000000000162E42FEFA39EF358 >> 128;
if (x & 0x1 > 0)
result = result * 0x10000000000000000B17217F7D1CF79AB >> 128;
result >>= uint256 (int256 (63 - (x >> 64)));
require (result <= uint256 (int256 (MAX_64x64)));
return int128 (int256 (result));
}
}
/**
* Calculate natural exponent of x. Revert on overflow.
*
* @param x signed 64.64-bit fixed point number
* @return signed 64.64-bit fixed point number
*/
function exp (int128 x) internal pure returns (int128) {
unchecked {
require (x < 0x400000000000000000); // Overflow
if (x < -0x400000000000000000) return 0; // Underflow
return exp_2 (
int128 (int256 (x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128));
}
}
/**
* Calculate x / y rounding towards zero, where x and y are unsigned 256-bit
* integer numbers. Revert on overflow or when y is zero.
*
* @param x unsigned 256-bit integer number
* @param y unsigned 256-bit integer number
* @return unsigned 64.64-bit fixed point number
*/
function divuu (uint256 x, uint256 y) private pure returns (uint128) {
unchecked {
require (y != 0);
uint256 result;
if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
result = (x << 64) / y;
else {
uint256 msb = 192;
uint256 xc = x >> 192;
if (xc >= 0x100000000) { xc >>= 32; msb += 32; }
if (xc >= 0x10000) { xc >>= 16; msb += 16; }
if (xc >= 0x100) { xc >>= 8; msb += 8; }
if (xc >= 0x10) { xc >>= 4; msb += 4; }
if (xc >= 0x4) { xc >>= 2; msb += 2; }
if (xc >= 0x2) msb += 1; // No need to shift xc anymore
result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1);
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 hi = result * (y >> 128);
uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
uint256 xh = x >> 192;
uint256 xl = x << 64;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
lo = hi << 128;
if (xl < lo) xh -= 1;
xl -= lo; // We rely on overflow behavior here
assert (xh == hi >> 128);
result += xl / y;
}
require (result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return uint128 (result);
}
}
/**
* Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer
* number.
*
* @param x unsigned 256-bit integer number
* @return unsigned 128-bit integer number
*/
function sqrtu (uint256 x) private pure returns (uint128) {
unchecked {
if (x == 0) return 0;
else {
uint256 xx = x;
uint256 r = 1;
if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; }
if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; }
if (xx >= 0x100000000) { xx >>= 32; r <<= 16; }
if (xx >= 0x10000) { xx >>= 16; r <<= 8; }
if (xx >= 0x100) { xx >>= 8; r <<= 4; }
if (xx >= 0x10) { xx >>= 4; r <<= 2; }
if (xx >= 0x4) { r <<= 1; }
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1;
r = (r + x / r) >> 1; // Seven iterations should be enough
uint256 r1 = x / r;
return uint128 (r < r1 ? r : r1);
}
}
}
}
| 31,291 |
22 | // should be zero | return (x.X == 0 && x.Y == 0);
| return (x.X == 0 && x.Y == 0);
| 32,197 |
55 | // function to get addresses of all members in congress return array of addresses / | function getAllMemberAddresses()
external
view
returns (address[] memory)
| function getAllMemberAddresses()
external
view
returns (address[] memory)
| 35,200 |
31 | // Return if price identifier is supported priceIdentifier Price feed identifierreturn isSupported True if price is supported otherwise false / | function isPriceSupported(bytes32 priceIdentifier)
external
view
override
returns (bool isSupported)
| function isPriceSupported(bytes32 priceIdentifier)
external
view
override
returns (bool isSupported)
| 8,912 |
54 | // add liquidity to uniswap pair | addLiquidity(tokenSaleInfo.contractAddress, tokenAmountToLock, saleEthToLock);
| addLiquidity(tokenSaleInfo.contractAddress, tokenAmountToLock, saleEthToLock);
| 73,763 |
733 | // Commit the block | commitBlock(S, blocks[i], publicDataHashes[i]);
| commitBlock(S, blocks[i], publicDataHashes[i]);
| 36,985 |
1 | // Reserve id for recipient. | hashes[newItemId] = recipient;
| hashes[newItemId] = recipient;
| 17,615 |
123 | // adds a pool to the list of pools of a liquidity providercan only be executed only by an ownerproviderliquidity provider address poolToken pool token address / | function addProviderPool(address provider, IDSToken poolToken) external override ownerOnly returns (bool) {
return _providerPools[provider].add(address(poolToken));
}
| function addProviderPool(address provider, IDSToken poolToken) external override ownerOnly returns (bool) {
return _providerPools[provider].add(address(poolToken));
}
| 41,263 |
2 | // require( _isApprovedOrOwner(msg.sender, tokenId), "ERC4907: transfer caller is not owner nor approved" ); | require(
msg.sender == getApproved(tokenId),
"ERC721A: transfer caller is not owner nor approved"
);
UserInfo storage info = _users[tokenId];
info.user = user;
info.expires = expires;
emit UpdateUser(tokenId, user, expires);
| require(
msg.sender == getApproved(tokenId),
"ERC721A: transfer caller is not owner nor approved"
);
UserInfo storage info = _users[tokenId];
info.user = user;
info.expires = expires;
emit UpdateUser(tokenId, user, expires);
| 19,761 |
99 | // Function to get staking count / | function getStakingCount() public view returns(uint256){
return _stakingCount;
}
| function getStakingCount() public view returns(uint256){
return _stakingCount;
}
| 34,638 |
5 | // Setting ERC20 implementation contract for the reference | ERC20Implementation = ERC20ImplementationAddress;
| ERC20Implementation = ERC20ImplementationAddress;
| 15,956 |
24 | // Initialization function for upgradable proxy contracts _nexus Nexus contract address / | function _initialize(address _nexus) internal {
require(_nexus != address(0), "Nexus address is zero");
nexus = INexus(_nexus);
InitializableModuleKeys._initialize();
}
| function _initialize(address _nexus) internal {
require(_nexus != address(0), "Nexus address is zero");
nexus = INexus(_nexus);
InitializableModuleKeys._initialize();
}
| 23,271 |
194 | // Traits | uint8 constant minTraits = 5;
uint8 constant maxTraits = 15;
mapping (uint16 => bool) private removedTraitsMap;
mapping (uint16 => uint8) private traitsUsedMap;
uint16[] private removedTraits;
| uint8 constant minTraits = 5;
uint8 constant maxTraits = 15;
mapping (uint16 => bool) private removedTraitsMap;
mapping (uint16 => uint8) private traitsUsedMap;
uint16[] private removedTraits;
| 42,068 |
148 | // in case rounding error, send all to final | token.transfer(
tokenPools[last],
totalTokens.mulBP(tokenPoolBPs[last])
);
| token.transfer(
tokenPools[last],
totalTokens.mulBP(tokenPoolBPs[last])
);
| 44,513 |
7 | // Authorize an issuer for specific ranges issuer Issuer that will be authorized ranges Ranges for which the issuer will be authorized / | function authorizeRanges(address issuer, Range[] memory ranges) external override onlyOwner {
for (uint256 i = 0; i < ranges.length; i++) {
_authorizeRange(issuer, ranges[i].min, ranges[i].max);
}
}
| function authorizeRanges(address issuer, Range[] memory ranges) external override onlyOwner {
for (uint256 i = 0; i < ranges.length; i++) {
_authorizeRange(issuer, ranges[i].min, ranges[i].max);
}
}
| 25,476 |
50 | // Minimu number of tiers should be 1 and less than or equal to 5 | require(_noOfTiers>=1 && _noOfTiers<=5);
| require(_noOfTiers>=1 && _noOfTiers<=5);
| 2,521 |
937 | // Checks if an address is already delegated _add in concernreturn bool value if the address is delegated or not / | function alreadyDelegated(address _add) public view returns(bool delegated) {
for (uint i=0; i < leaderDelegation[_add].length; i++) {
if (allDelegation[leaderDelegation[_add][i]].leader == _add) {
return true;
}
}
}
| function alreadyDelegated(address _add) public view returns(bool delegated) {
for (uint i=0; i < leaderDelegation[_add].length; i++) {
if (allDelegation[leaderDelegation[_add][i]].leader == _add) {
return true;
}
}
}
| 22,691 |
319 | // info stored for each user's position | struct Info {
bool isEmpty;
int24 tickLower;
int24 tickUpper;
}
| struct Info {
bool isEmpty;
int24 tickLower;
int24 tickUpper;
}
| 27,066 |
9 | // 0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303 |
mapping(address => address) private _bridges;
event LogBridgeSet(address indexed token, address indexed bridge);
event LogConvert(
address indexed server,
address indexed token0,
uint256 amount0,
uint256 amountBENTO,
uint256 amountSUSHI
|
mapping(address => address) private _bridges;
event LogBridgeSet(address indexed token, address indexed bridge);
event LogConvert(
address indexed server,
address indexed token0,
uint256 amount0,
uint256 amountBENTO,
uint256 amountSUSHI
| 45,305 |
7 | // The token Id of the next set of packs to be minted. uint256 public nextTokenIdToMint; |
/*///////////////////////////////////////////////////////////////
Mappings
|
/*///////////////////////////////////////////////////////////////
Mappings
| 27,968 |
57 | // WHITELIST MGMT / | {
bool _didAdd = whitelist.add(_addr);
if (_didAdd) emit AddedToWhitelist(now, _addr, msg.sender);
}
| {
bool _didAdd = whitelist.add(_addr);
if (_didAdd) emit AddedToWhitelist(now, _addr, msg.sender);
}
| 21,645 |
231 | // Lets the token owner alter the end time of an auction in case they want to end an auction early or extendthe auction. This can only be called when the auction has not yet been concluded and is not within a minLastBidDuration from concluding. / | function alterEndTime(uint256 tokenId, uint256 endTime) external {
// 0 EndTimestamp is reserved to check if a tokenId is on auction or not
require(endTime != 0, "End time cannot be 0");
require(_msgSender() == ownerOf(tokenId), "Only token owner can alter end time");
Auction memory auction = _tokenIdToAuction[tokenId];
require(auction.endTimestamp > block.timestamp + auction.minLastBidDuration, "Auction has already ended");
auction.endTimestamp = endTime;
_tokenIdToAuction[tokenId] = auction;
emit AuctionEndTimeAltered(tokenId, endTime, ownerOf(tokenId));
}
| function alterEndTime(uint256 tokenId, uint256 endTime) external {
// 0 EndTimestamp is reserved to check if a tokenId is on auction or not
require(endTime != 0, "End time cannot be 0");
require(_msgSender() == ownerOf(tokenId), "Only token owner can alter end time");
Auction memory auction = _tokenIdToAuction[tokenId];
require(auction.endTimestamp > block.timestamp + auction.minLastBidDuration, "Auction has already ended");
auction.endTimestamp = endTime;
_tokenIdToAuction[tokenId] = auction;
emit AuctionEndTimeAltered(tokenId, endTime, ownerOf(tokenId));
}
| 33,591 |
51 | // convert to titan | return _wethToTitan(wethAmount);
| return _wethToTitan(wethAmount);
| 2,545 |
20 | // Function to check if an investor is eligible for investing in a TradingContract. | function checkBeta(address _addr) external view returns (bool) {
if (ITradingContract(msg.sender).deployer() == _addr) {
return true;
}
if (testMode) {
return true;
}
if (isParticipantWhitelisted[_addr]) {
return true;
}
if (isParticipantBlacklisted[_addr]) {
return false;
}
if (isTradingContractPremium[msg.sender]) {
uint256 balance = stakingContract.getBalance(_addr);
if (balance < gold) {
return false;
}
}
return checkTradingCounter(_addr,msg.sender);
}
| function checkBeta(address _addr) external view returns (bool) {
if (ITradingContract(msg.sender).deployer() == _addr) {
return true;
}
if (testMode) {
return true;
}
if (isParticipantWhitelisted[_addr]) {
return true;
}
if (isParticipantBlacklisted[_addr]) {
return false;
}
if (isTradingContractPremium[msg.sender]) {
uint256 balance = stakingContract.getBalance(_addr);
if (balance < gold) {
return false;
}
}
return checkTradingCounter(_addr,msg.sender);
}
| 30,245 |
2 | // Associated hird parties (discord, twitch...) | ThirdParty[] linkedThirdParties;
| ThirdParty[] linkedThirdParties;
| 22,191 |
174 | // After EIP-150, max gas cost allowed to be passed to the internal call is equal to the 63/64 of total gas left. In reality, min(gasLimit, 63/64gasleft()) will be used as the call gas limit. Imagine a situation, when message requires 10000000 gas to be executed successfully. Also suppose, that at this point, gasleft() is equal to 10158000, so the callee will receive ~ 1015800063 / 64 = 9999300 gas. That amount of gas is not enough, so the call will fail. At the same time, even if the callee failed the bridge contract still has ~ 158000 gas to finish | require(_gas == 0xffffffff || (gasleft() * 63) / 64 > _gas);
bool status = _contract.call.gas(_gas)(_data);
_validateExecutionStatus(status);
setMessageSender(address(0));
setMessageId(bytes32(0));
setMessageSourceChainId(0);
return status;
| require(_gas == 0xffffffff || (gasleft() * 63) / 64 > _gas);
bool status = _contract.call.gas(_gas)(_data);
_validateExecutionStatus(status);
setMessageSender(address(0));
setMessageId(bytes32(0));
setMessageSourceChainId(0);
return status;
| 34,031 |
132 | // check if the user wants to unwrap its pair or not | if (unwrapPair) {
| if (unwrapPair) {
| 57,129 |
233 | // get the current scaled oracle price/ applies the change smoothly over a 28 day period/ scaled by 18 decimals | function getCurrentOraclePrice() external view returns (uint256);
| function getCurrentOraclePrice() external view returns (uint256);
| 13,998 |
123 | // Returns an URI for a given token IDThrows if the token ID does not exist. May return an empty string. tokenId uint256 ID of the token to query / | function tokenURI(uint256 tokenId) external view returns (string memory) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
| function tokenURI(uint256 tokenId) external view returns (string memory) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
| 22,849 |
68 | // uses the Multiplier contract for double rewarding------------------------------------------------------ _term --> the lockup term. amountETH --> ETH amount provided in liquidity amountToken --> token amount provided in liquidity wethRP--> return percentge for ETH based on term period tokenRP --> return percentge for token based on term period-------------------------------------------------------------------- / | function _withMultiplier(
uint _term, uint amountETH, uint amountToken, uint wethRP, uint tokenRP
| function _withMultiplier(
uint _term, uint amountETH, uint amountToken, uint wethRP, uint tokenRP
| 74,531 |
17 | // if address not in mapping , returns false | return lockedAccounts[_targetAddress];
| return lockedAccounts[_targetAddress];
| 16,662 |
5 | // The Authorizable constructor sets the first `authorized` of the contract to the senderaccount. / | function Authorizable() public {
authorize(msg.sender);
}
| function Authorizable() public {
authorize(msg.sender);
}
| 31,396 |
5 | // Error message for when the claim manager is used not initialized. / | error NotInitializedClaimManager();
| error NotInitializedClaimManager();
| 30,447 |
382 | // round 56 | ark(i, q, 9799099446406796696742256539758943483211846559715874347178722060519817626047);
sbox_full(i, q);
mix(i, q);
| ark(i, q, 9799099446406796696742256539758943483211846559715874347178722060519817626047);
sbox_full(i, q);
mix(i, q);
| 36,834 |
6 | // A mapping from an address to the balance of tokens held by that address. | mapping ( address => uint256 ) private balances;
| mapping ( address => uint256 ) private balances;
| 32,344 |
14 | // Transfer the token | super._transfer(from, to, tokenId);
| super._transfer(from, to, tokenId);
| 10,109 |
47 | // we check how much LP we have This call only happens once so we can assume a lot here | uint256 totalETHInLSW = (1500 ether + WETH.balanceOf(RESERVE_VAULT) + IDELTA_LSW(LSW).totalWETHEarmarkedForReferrers()) * 2;
uint256 totalInPairRatioE12 = uint256(1500 ether).mul(1e12).div(totalETHInLSW);
rlpPerLP = totalInPairRatioE12.mul(1e6); // 18 - 12
| uint256 totalETHInLSW = (1500 ether + WETH.balanceOf(RESERVE_VAULT) + IDELTA_LSW(LSW).totalWETHEarmarkedForReferrers()) * 2;
uint256 totalInPairRatioE12 = uint256(1500 ether).mul(1e12).div(totalETHInLSW);
rlpPerLP = totalInPairRatioE12.mul(1e6); // 18 - 12
| 30,509 |
278 | // Record race reults | RacerPosition[] storage racePositions = _results[raceId];
unchecked {
for (uint256 i = 0; i < positions.length; ++i) {
racePositions.push(RacerPosition({ racer: racers[indexes[i]], position: positions[i] }));
| RacerPosition[] storage racePositions = _results[raceId];
unchecked {
for (uint256 i = 0; i < positions.length; ++i) {
racePositions.push(RacerPosition({ racer: racers[indexes[i]], position: positions[i] }));
| 17,270 |
48 | // Deleting deadline process/ | uint _winningContributionId = getWinningContribution(_questId);
_transferQuestTokenTo(contributions[_winningContributionId].owner,
quests[_questId].tokenReward);
IERC20Token(cUsdTokenAddress).transferFrom(
address(this),
contributions[_winningContributionId].owner,
quests[_questId].cUsdReward);
emit NewRewardPayment(contributions[_winningContributionId].owner,
_questId,
quests[_questId].tokenReward,
| uint _winningContributionId = getWinningContribution(_questId);
_transferQuestTokenTo(contributions[_winningContributionId].owner,
quests[_questId].tokenReward);
IERC20Token(cUsdTokenAddress).transferFrom(
address(this),
contributions[_winningContributionId].owner,
quests[_questId].cUsdReward);
emit NewRewardPayment(contributions[_winningContributionId].owner,
_questId,
quests[_questId].tokenReward,
| 22,588 |
17 | // withdaw ether from contract | function withdraw() public onlyOwner {
require(address(this).balance > 0, "No ether to withdraw");
msg.sender.transfer(address(this).balance);
}
| function withdraw() public onlyOwner {
require(address(this).balance > 0, "No ether to withdraw");
msg.sender.transfer(address(this).balance);
}
| 36,396 |
29 | // not really needed but better safe then sorry if someone decides to add in a mapping to this array | ArbiterVote memory dummyArbiterVote = ArbiterVote({
state:VoteState.PENDING_VOTE,
arbitrationJobId:0,
vote:0,
arbiterId:0
});
| ArbiterVote memory dummyArbiterVote = ArbiterVote({
state:VoteState.PENDING_VOTE,
arbitrationJobId:0,
vote:0,
arbiterId:0
});
| 48,186 |
31 | // Only allow setting of the timeLockPeriod if the period is greater than the existing | require(
_timeLockPeriod > timeLockPeriod,
"TimeLockUpgradeV2: New period must be greater than existing"
);
timeLockPeriod = _timeLockPeriod;
| require(
_timeLockPeriod > timeLockPeriod,
"TimeLockUpgradeV2: New period must be greater than existing"
);
timeLockPeriod = _timeLockPeriod;
| 40,841 |
33 | // update claim data | claimsData[hash].numEntriesPerUser += priceStruct.numEntries;
claimsData[hash].amountSpentInWeis += msg.value;
emit EntrySold(_raffleId, msg.sender, raffle.entriesLength, _id); // 2377
| claimsData[hash].numEntriesPerUser += priceStruct.numEntries;
claimsData[hash].amountSpentInWeis += msg.value;
emit EntrySold(_raffleId, msg.sender, raffle.entriesLength, _id); // 2377
| 19,687 |
87 | // returns the available liquidity (including LP tokens) for a given asset asset the asset to calculate liquidity forreturn the amount of liquidity available / | function liquidityOf(address asset) public view returns (uint) {
return IERC20(asset).balanceOf(address(this)).
add(IERC20(asset).balanceOf(pair)
.mul(IERC20(pair).balanceOf(address(this)))
.div(IERC20(pair).totalSupply()));
}
| function liquidityOf(address asset) public view returns (uint) {
return IERC20(asset).balanceOf(address(this)).
add(IERC20(asset).balanceOf(pair)
.mul(IERC20(pair).balanceOf(address(this)))
.div(IERC20(pair).totalSupply()));
}
| 51,061 |
44 | // Test coverage [x] Does allowance update correctly? | function setAllowanceForPoolToken(
address spender,
uint256 _pid,
uint256 value
| function setAllowanceForPoolToken(
address spender,
uint256 _pid,
uint256 value
| 3,162 |
126 | // Transfer to non-rebasing account from rebasing account, credits are removed from the non rebasing tally | nonRebasingSupply = nonRebasingSupply.add(_value);
| nonRebasingSupply = nonRebasingSupply.add(_value);
| 11,371 |
1 | // See BaseRewardPool.sol / | constructor(
uint256 pid_,
address stakingToken_,
address rewardToken_,
address operator_,
address rewardManager_,
| constructor(
uint256 pid_,
address stakingToken_,
address rewardToken_,
address operator_,
address rewardManager_,
| 15,845 |
107 | // nothing to do here except update kn = \sum_{i=0}^{m-1}k_i - \sum_{i=m}^{n-1}k_i | kn := addmod(kn, k, gen_order)
| kn := addmod(kn, k, gen_order)
| 43,078 |
3 | // Returns the EIP712 hash of the handled asset data struct.See `getAssetTypedHash` in the subclasses for asset struct type description. / | function getAssetTypedHash(bytes memory data) internal view returns (bytes32);
| function getAssetTypedHash(bytes memory data) internal view returns (bytes32);
| 9,360 |
0 | // Reads the votes that an account has. / | interface IHasVotes {
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account) external view returns (uint96);
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint256 blockNumber)
external
view
returns (uint96);
}
| interface IHasVotes {
/**
* @notice Gets the current votes balance for `account`
* @param account The address to get votes balance
* @return The number of current votes for `account`
*/
function getCurrentVotes(address account) external view returns (uint96);
/**
* @notice Determine the prior number of votes for an account as of a block number
* @dev Block number must be a finalized block or else this function will revert to prevent misinformation.
* @param account The address of the account to check
* @param blockNumber The block number to get the vote balance at
* @return The number of votes the account had as of the given block
*/
function getPriorVotes(address account, uint256 blockNumber)
external
view
returns (uint96);
}
| 13,264 |
9 | // Vote tracking during 'Pending' phase | mapping (address => bool) outcomeVoters;
uint256 outcomeVotersCount;
uint256 public votersFromForCount;
uint256 public votersFromAgainstCount;
uint256 public votersForCount;
uint256 public votersAgainstCount;
| mapping (address => bool) outcomeVoters;
uint256 outcomeVotersCount;
uint256 public votersFromForCount;
uint256 public votersFromAgainstCount;
uint256 public votersForCount;
uint256 public votersAgainstCount;
| 14,030 |
67 | // deposit registration fee | plyr_[1].gen = (msg.value).add(plyr_[1].gen);
| plyr_[1].gen = (msg.value).add(plyr_[1].gen);
| 7,893 |
21 | // Returns the integer division of two unsigned integers. Reverts with custom message ondivision by zero. The result is rounded towards zero. Counterpart to Solidity's `/` operator. Note: this function uses a`revert` opcode (which leaves remaining gas untouched) while Solidityuses an invalid opcode to revert (consuming all remaining gas). Requirements: - The divisor cannot be zero. / | function div(
uint256 a,
uint256 b,
string memory errorMessage
| function div(
uint256 a,
uint256 b,
string memory errorMessage
| 25,545 |
35 | // FlashLender: Borrow from the bank and enforce repayment by the end of transaction execution.Rich McAteer <rich@marble.org>, Max Wolff <max@marble.org> | contract FlashLender is ReentrancyGuard, Ownable {
using SafeMath for uint256;
string public version = '0.1';
address public bank;
uint256 public fee;
/**
* @dev Verify that the borrowed tokens are returned to the bank plus a fee by the end of transaction execution.
* @param token Address of the token to for arbitrage. 0x0 for Ether.
* @param amount Amount borrowed.
*/
modifier isArbitrage(address token, uint256 amount) {
uint256 balance = IBank(bank).totalSupplyOf(token);
uint256 feeAmount = amount.mul(fee).div(10 ** 18);
_;
require(IBank(bank).totalSupplyOf(token) >= (balance.add(feeAmount)));
}
constructor(address _bank, uint256 _fee) public {
bank = _bank;
fee = _fee;
}
/**
* @dev Borrow from the bank on behalf of an arbitrage contract and execute the arbitrage contract's callback function.
* @param token Address of the token to borrow. 0x0 for Ether.
* @param amount Amount to borrow.
* @param dest Address of the account to receive arbitrage profits.
* @param data The data to execute the arbitrage trade.
*/
function borrow(
address token,
uint256 amount,
address dest,
bytes data
)
external
nonReentrant
isArbitrage(token, amount)
returns (bool)
{
// Borrow from the bank and send to the arbitrageur.
IBank(bank).borrowFor(token, msg.sender, amount);
// Call the arbitrageur's execute arbitrage method.
return IArbitrage(msg.sender).executeArbitrage(token, amount, dest, data);
}
/**
* @dev Allow the owner to set the bank address.
* @param _bank Address of the bank.
*/
function setBank(address _bank) external onlyOwner {
bank = _bank;
}
/**
* @dev Allow the owner to set the fee.
* @param _fee Fee to borrow, as a percentage of principal borrowed. 18 decimals of precision (e.g., 10^18 = 100% fee).
*/
function setFee(uint256 _fee) external onlyOwner {
fee = _fee;
}
}
| contract FlashLender is ReentrancyGuard, Ownable {
using SafeMath for uint256;
string public version = '0.1';
address public bank;
uint256 public fee;
/**
* @dev Verify that the borrowed tokens are returned to the bank plus a fee by the end of transaction execution.
* @param token Address of the token to for arbitrage. 0x0 for Ether.
* @param amount Amount borrowed.
*/
modifier isArbitrage(address token, uint256 amount) {
uint256 balance = IBank(bank).totalSupplyOf(token);
uint256 feeAmount = amount.mul(fee).div(10 ** 18);
_;
require(IBank(bank).totalSupplyOf(token) >= (balance.add(feeAmount)));
}
constructor(address _bank, uint256 _fee) public {
bank = _bank;
fee = _fee;
}
/**
* @dev Borrow from the bank on behalf of an arbitrage contract and execute the arbitrage contract's callback function.
* @param token Address of the token to borrow. 0x0 for Ether.
* @param amount Amount to borrow.
* @param dest Address of the account to receive arbitrage profits.
* @param data The data to execute the arbitrage trade.
*/
function borrow(
address token,
uint256 amount,
address dest,
bytes data
)
external
nonReentrant
isArbitrage(token, amount)
returns (bool)
{
// Borrow from the bank and send to the arbitrageur.
IBank(bank).borrowFor(token, msg.sender, amount);
// Call the arbitrageur's execute arbitrage method.
return IArbitrage(msg.sender).executeArbitrage(token, amount, dest, data);
}
/**
* @dev Allow the owner to set the bank address.
* @param _bank Address of the bank.
*/
function setBank(address _bank) external onlyOwner {
bank = _bank;
}
/**
* @dev Allow the owner to set the fee.
* @param _fee Fee to borrow, as a percentage of principal borrowed. 18 decimals of precision (e.g., 10^18 = 100% fee).
*/
function setFee(uint256 _fee) external onlyOwner {
fee = _fee;
}
}
| 68,324 |
103 | // If the price is acceptable relative to the trade type | while (_orderId != 0 && _bestAmount > 0 && _tradeData.loopLimit > 0 && isMatch(_orderId, _type, _orderPrice, _tradeData.price)) {
bytes32 _nextOrderId = _orders.getWorseOrderId(_orderId);
_lastTradePrice = _orderPrice;
_bestAmount = fillOrder.fillOrder(_tradeData.sender, _orderId, _bestAmount, _tradeData.tradeGroupId, _tradeData.fingerprint);
_orderId = _nextOrderId;
_orderPrice = _orders.getPrice(_orderId);
_tradeData.loopLimit -= 1;
}
| while (_orderId != 0 && _bestAmount > 0 && _tradeData.loopLimit > 0 && isMatch(_orderId, _type, _orderPrice, _tradeData.price)) {
bytes32 _nextOrderId = _orders.getWorseOrderId(_orderId);
_lastTradePrice = _orderPrice;
_bestAmount = fillOrder.fillOrder(_tradeData.sender, _orderId, _bestAmount, _tradeData.tradeGroupId, _tradeData.fingerprint);
_orderId = _nextOrderId;
_orderPrice = _orders.getPrice(_orderId);
_tradeData.loopLimit -= 1;
}
| 37,066 |
23 | // Transfers `tokenId` token from `from` to `to`. | * Emits a {Transfer} event.
*/
function _transferFrom(
address from,
address to,
uint256 tokenId
) internal virtual {
require(
_isApprovedOrOwner(msg.sender, tokenId),
"ERC721: transfer caller is not owner nor approved"
);
require(
ownerOf(tokenId) == from,
"ERC721: transfer of token that is not own"
);
require(to != address(0), "ERC721: transfer to the zero address");
_clearApproval(tokenId);
_tokenOwner[tokenId] = to;
_ownedTokensCount[from].decrement();
_ownedTokensCount[to].increment();
emit Transfer(from, to, tokenId);
}
| * Emits a {Transfer} event.
*/
function _transferFrom(
address from,
address to,
uint256 tokenId
) internal virtual {
require(
_isApprovedOrOwner(msg.sender, tokenId),
"ERC721: transfer caller is not owner nor approved"
);
require(
ownerOf(tokenId) == from,
"ERC721: transfer of token that is not own"
);
require(to != address(0), "ERC721: transfer to the zero address");
_clearApproval(tokenId);
_tokenOwner[tokenId] = to;
_ownedTokensCount[from].decrement();
_ownedTokensCount[to].increment();
emit Transfer(from, to, tokenId);
}
| 21,473 |
111 | // Returns the URI for token type `id`. | * If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
| * If the `\{id\}` substring is present in the URI, it must be replaced by
* clients with the actual token type ID.
*/
function uri(uint256 id) external view returns (string memory);
}
| 1,738 |
695 | // validatorId => bool - is Delegated or not |
mapping (uint => uint) delegated;
|
mapping (uint => uint) delegated;
| 1,099 |
49 | // A custom modifier which permits only approved minters to mint items. | modifier onlyMinters {
require(msg.sender == owner() || approvedMinters[msg.sender],
"You are not an approved minter for this item.");
_;
}
| modifier onlyMinters {
require(msg.sender == owner() || approvedMinters[msg.sender],
"You are not an approved minter for this item.");
_;
}
| 41,350 |
4 | // Works like address.send but with a customizable gas limit Make sure your code is safe for reentrancy when using this function! | function sendETH(
address to,
uint amount,
uint gasLimit
)
internal
returns (bool success)
| function sendETH(
address to,
uint amount,
uint gasLimit
)
internal
returns (bool success)
| 14,409 |
147 | // Collections on the platform are associated with a call to this | * function which will generate a {NiftyBuilderInstance} to house the
* NFTs for that particular artist release.
*
* @param name Of the collection being deployed.
* @param symbol Shorthand token identifier, for wallets, etc.
* @param typeCount The number of different Nifty types (different
* individual NFTs) associated with the deployed collection.
* @param baseURI The location where the artifact assets are stored.
* @param creator The artist associated with the collection.
*/
function createNewBuilderInstance(
string memory name,
string memory symbol,
uint256 typeCount,
string memory baseURI,
string memory creator) external onlyValidSender {
_id += 1;
NiftyBuilderInstance instance = new NiftyBuilderInstance(
name,
symbol,
_id,
typeCount,
baseURI,
creator,
niftyRegistryContract,
_defaultOwner
);
address instanceAddress = address(instance);
validBuilderInstance[instanceAddress] = true;
emit BuilderInstanceCreated(instanceAddress, _id);
}
| * function which will generate a {NiftyBuilderInstance} to house the
* NFTs for that particular artist release.
*
* @param name Of the collection being deployed.
* @param symbol Shorthand token identifier, for wallets, etc.
* @param typeCount The number of different Nifty types (different
* individual NFTs) associated with the deployed collection.
* @param baseURI The location where the artifact assets are stored.
* @param creator The artist associated with the collection.
*/
function createNewBuilderInstance(
string memory name,
string memory symbol,
uint256 typeCount,
string memory baseURI,
string memory creator) external onlyValidSender {
_id += 1;
NiftyBuilderInstance instance = new NiftyBuilderInstance(
name,
symbol,
_id,
typeCount,
baseURI,
creator,
niftyRegistryContract,
_defaultOwner
);
address instanceAddress = address(instance);
validBuilderInstance[instanceAddress] = true;
emit BuilderInstanceCreated(instanceAddress, _id);
}
| 26,054 |
63 | // Total to go to platform = base fee / platform fee % | uint totalPlatformFee = (contractFunds.mul(PLATFORM_FEE)).div(100);
| uint totalPlatformFee = (contractFunds.mul(PLATFORM_FEE)).div(100);
| 8,417 |
1,383 | // Create a new token and return it to the caller. The caller will become the only minter and burner and the new owner capable of assigning the roles. tokenName used to describe the new token. tokenSymbol short ticker abbreviation of the name. Ideally < 5 chars. tokenDecimals used to define the precision used in the token's numerical representation.return newToken an instance of the newly created token interface. / | function createToken(
string calldata tokenName,
string calldata tokenSymbol,
uint8 tokenDecimals
| function createToken(
string calldata tokenName,
string calldata tokenSymbol,
uint8 tokenDecimals
| 21,870 |
80 | // transfers from a sender to receipent with subtracting spenders allowance with each successfull transfer / | function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
| function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
| 13,577 |
8 | // override this since we're no longer tracking eth deposits / | receive() external virtual override payable {
revert();
}
| receive() external virtual override payable {
revert();
}
| 3,704 |
7 | // adds airline address to the list of addresses | registeredAirlines.push(firstAirline);
| registeredAirlines.push(firstAirline);
| 219 |
432 | // computeProportionalAmountsOut(per token)aO = tokenAmountOut /bptIn \ b = tokenBalancea0 = b| ---------------------|bptIn = bptAmountIn \ bptTotalSupply/bpt = bptTotalSupply/ Since we're computing an amount out, we round down overall. This means rounding down on both the multiplication and division. |
uint256 bptRatio = bptAmountIn.divDown(bptTotalSupply);
amountsOut = new uint256[](balances.length);
for (uint256 i = 0; i < balances.length; i++) {
amountsOut[i] = balances[i].mulDown(bptRatio);
}
|
uint256 bptRatio = bptAmountIn.divDown(bptTotalSupply);
amountsOut = new uint256[](balances.length);
for (uint256 i = 0; i < balances.length; i++) {
amountsOut[i] = balances[i].mulDown(bptRatio);
}
| 29,331 |
3 | // error IllegalAddressError, caller destination account address is invalid / | error IllegalAddressError(address account);
| error IllegalAddressError(address account);
| 23,617 |
236 | // Constants / | function WEI_PER_ETH() internal pure returns (uint256) {
return _WEI_PER_ETH;
}
| function WEI_PER_ETH() internal pure returns (uint256) {
return _WEI_PER_ETH;
}
| 20,199 |
167 | // Function to get token URI of given token IDURI will be blank untill totalSupply reaches MAX_NFT/ | function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
if (tokenId < 1000) {
return bytes(baseURI[0]).length > 0 && totalSupply >= 1000 ? string(abi.encodePacked(baseURI[0],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 1000 && tokenId < 2000) {
return bytes(baseURI[1]).length > 0 && totalSupply >= 2000 ? string(abi.encodePacked(baseURI[1],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 2000 && tokenId < 3000) {
return bytes(baseURI[2]).length > 0 && totalSupply >= 3000 ? string(abi.encodePacked(baseURI[2],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 3000 && tokenId < 4000) {
return bytes(baseURI[3]).length > 0 && totalSupply >= 4000 ? string(abi.encodePacked(baseURI[3],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 4000 && tokenId < 5000) {
return bytes(baseURI[4]).length > 0 && totalSupply >= 5000 ? string(abi.encodePacked(baseURI[4],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 5000 && tokenId < 6000) {
return bytes(baseURI[5]).length > 0 && totalSupply >= 6000 ? string(abi.encodePacked(baseURI[5],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 6000 && tokenId < 7000) {
return bytes(baseURI[6]).length > 0 && totalSupply >= 7000 ? string(abi.encodePacked(baseURI[6],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 7000 && tokenId < 8000) {
return bytes(baseURI[7]).length > 0 && totalSupply >= 8000 ? string(abi.encodePacked(baseURI[7],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 8000 && tokenId < 9000) {
return bytes(baseURI[8]).length > 0 && totalSupply >= 9000 ? string(abi.encodePacked(baseURI[8],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else {
return bytes(baseURI[9]).length > 0 && totalSupply >= MAX_NFT ? string(abi.encodePacked(baseURI[9],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
}
}
| function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "ERC721Metadata: URI query for nonexistent token");
if (tokenId < 1000) {
return bytes(baseURI[0]).length > 0 && totalSupply >= 1000 ? string(abi.encodePacked(baseURI[0],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 1000 && tokenId < 2000) {
return bytes(baseURI[1]).length > 0 && totalSupply >= 2000 ? string(abi.encodePacked(baseURI[1],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 2000 && tokenId < 3000) {
return bytes(baseURI[2]).length > 0 && totalSupply >= 3000 ? string(abi.encodePacked(baseURI[2],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 3000 && tokenId < 4000) {
return bytes(baseURI[3]).length > 0 && totalSupply >= 4000 ? string(abi.encodePacked(baseURI[3],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 4000 && tokenId < 5000) {
return bytes(baseURI[4]).length > 0 && totalSupply >= 5000 ? string(abi.encodePacked(baseURI[4],
tokenId.toString())) : string(abi.encodePacked(blindURI1_, tokenId.toString()));
} else if (tokenId >= 5000 && tokenId < 6000) {
return bytes(baseURI[5]).length > 0 && totalSupply >= 6000 ? string(abi.encodePacked(baseURI[5],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 6000 && tokenId < 7000) {
return bytes(baseURI[6]).length > 0 && totalSupply >= 7000 ? string(abi.encodePacked(baseURI[6],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 7000 && tokenId < 8000) {
return bytes(baseURI[7]).length > 0 && totalSupply >= 8000 ? string(abi.encodePacked(baseURI[7],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else if (tokenId >= 8000 && tokenId < 9000) {
return bytes(baseURI[8]).length > 0 && totalSupply >= 9000 ? string(abi.encodePacked(baseURI[8],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
} else {
return bytes(baseURI[9]).length > 0 && totalSupply >= MAX_NFT ? string(abi.encodePacked(baseURI[9],
tokenId.toString())) : string(abi.encodePacked(blindURI2_, tokenId.toString()));
}
}
| 32,842 |
446 | // Redeem interest and/or principal from an ITranchedPool investment tokenId the ID of an IPoolTokens token to be redeemed / | function redeem(uint256 tokenId) public override whenNotPaused nonReentrant {
IPoolTokens poolTokens = config.getPoolTokens();
IPoolTokens.TokenInfo memory tokenInfo = poolTokens.getTokenInfo(tokenId);
ITranchedPool pool = ITranchedPool(tokenInfo.pool);
(uint256 interestRedeemed, uint256 principalRedeemed) = pool.withdrawMax(tokenId);
_collectInterestAndPrincipal(address(pool), interestRedeemed, principalRedeemed);
}
| function redeem(uint256 tokenId) public override whenNotPaused nonReentrant {
IPoolTokens poolTokens = config.getPoolTokens();
IPoolTokens.TokenInfo memory tokenInfo = poolTokens.getTokenInfo(tokenId);
ITranchedPool pool = ITranchedPool(tokenInfo.pool);
(uint256 interestRedeemed, uint256 principalRedeemed) = pool.withdrawMax(tokenId);
_collectInterestAndPrincipal(address(pool), interestRedeemed, principalRedeemed);
}
| 61,918 |
15 | // Solidity only automatically asserts when dividing by 0 | require(b > 0, errorMessage);
uint256 c = a / b;
| require(b > 0, errorMessage);
uint256 c = a / b;
| 2,216 |
10 | // Bid count by token address => token id => bid counts | mapping(address => mapping(uint256 => uint256)) public bidCounterByToken;
| mapping(address => mapping(uint256 => uint256)) public bidCounterByToken;
| 30,396 |
82 | // Modifier that validates a purchase at a tierAll the following has to be met:- current time within the offering period- valid sender address and ether value greater than 0.1- total Wei raised not greater than FUNDING_ETH_HARD_CAP- contribution per perticipant within contribution limit/ | modifier validPurchase() {
require(now >= startTime && now <= endTime && stage == Stages.OfferingStarted);
if(now > capReleaseTimestamp) {
maxContribution = 5000 * 1 ether;
}
uint256 contributionInWei = msg.value;
address participant = msg.sender;
require(contributionInWei <= maxContribution.sub(contributions[participant]));
require(participant != address(0) && contributionInWei >= minContribution && contributionInWei <= maxContribution);
require(weiRaised.add(contributionInWei) <= FUNDING_ETH_HARD_CAP);
_;
}
| modifier validPurchase() {
require(now >= startTime && now <= endTime && stage == Stages.OfferingStarted);
if(now > capReleaseTimestamp) {
maxContribution = 5000 * 1 ether;
}
uint256 contributionInWei = msg.value;
address participant = msg.sender;
require(contributionInWei <= maxContribution.sub(contributions[participant]));
require(participant != address(0) && contributionInWei >= minContribution && contributionInWei <= maxContribution);
require(weiRaised.add(contributionInWei) <= FUNDING_ETH_HARD_CAP);
_;
}
| 18,976 |
12 | // 储存奖励信息 | mapping (address => bool) public claimed;
event ActionCommitted(uint indexed punkId, uint indexed time, ActionChoices action);
event GoldPicked(uint indexed punkId, uint indexed time, int x, int y, uint amount);
event GoldPut(uint indexed punkId, int x, int y, uint amount, bool isPut);
| mapping (address => bool) public claimed;
event ActionCommitted(uint indexed punkId, uint indexed time, ActionChoices action);
event GoldPicked(uint indexed punkId, uint indexed time, int x, int y, uint amount);
event GoldPut(uint indexed punkId, int x, int y, uint amount, bool isPut);
| 24,748 |
26 | // Sets the treasury fee Throws if setting fee over 20% _treasuryFee The value for the treasury fee / | function setTreasuryFee(uint256 _treasuryFee) public {
require(msg.sender == governance, "!governance");
require(_treasuryFee <= 2000, "_treasuryFee over 20%");
treasuryFee = _treasuryFee;
}
| function setTreasuryFee(uint256 _treasuryFee) public {
require(msg.sender == governance, "!governance");
require(_treasuryFee <= 2000, "_treasuryFee over 20%");
treasuryFee = _treasuryFee;
}
| 39,931 |
55 | // A variant of {claim} that combines multiple claims for the same Champion & version into a single call./This is more efficient than {claimMultiple} since it only checks Champion ownership & verifies Merkle proof once. | function claimMultipleTokensForChampion(
address recipient,
Version version,
ERC20[] calldata tokenList,
Champion champion,
uint256 shares,
bytes32[] calldata merkleProof
) external returns (uint256[] memory claimedTokenAmountList) {
| function claimMultipleTokensForChampion(
address recipient,
Version version,
ERC20[] calldata tokenList,
Champion champion,
uint256 shares,
bytes32[] calldata merkleProof
) external returns (uint256[] memory claimedTokenAmountList) {
| 22,830 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.