contract_name
stringlengths 1
61
| file_path
stringlengths 5
50.4k
| contract_address
stringlengths 42
42
| language
stringclasses 1
value | class_name
stringlengths 1
61
| class_code
stringlengths 4
330k
| class_documentation
stringlengths 0
29.1k
| class_documentation_type
stringclasses 6
values | func_name
stringlengths 0
62
| func_code
stringlengths 1
303k
| func_documentation
stringlengths 2
14.9k
| func_documentation_type
stringclasses 4
values | compiler_version
stringlengths 15
42
| license_type
stringclasses 14
values | swarm_source
stringlengths 0
71
| meta
dict | __index_level_0__
int64 0
60.4k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GermanBakery | /contracts/Brotchain.sol | 0x5721be2b7b1403daaea264daa26c29c51398bc2f | Solidity | Brotchain | contract Brotchain is BaseOpenSea, ERC721Enumerable, ERC721Pausable, Ownable, PullPayment {
/**
* @dev A BMP pixel encoder, supporting arbitrary colour palettes.
*/
BMP public immutable _bmp;
/**
* @dev A Mandelbrot-and-friends fractal generator.
*/
Mandelbrot public immutable _brots;
/**
* @dev Maximum number of editions per series.
*/
uint256 public constant MAX_PER_SERIES = 64;
/**
* @dev Mint price = pi/10.
*/
uint256 public constant MINT_PRICE = (314159 ether) / 1000000;
constructor(string memory name, string memory symbol, address brots, address openSeaProxyRegistry) ERC721(name, symbol) {
_bmp = new BMP();
_brots = Mandelbrot(brots);
if (openSeaProxyRegistry != address(0)) {
_setOpenSeaRegistry(openSeaProxyRegistry);
}
}
/**
* @dev Base config for pricing + all tokens in a series.
*/
struct Series {
uint256[] patches;
uint256 numMinted;
uint32 width;
uint32 height;
bytes defaultPalette;
bool locked;
string name;
string description;
}
/**
* @dev All existing series configs.
*/
Series[] public seriesConfigs;
/**
* @dev Require that the series exists.
*/
modifier seriesMustExist(uint256 seriesId) {
require(seriesId < seriesConfigs.length, "Series doesn't exist");
_;
}
/**
* @dev Creates a new series of brots, based on the precomputed patches.
*
* The seriesId MUST be equal to seriesConfigs.length. This is a safety
* measure for automated deployment of multiple series in case an earlier
* transaction fails as series would otherwise be created out of order. This
* effectively makes newSeries() idempotent.
*/
function newSeries(uint256 seriesId, string memory name, string memory description, uint256[] memory patches, uint32 width, uint32 height) external onlyOwner {
require(seriesId == seriesConfigs.length, "Invalid new series ID");
seriesConfigs.push(Series({
name: name,
description: description,
patches: patches,
width: width,
height: height,
numMinted: 0,
locked: false,
defaultPalette: new bytes(0)
}));
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Require that the series isn't locked to updates.
*/
modifier seriesNotLocked(uint256 seriesId) {
require(!seriesConfigs[seriesId].locked, "Series locked");
_;
}
/**
* @dev Permanently lock the series to changes in pixels.
*/
function lockSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
Series memory series = seriesConfigs[seriesId];
uint256 length;
for (uint i = 0; i < series.patches.length; i++) {
length += _brots.cachedPatch(series.patches[i]).pixels.length;
}
require(series.width * series.height == length, "Invalid dimensions");
seriesConfigs[seriesId].locked = true;
}
/**
* @dev Emitted when a series' patches or dimensions change.
*/
event SeriesPixelsChanged(uint256 indexed seriesId);
/**
* @dev Update the patches that govern series pixels.
*/
function setSeriesPatches(uint256 seriesId, uint256[] memory patches) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].patches = patches;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the dimensions of the series.
*/
function setSeriesDimensions(uint256 seriesId, uint32 width, uint32 height) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].width = width;
seriesConfigs[seriesId].height = height;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the default palette for a series when the token doesn't have one.
*/
function setSeriesDefaultPalette(uint256 seriesId, bytes memory palette) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
require(palette.length == 768, "256 colours required");
seriesConfigs[seriesId].defaultPalette = palette;
}
/**
* @dev Update the series name.
*/
function setSeriesName(uint256 seriesId, string memory name) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].name = name;
}
/**
* @dev Update the series description.
*/
function setSeriesDescription(uint256 seriesId, string memory description) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].description = description;
}
/**
* @dev Token configuration such as series (pixels).
*/
struct TokenConfig {
uint256 paletteChanges;
address paletteBy;
address paletteApproval;
// paletteReset is actually a boolean, but sized to align with a 256-bit
// boundary for better storage. See resetPalette();
uint192 paletteReset;
bytes palette;
}
/**
* @dev All existing token configs.
*/
mapping(uint256 => TokenConfig) public tokenConfigs;
/**
* @dev Whether to limit minting only to those in _earlyAccess mapping.
*/
bool public onlyEarlyAccess = true;
/**
* @dev Addresses with early minting access.
*/
mapping(address => uint256) private _earlyAccess;
/**
* @dev Emitted when setOnlyEarlyAccess(to) is called.
*/
event OnlyEarlyAccess();
/**
* @dev Set the onlyEarlyAccess flag.
*/
function setOnlyEarlyAccess(bool to) external onlyOwner {
onlyEarlyAccess = to;
emit OnlyEarlyAccess();
}
/**
* @dev Call parameter for early access because mapping()s are disallowed.
*/
struct EarlyAccess {
address addr;
uint256 totalAllowed;
}
/**
* @dev Set early-access granting or revocation for the addresses.
*
* The supply is not the amount left, but the total in the early-access
* phase.
*/
function setEarlyAccessGrants(EarlyAccess[] calldata addresses) external onlyOwner {
for (uint i = 0; i < addresses.length; i++) {
_earlyAccess[addresses[i].addr] = addresses[i].totalAllowed;
}
}
/**
* @dev Returns the total early-access allocation for the address.
*/
function earlyAccessFor(address addr) public view returns (uint256) {
return _earlyAccess[addr];
}
/**
* @dev Max number that the contract owner can mint in a specific series.
*/
uint256 public constant OWNER_ALLOCATION = 2;
/**
* @dev Allow minting of the genesis pieces.
*/
function safeMintInSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
require(seriesConfigs[seriesId].numMinted < OWNER_ALLOCATION, "Don't be greedy");
_safeMintInSeries(seriesId);
}
/**
* @dev Mint one edition, from a randomly selected series.
*
* # NB see the bug described in _safeMintInSeries().
*/
function safeMint() external payable {
require(msg.value >= MINT_PRICE, "Insufficient payment");
_asyncTransfer(owner(), msg.value);
uint256 numSeries = seriesConfigs.length;
// We need some sort of randomness to choose which series is issued
// next. sha3 is, by nature of being a cryptographic hash, a good PRNG.
// Although this can technically be manipulated by someone in control of
// block.timestamp, they're in a race against other blocks and also the
// last minted (which is also random). If you can control this and care
// enough to do so, then you deserve to choose which series you get!
uint256 rand = uint256(keccak256(abi.encodePacked(
_msgSender(),
block.timestamp,
lastTokenMinted
))) % numSeries; // uniform if numSeries is a power of 2 (it is)
// Try each, starting from a random index, until a series with
// capacity is found.
for (uint256 i = 0; i < numSeries; i++) {
uint256 seriesId = (rand + i) % numSeries;
if (seriesConfigs[seriesId].numMinted < MAX_PER_SERIES) {
_safeMintInSeries(seriesId);
return;
}
}
revert("All series sold out");
}
/**
* @dev Last tokenId minted.
*
* This doesn't increment because the series could be different to the one
* before. It's useful for randomly choosing the next token and for testing
* too. Even at a gas price of 100, updating this only costs 0.0005 ETH.
*/
uint256 public lastTokenMinted;
/**
* @dev Value by which seriesId is multiplied for the prefix of a tokenId.
*
* Series 0 will have tokens 0, 1, 2…; series 1 will have tokens 1000, 1001,
* etc.
*/
uint256 private constant _tokenIdSeriesMultiplier = 1e4;
/**
* @dev Returns the seriesId of a token. The token may not exist.
*/
function tokenSeries(uint256 tokenId) public pure returns (uint256) {
return tokenId / _tokenIdSeriesMultiplier;
}
/**
* @dev Returns a token's edition within its series. The token may not exist.
*/
function tokenEditionNum(uint256 tokenId) public pure returns (uint256) {
return tokenId % _tokenIdSeriesMultiplier;
}
/**
* @dev Mints the next token in the series.
*/
function _safeMintInSeries(uint256 seriesId) internal seriesMustExist(seriesId) {
/**
* ################################
* There is a bug in this code that we only discovered after deployment.
* A minter can move their piece to a different wallet, reducing their
* balance, and then mint again. See GermanBakery.sol for the fix.
* ################################
*/
if (_msgSender() != owner()) {
if (onlyEarlyAccess) {
require(balanceOf(_msgSender()) < _earlyAccess[_msgSender()], "Early access exhausted for wallet");
} else {
require(balanceOf(_msgSender()) < seriesConfigs.length, "Wallet cap reached");
}
}
Series memory series = seriesConfigs[seriesId];
uint256 tokenId = seriesId * _tokenIdSeriesMultiplier + series.numMinted;
lastTokenMinted = tokenId;
tokenConfigs[tokenId] = TokenConfig({
paletteChanges: 0,
paletteBy: address(0),
paletteApproval: address(0),
paletteReset: 0,
palette: new bytes(0)
});
seriesConfigs[seriesId].numMinted++;
_safeMint(_msgSender(), tokenId);
emit TokenBMPChanged(tokenId);
}
/**
* @dev Emitted when the address is approved to change a token's palette.
*/
event PaletteApproval(uint256 indexed tokenId, address approved);
/**
* @dev Approve the address to change the token's palette.
*
* Set to 0x00 address to revoke. Token owner and ERC721 approved already
* have palette approval. This is to allow someone else to modify a palette
* without the risk of them transferring the token.
*
* Revoked upon token transfer.
*/
function approveForPalette(uint256 tokenId, address approved) external {
require(_isApprovedOrOwner(_msgSender(), tokenId), "Only owner or approver");
address owner = ownerOf(tokenId);
require(approved != owner, "Approving token owner");
tokenConfigs[tokenId].paletteApproval = approved;
emit PaletteApproval(tokenId, approved);
}
/**
* @dev Emitted to signal changing of a token's BMP.
*/
event TokenBMPChanged(uint256 indexed tokenId);
/**
* @dev Require that the message sender is approved for palette changes.
*/
modifier approvedForPalette(uint256 tokenId) {
require(
_isApprovedOrOwner(_msgSender(), tokenId) ||
tokenConfigs[tokenId].paletteApproval == _msgSender(),
"Not approved for palette"
);
_;
}
/**
* @dev Clear a token's palette, using the series default instead.
*
* Does not reset the paletteChanges count, but increments it.
*
* Emits TokenBMPChanged(tokenId);
*/
function resetPalette(uint256 tokenId) approvedForPalette(tokenId) external {
require(tokenConfigs[tokenId].paletteReset == 0, "Already reset");
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = address(0);
// Initial palette setting costs about 0.01 ETH at 30 gas but changes
// are a little over 25% of that. Using a boolean for reset adds
// negligible cost to the reset, in exchange for greater savings on the
// next setPalette() call.
tokenConfigs[tokenId].paletteReset = 1;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Set a token's palette if an owner or has approval.
*
* Emits TokenBMPChanged(tokenId).
*/
function setPalette(uint256 tokenId, bytes memory palette) approvedForPalette(tokenId) external {
require(palette.length == 768, "256 colours required");
tokenConfigs[tokenId].palette = palette;
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = _msgSender();
tokenConfigs[tokenId].paletteReset = 0;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Concatenates a series' patches into a single array.
*/
function seriesPixels(uint256 seriesId) public view seriesMustExist(seriesId) returns (bytes memory) {
return _brots.concatenatePatches(seriesConfigs[seriesId].patches);
}
/**
* @dev Token equivalent of seriesPixels().
*/
function pixelsOf(uint256 tokenId) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
return seriesPixels(tokenSeries(tokenId));
}
/**
* @dev Returns the effective token palette, considering resets.
*
* Boolean flag indicates whether it's the original palette; i.e. nothing is
* set or the palette has been explicitly reset().
*/
function _tokenPalette(uint256 tokenId) private view returns (bytes memory, bool) {
TokenConfig memory token = tokenConfigs[tokenId];
bytes memory palette = token.palette;
bool original = token.paletteReset == 1 || palette.length == 0;
if (original) {
palette = seriesConfigs[tokenSeries(tokenId)].defaultPalette;
if (palette.length == 0) {
palette = _bmp.grayscale();
}
}
return (palette, original);
}
/**
* @dev Returns the BMP-encoded token image, scaling pixels in both dimensions.
*
* Scale of 0 is treated as 1.
*/
function bmpOf(uint256 tokenId, uint32 scale) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
(bytes memory palette, ) = _tokenPalette(tokenId);
bytes memory pixels = pixelsOf(tokenId);
if (scale > 1) {
return _bmp.bmp(
_bmp.scalePixels(pixels, series.width, series.height, scale),
series.width * scale,
series.height * scale,
palette
);
}
return _bmp.bmp(pixels, series.width, series.height, palette);
}
/**
* @dev Equivalent to bmpOf() but encoded as a data URI to view in a browser.
*/
function bmpDataURIOf(uint256 tokenId, uint32 scale) public view returns (string memory) {
return _bmp.bmpDataURI(bmpOf(tokenId, scale));
}
/**
* @dev Renders the token as an ASCII brot.
*
* This is an homage to Robert W Brooks and Peter Matelski who were the
* first to render the Mandelbrot, in this form.
*/
function brooksMatelskiOf(uint256 tokenId, string memory characters) external view returns (string memory) {
bytes memory charset = abi.encodePacked(characters);
require(charset.length == 256, "256 characters");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
// Include newlines except for the end.
bytes memory ascii = new bytes((series.width+1)*series.height - 1);
bytes memory pixels = pixelsOf(tokenId);
uint col;
uint a; // ascii index
for (uint p = 0; p < pixels.length; p++) {
ascii[a] = charset[uint8(pixels[p])];
a++;
col++;
if (col == series.width && a < ascii.length) {
ascii[a] = 0x0a; // Not compatible with Windows and typewriters.
a++;
col = 0;
}
}
return string(ascii);
}
/**
* @dev Base URL for external_url metadata field.
*/
string private _baseExternalUrl = "https://brotchain.art/brot/";
/**
* @dev Set the base URL for external_url metadata field.
*/
function setBaseExternalUrl(string memory url) public onlyOwner {
_baseExternalUrl = url;
}
/**
* @dev Returns data URI of token metadata.
*
* The BMP-encoded image is included in its own base64-encoded data URI.
*/
function tokenURI(uint256 tokenId) public override view returns (string memory) {
TokenConfig memory token = tokenConfigs[tokenId];
Series memory series = seriesConfigs[tokenSeries(tokenId)];
uint256 editionNum = tokenEditionNum(tokenId);
bytes memory data = abi.encodePacked(
'data:application/json,{',
'"name":"', series.name, ' #', Strings.toString(editionNum) ,'",',
'"description":"', series.description, '",'
'"external_url":"', _baseExternalUrl, Strings.toString(tokenId),'",'
);
// Combining this packing with the one above would result in the stack
// being too deep and a failure to compile.
data = abi.encodePacked(
data,
'"attributes":['
'{"value":"', series.name, '"},'
'{',
'"trait_type":"Palette Changes",',
'"value":', Strings.toString(token.paletteChanges),
'}'
);
if (token.paletteBy != address(0)) {
data = abi.encodePacked(
data,
',{',
'"trait_type":"Palette By",',
'"value":"', Strings.toHexString(uint256(uint160(token.paletteBy)), 20),'"',
'}'
);
}
(, bool original) = _tokenPalette(tokenId);
if (original) {
data = abi.encodePacked(
data,
',{"value":"Original Palette"}'
);
}
if (editionNum == 0) {
data = abi.encodePacked(
data,
',{"value":"Genesis"}'
);
}
return string(abi.encodePacked(
data,
'],',
'"image":"', bmpDataURIOf(tokenId, 1), '"',
'}'
));
}
/**
* @dev Pause the contract.
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Unpause the contract.
*/
function unpause() external onlyOwner {
_unpause();
}
function isApprovedForAll(address owner, address operator) public view override returns (bool) {
return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
}
/**
* @dev OpenSea collection config.
*
* https://docs.opensea.io/docs/contract-level-metadata
*/
function setContractURI(string memory contractURI) external onlyOwner {
_setContractURI(contractURI);
}
/**
* @dev Revoke palette approval upon token transfer.
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable, ERC721Pausable) {
tokenConfigs[tokenId].paletteApproval = address(0);
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override (ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
} | pause | function pause() external onlyOwner {
_pause();
}
| /**
* @dev Pause the contract.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
19686,
19751
]
} | 3,807 |
||||
GermanBakery | /contracts/Brotchain.sol | 0x5721be2b7b1403daaea264daa26c29c51398bc2f | Solidity | Brotchain | contract Brotchain is BaseOpenSea, ERC721Enumerable, ERC721Pausable, Ownable, PullPayment {
/**
* @dev A BMP pixel encoder, supporting arbitrary colour palettes.
*/
BMP public immutable _bmp;
/**
* @dev A Mandelbrot-and-friends fractal generator.
*/
Mandelbrot public immutable _brots;
/**
* @dev Maximum number of editions per series.
*/
uint256 public constant MAX_PER_SERIES = 64;
/**
* @dev Mint price = pi/10.
*/
uint256 public constant MINT_PRICE = (314159 ether) / 1000000;
constructor(string memory name, string memory symbol, address brots, address openSeaProxyRegistry) ERC721(name, symbol) {
_bmp = new BMP();
_brots = Mandelbrot(brots);
if (openSeaProxyRegistry != address(0)) {
_setOpenSeaRegistry(openSeaProxyRegistry);
}
}
/**
* @dev Base config for pricing + all tokens in a series.
*/
struct Series {
uint256[] patches;
uint256 numMinted;
uint32 width;
uint32 height;
bytes defaultPalette;
bool locked;
string name;
string description;
}
/**
* @dev All existing series configs.
*/
Series[] public seriesConfigs;
/**
* @dev Require that the series exists.
*/
modifier seriesMustExist(uint256 seriesId) {
require(seriesId < seriesConfigs.length, "Series doesn't exist");
_;
}
/**
* @dev Creates a new series of brots, based on the precomputed patches.
*
* The seriesId MUST be equal to seriesConfigs.length. This is a safety
* measure for automated deployment of multiple series in case an earlier
* transaction fails as series would otherwise be created out of order. This
* effectively makes newSeries() idempotent.
*/
function newSeries(uint256 seriesId, string memory name, string memory description, uint256[] memory patches, uint32 width, uint32 height) external onlyOwner {
require(seriesId == seriesConfigs.length, "Invalid new series ID");
seriesConfigs.push(Series({
name: name,
description: description,
patches: patches,
width: width,
height: height,
numMinted: 0,
locked: false,
defaultPalette: new bytes(0)
}));
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Require that the series isn't locked to updates.
*/
modifier seriesNotLocked(uint256 seriesId) {
require(!seriesConfigs[seriesId].locked, "Series locked");
_;
}
/**
* @dev Permanently lock the series to changes in pixels.
*/
function lockSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
Series memory series = seriesConfigs[seriesId];
uint256 length;
for (uint i = 0; i < series.patches.length; i++) {
length += _brots.cachedPatch(series.patches[i]).pixels.length;
}
require(series.width * series.height == length, "Invalid dimensions");
seriesConfigs[seriesId].locked = true;
}
/**
* @dev Emitted when a series' patches or dimensions change.
*/
event SeriesPixelsChanged(uint256 indexed seriesId);
/**
* @dev Update the patches that govern series pixels.
*/
function setSeriesPatches(uint256 seriesId, uint256[] memory patches) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].patches = patches;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the dimensions of the series.
*/
function setSeriesDimensions(uint256 seriesId, uint32 width, uint32 height) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].width = width;
seriesConfigs[seriesId].height = height;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the default palette for a series when the token doesn't have one.
*/
function setSeriesDefaultPalette(uint256 seriesId, bytes memory palette) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
require(palette.length == 768, "256 colours required");
seriesConfigs[seriesId].defaultPalette = palette;
}
/**
* @dev Update the series name.
*/
function setSeriesName(uint256 seriesId, string memory name) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].name = name;
}
/**
* @dev Update the series description.
*/
function setSeriesDescription(uint256 seriesId, string memory description) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].description = description;
}
/**
* @dev Token configuration such as series (pixels).
*/
struct TokenConfig {
uint256 paletteChanges;
address paletteBy;
address paletteApproval;
// paletteReset is actually a boolean, but sized to align with a 256-bit
// boundary for better storage. See resetPalette();
uint192 paletteReset;
bytes palette;
}
/**
* @dev All existing token configs.
*/
mapping(uint256 => TokenConfig) public tokenConfigs;
/**
* @dev Whether to limit minting only to those in _earlyAccess mapping.
*/
bool public onlyEarlyAccess = true;
/**
* @dev Addresses with early minting access.
*/
mapping(address => uint256) private _earlyAccess;
/**
* @dev Emitted when setOnlyEarlyAccess(to) is called.
*/
event OnlyEarlyAccess();
/**
* @dev Set the onlyEarlyAccess flag.
*/
function setOnlyEarlyAccess(bool to) external onlyOwner {
onlyEarlyAccess = to;
emit OnlyEarlyAccess();
}
/**
* @dev Call parameter for early access because mapping()s are disallowed.
*/
struct EarlyAccess {
address addr;
uint256 totalAllowed;
}
/**
* @dev Set early-access granting or revocation for the addresses.
*
* The supply is not the amount left, but the total in the early-access
* phase.
*/
function setEarlyAccessGrants(EarlyAccess[] calldata addresses) external onlyOwner {
for (uint i = 0; i < addresses.length; i++) {
_earlyAccess[addresses[i].addr] = addresses[i].totalAllowed;
}
}
/**
* @dev Returns the total early-access allocation for the address.
*/
function earlyAccessFor(address addr) public view returns (uint256) {
return _earlyAccess[addr];
}
/**
* @dev Max number that the contract owner can mint in a specific series.
*/
uint256 public constant OWNER_ALLOCATION = 2;
/**
* @dev Allow minting of the genesis pieces.
*/
function safeMintInSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
require(seriesConfigs[seriesId].numMinted < OWNER_ALLOCATION, "Don't be greedy");
_safeMintInSeries(seriesId);
}
/**
* @dev Mint one edition, from a randomly selected series.
*
* # NB see the bug described in _safeMintInSeries().
*/
function safeMint() external payable {
require(msg.value >= MINT_PRICE, "Insufficient payment");
_asyncTransfer(owner(), msg.value);
uint256 numSeries = seriesConfigs.length;
// We need some sort of randomness to choose which series is issued
// next. sha3 is, by nature of being a cryptographic hash, a good PRNG.
// Although this can technically be manipulated by someone in control of
// block.timestamp, they're in a race against other blocks and also the
// last minted (which is also random). If you can control this and care
// enough to do so, then you deserve to choose which series you get!
uint256 rand = uint256(keccak256(abi.encodePacked(
_msgSender(),
block.timestamp,
lastTokenMinted
))) % numSeries; // uniform if numSeries is a power of 2 (it is)
// Try each, starting from a random index, until a series with
// capacity is found.
for (uint256 i = 0; i < numSeries; i++) {
uint256 seriesId = (rand + i) % numSeries;
if (seriesConfigs[seriesId].numMinted < MAX_PER_SERIES) {
_safeMintInSeries(seriesId);
return;
}
}
revert("All series sold out");
}
/**
* @dev Last tokenId minted.
*
* This doesn't increment because the series could be different to the one
* before. It's useful for randomly choosing the next token and for testing
* too. Even at a gas price of 100, updating this only costs 0.0005 ETH.
*/
uint256 public lastTokenMinted;
/**
* @dev Value by which seriesId is multiplied for the prefix of a tokenId.
*
* Series 0 will have tokens 0, 1, 2…; series 1 will have tokens 1000, 1001,
* etc.
*/
uint256 private constant _tokenIdSeriesMultiplier = 1e4;
/**
* @dev Returns the seriesId of a token. The token may not exist.
*/
function tokenSeries(uint256 tokenId) public pure returns (uint256) {
return tokenId / _tokenIdSeriesMultiplier;
}
/**
* @dev Returns a token's edition within its series. The token may not exist.
*/
function tokenEditionNum(uint256 tokenId) public pure returns (uint256) {
return tokenId % _tokenIdSeriesMultiplier;
}
/**
* @dev Mints the next token in the series.
*/
function _safeMintInSeries(uint256 seriesId) internal seriesMustExist(seriesId) {
/**
* ################################
* There is a bug in this code that we only discovered after deployment.
* A minter can move their piece to a different wallet, reducing their
* balance, and then mint again. See GermanBakery.sol for the fix.
* ################################
*/
if (_msgSender() != owner()) {
if (onlyEarlyAccess) {
require(balanceOf(_msgSender()) < _earlyAccess[_msgSender()], "Early access exhausted for wallet");
} else {
require(balanceOf(_msgSender()) < seriesConfigs.length, "Wallet cap reached");
}
}
Series memory series = seriesConfigs[seriesId];
uint256 tokenId = seriesId * _tokenIdSeriesMultiplier + series.numMinted;
lastTokenMinted = tokenId;
tokenConfigs[tokenId] = TokenConfig({
paletteChanges: 0,
paletteBy: address(0),
paletteApproval: address(0),
paletteReset: 0,
palette: new bytes(0)
});
seriesConfigs[seriesId].numMinted++;
_safeMint(_msgSender(), tokenId);
emit TokenBMPChanged(tokenId);
}
/**
* @dev Emitted when the address is approved to change a token's palette.
*/
event PaletteApproval(uint256 indexed tokenId, address approved);
/**
* @dev Approve the address to change the token's palette.
*
* Set to 0x00 address to revoke. Token owner and ERC721 approved already
* have palette approval. This is to allow someone else to modify a palette
* without the risk of them transferring the token.
*
* Revoked upon token transfer.
*/
function approveForPalette(uint256 tokenId, address approved) external {
require(_isApprovedOrOwner(_msgSender(), tokenId), "Only owner or approver");
address owner = ownerOf(tokenId);
require(approved != owner, "Approving token owner");
tokenConfigs[tokenId].paletteApproval = approved;
emit PaletteApproval(tokenId, approved);
}
/**
* @dev Emitted to signal changing of a token's BMP.
*/
event TokenBMPChanged(uint256 indexed tokenId);
/**
* @dev Require that the message sender is approved for palette changes.
*/
modifier approvedForPalette(uint256 tokenId) {
require(
_isApprovedOrOwner(_msgSender(), tokenId) ||
tokenConfigs[tokenId].paletteApproval == _msgSender(),
"Not approved for palette"
);
_;
}
/**
* @dev Clear a token's palette, using the series default instead.
*
* Does not reset the paletteChanges count, but increments it.
*
* Emits TokenBMPChanged(tokenId);
*/
function resetPalette(uint256 tokenId) approvedForPalette(tokenId) external {
require(tokenConfigs[tokenId].paletteReset == 0, "Already reset");
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = address(0);
// Initial palette setting costs about 0.01 ETH at 30 gas but changes
// are a little over 25% of that. Using a boolean for reset adds
// negligible cost to the reset, in exchange for greater savings on the
// next setPalette() call.
tokenConfigs[tokenId].paletteReset = 1;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Set a token's palette if an owner or has approval.
*
* Emits TokenBMPChanged(tokenId).
*/
function setPalette(uint256 tokenId, bytes memory palette) approvedForPalette(tokenId) external {
require(palette.length == 768, "256 colours required");
tokenConfigs[tokenId].palette = palette;
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = _msgSender();
tokenConfigs[tokenId].paletteReset = 0;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Concatenates a series' patches into a single array.
*/
function seriesPixels(uint256 seriesId) public view seriesMustExist(seriesId) returns (bytes memory) {
return _brots.concatenatePatches(seriesConfigs[seriesId].patches);
}
/**
* @dev Token equivalent of seriesPixels().
*/
function pixelsOf(uint256 tokenId) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
return seriesPixels(tokenSeries(tokenId));
}
/**
* @dev Returns the effective token palette, considering resets.
*
* Boolean flag indicates whether it's the original palette; i.e. nothing is
* set or the palette has been explicitly reset().
*/
function _tokenPalette(uint256 tokenId) private view returns (bytes memory, bool) {
TokenConfig memory token = tokenConfigs[tokenId];
bytes memory palette = token.palette;
bool original = token.paletteReset == 1 || palette.length == 0;
if (original) {
palette = seriesConfigs[tokenSeries(tokenId)].defaultPalette;
if (palette.length == 0) {
palette = _bmp.grayscale();
}
}
return (palette, original);
}
/**
* @dev Returns the BMP-encoded token image, scaling pixels in both dimensions.
*
* Scale of 0 is treated as 1.
*/
function bmpOf(uint256 tokenId, uint32 scale) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
(bytes memory palette, ) = _tokenPalette(tokenId);
bytes memory pixels = pixelsOf(tokenId);
if (scale > 1) {
return _bmp.bmp(
_bmp.scalePixels(pixels, series.width, series.height, scale),
series.width * scale,
series.height * scale,
palette
);
}
return _bmp.bmp(pixels, series.width, series.height, palette);
}
/**
* @dev Equivalent to bmpOf() but encoded as a data URI to view in a browser.
*/
function bmpDataURIOf(uint256 tokenId, uint32 scale) public view returns (string memory) {
return _bmp.bmpDataURI(bmpOf(tokenId, scale));
}
/**
* @dev Renders the token as an ASCII brot.
*
* This is an homage to Robert W Brooks and Peter Matelski who were the
* first to render the Mandelbrot, in this form.
*/
function brooksMatelskiOf(uint256 tokenId, string memory characters) external view returns (string memory) {
bytes memory charset = abi.encodePacked(characters);
require(charset.length == 256, "256 characters");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
// Include newlines except for the end.
bytes memory ascii = new bytes((series.width+1)*series.height - 1);
bytes memory pixels = pixelsOf(tokenId);
uint col;
uint a; // ascii index
for (uint p = 0; p < pixels.length; p++) {
ascii[a] = charset[uint8(pixels[p])];
a++;
col++;
if (col == series.width && a < ascii.length) {
ascii[a] = 0x0a; // Not compatible with Windows and typewriters.
a++;
col = 0;
}
}
return string(ascii);
}
/**
* @dev Base URL for external_url metadata field.
*/
string private _baseExternalUrl = "https://brotchain.art/brot/";
/**
* @dev Set the base URL for external_url metadata field.
*/
function setBaseExternalUrl(string memory url) public onlyOwner {
_baseExternalUrl = url;
}
/**
* @dev Returns data URI of token metadata.
*
* The BMP-encoded image is included in its own base64-encoded data URI.
*/
function tokenURI(uint256 tokenId) public override view returns (string memory) {
TokenConfig memory token = tokenConfigs[tokenId];
Series memory series = seriesConfigs[tokenSeries(tokenId)];
uint256 editionNum = tokenEditionNum(tokenId);
bytes memory data = abi.encodePacked(
'data:application/json,{',
'"name":"', series.name, ' #', Strings.toString(editionNum) ,'",',
'"description":"', series.description, '",'
'"external_url":"', _baseExternalUrl, Strings.toString(tokenId),'",'
);
// Combining this packing with the one above would result in the stack
// being too deep and a failure to compile.
data = abi.encodePacked(
data,
'"attributes":['
'{"value":"', series.name, '"},'
'{',
'"trait_type":"Palette Changes",',
'"value":', Strings.toString(token.paletteChanges),
'}'
);
if (token.paletteBy != address(0)) {
data = abi.encodePacked(
data,
',{',
'"trait_type":"Palette By",',
'"value":"', Strings.toHexString(uint256(uint160(token.paletteBy)), 20),'"',
'}'
);
}
(, bool original) = _tokenPalette(tokenId);
if (original) {
data = abi.encodePacked(
data,
',{"value":"Original Palette"}'
);
}
if (editionNum == 0) {
data = abi.encodePacked(
data,
',{"value":"Genesis"}'
);
}
return string(abi.encodePacked(
data,
'],',
'"image":"', bmpDataURIOf(tokenId, 1), '"',
'}'
));
}
/**
* @dev Pause the contract.
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Unpause the contract.
*/
function unpause() external onlyOwner {
_unpause();
}
function isApprovedForAll(address owner, address operator) public view override returns (bool) {
return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
}
/**
* @dev OpenSea collection config.
*
* https://docs.opensea.io/docs/contract-level-metadata
*/
function setContractURI(string memory contractURI) external onlyOwner {
_setContractURI(contractURI);
}
/**
* @dev Revoke palette approval upon token transfer.
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable, ERC721Pausable) {
tokenConfigs[tokenId].paletteApproval = address(0);
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override (ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
} | unpause | function unpause() external onlyOwner {
_unpause();
}
| /**
* @dev Unpause the contract.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
19803,
19872
]
} | 3,808 |
||||
GermanBakery | /contracts/Brotchain.sol | 0x5721be2b7b1403daaea264daa26c29c51398bc2f | Solidity | Brotchain | contract Brotchain is BaseOpenSea, ERC721Enumerable, ERC721Pausable, Ownable, PullPayment {
/**
* @dev A BMP pixel encoder, supporting arbitrary colour palettes.
*/
BMP public immutable _bmp;
/**
* @dev A Mandelbrot-and-friends fractal generator.
*/
Mandelbrot public immutable _brots;
/**
* @dev Maximum number of editions per series.
*/
uint256 public constant MAX_PER_SERIES = 64;
/**
* @dev Mint price = pi/10.
*/
uint256 public constant MINT_PRICE = (314159 ether) / 1000000;
constructor(string memory name, string memory symbol, address brots, address openSeaProxyRegistry) ERC721(name, symbol) {
_bmp = new BMP();
_brots = Mandelbrot(brots);
if (openSeaProxyRegistry != address(0)) {
_setOpenSeaRegistry(openSeaProxyRegistry);
}
}
/**
* @dev Base config for pricing + all tokens in a series.
*/
struct Series {
uint256[] patches;
uint256 numMinted;
uint32 width;
uint32 height;
bytes defaultPalette;
bool locked;
string name;
string description;
}
/**
* @dev All existing series configs.
*/
Series[] public seriesConfigs;
/**
* @dev Require that the series exists.
*/
modifier seriesMustExist(uint256 seriesId) {
require(seriesId < seriesConfigs.length, "Series doesn't exist");
_;
}
/**
* @dev Creates a new series of brots, based on the precomputed patches.
*
* The seriesId MUST be equal to seriesConfigs.length. This is a safety
* measure for automated deployment of multiple series in case an earlier
* transaction fails as series would otherwise be created out of order. This
* effectively makes newSeries() idempotent.
*/
function newSeries(uint256 seriesId, string memory name, string memory description, uint256[] memory patches, uint32 width, uint32 height) external onlyOwner {
require(seriesId == seriesConfigs.length, "Invalid new series ID");
seriesConfigs.push(Series({
name: name,
description: description,
patches: patches,
width: width,
height: height,
numMinted: 0,
locked: false,
defaultPalette: new bytes(0)
}));
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Require that the series isn't locked to updates.
*/
modifier seriesNotLocked(uint256 seriesId) {
require(!seriesConfigs[seriesId].locked, "Series locked");
_;
}
/**
* @dev Permanently lock the series to changes in pixels.
*/
function lockSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
Series memory series = seriesConfigs[seriesId];
uint256 length;
for (uint i = 0; i < series.patches.length; i++) {
length += _brots.cachedPatch(series.patches[i]).pixels.length;
}
require(series.width * series.height == length, "Invalid dimensions");
seriesConfigs[seriesId].locked = true;
}
/**
* @dev Emitted when a series' patches or dimensions change.
*/
event SeriesPixelsChanged(uint256 indexed seriesId);
/**
* @dev Update the patches that govern series pixels.
*/
function setSeriesPatches(uint256 seriesId, uint256[] memory patches) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].patches = patches;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the dimensions of the series.
*/
function setSeriesDimensions(uint256 seriesId, uint32 width, uint32 height) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].width = width;
seriesConfigs[seriesId].height = height;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the default palette for a series when the token doesn't have one.
*/
function setSeriesDefaultPalette(uint256 seriesId, bytes memory palette) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
require(palette.length == 768, "256 colours required");
seriesConfigs[seriesId].defaultPalette = palette;
}
/**
* @dev Update the series name.
*/
function setSeriesName(uint256 seriesId, string memory name) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].name = name;
}
/**
* @dev Update the series description.
*/
function setSeriesDescription(uint256 seriesId, string memory description) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].description = description;
}
/**
* @dev Token configuration such as series (pixels).
*/
struct TokenConfig {
uint256 paletteChanges;
address paletteBy;
address paletteApproval;
// paletteReset is actually a boolean, but sized to align with a 256-bit
// boundary for better storage. See resetPalette();
uint192 paletteReset;
bytes palette;
}
/**
* @dev All existing token configs.
*/
mapping(uint256 => TokenConfig) public tokenConfigs;
/**
* @dev Whether to limit minting only to those in _earlyAccess mapping.
*/
bool public onlyEarlyAccess = true;
/**
* @dev Addresses with early minting access.
*/
mapping(address => uint256) private _earlyAccess;
/**
* @dev Emitted when setOnlyEarlyAccess(to) is called.
*/
event OnlyEarlyAccess();
/**
* @dev Set the onlyEarlyAccess flag.
*/
function setOnlyEarlyAccess(bool to) external onlyOwner {
onlyEarlyAccess = to;
emit OnlyEarlyAccess();
}
/**
* @dev Call parameter for early access because mapping()s are disallowed.
*/
struct EarlyAccess {
address addr;
uint256 totalAllowed;
}
/**
* @dev Set early-access granting or revocation for the addresses.
*
* The supply is not the amount left, but the total in the early-access
* phase.
*/
function setEarlyAccessGrants(EarlyAccess[] calldata addresses) external onlyOwner {
for (uint i = 0; i < addresses.length; i++) {
_earlyAccess[addresses[i].addr] = addresses[i].totalAllowed;
}
}
/**
* @dev Returns the total early-access allocation for the address.
*/
function earlyAccessFor(address addr) public view returns (uint256) {
return _earlyAccess[addr];
}
/**
* @dev Max number that the contract owner can mint in a specific series.
*/
uint256 public constant OWNER_ALLOCATION = 2;
/**
* @dev Allow minting of the genesis pieces.
*/
function safeMintInSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
require(seriesConfigs[seriesId].numMinted < OWNER_ALLOCATION, "Don't be greedy");
_safeMintInSeries(seriesId);
}
/**
* @dev Mint one edition, from a randomly selected series.
*
* # NB see the bug described in _safeMintInSeries().
*/
function safeMint() external payable {
require(msg.value >= MINT_PRICE, "Insufficient payment");
_asyncTransfer(owner(), msg.value);
uint256 numSeries = seriesConfigs.length;
// We need some sort of randomness to choose which series is issued
// next. sha3 is, by nature of being a cryptographic hash, a good PRNG.
// Although this can technically be manipulated by someone in control of
// block.timestamp, they're in a race against other blocks and also the
// last minted (which is also random). If you can control this and care
// enough to do so, then you deserve to choose which series you get!
uint256 rand = uint256(keccak256(abi.encodePacked(
_msgSender(),
block.timestamp,
lastTokenMinted
))) % numSeries; // uniform if numSeries is a power of 2 (it is)
// Try each, starting from a random index, until a series with
// capacity is found.
for (uint256 i = 0; i < numSeries; i++) {
uint256 seriesId = (rand + i) % numSeries;
if (seriesConfigs[seriesId].numMinted < MAX_PER_SERIES) {
_safeMintInSeries(seriesId);
return;
}
}
revert("All series sold out");
}
/**
* @dev Last tokenId minted.
*
* This doesn't increment because the series could be different to the one
* before. It's useful for randomly choosing the next token and for testing
* too. Even at a gas price of 100, updating this only costs 0.0005 ETH.
*/
uint256 public lastTokenMinted;
/**
* @dev Value by which seriesId is multiplied for the prefix of a tokenId.
*
* Series 0 will have tokens 0, 1, 2…; series 1 will have tokens 1000, 1001,
* etc.
*/
uint256 private constant _tokenIdSeriesMultiplier = 1e4;
/**
* @dev Returns the seriesId of a token. The token may not exist.
*/
function tokenSeries(uint256 tokenId) public pure returns (uint256) {
return tokenId / _tokenIdSeriesMultiplier;
}
/**
* @dev Returns a token's edition within its series. The token may not exist.
*/
function tokenEditionNum(uint256 tokenId) public pure returns (uint256) {
return tokenId % _tokenIdSeriesMultiplier;
}
/**
* @dev Mints the next token in the series.
*/
function _safeMintInSeries(uint256 seriesId) internal seriesMustExist(seriesId) {
/**
* ################################
* There is a bug in this code that we only discovered after deployment.
* A minter can move their piece to a different wallet, reducing their
* balance, and then mint again. See GermanBakery.sol for the fix.
* ################################
*/
if (_msgSender() != owner()) {
if (onlyEarlyAccess) {
require(balanceOf(_msgSender()) < _earlyAccess[_msgSender()], "Early access exhausted for wallet");
} else {
require(balanceOf(_msgSender()) < seriesConfigs.length, "Wallet cap reached");
}
}
Series memory series = seriesConfigs[seriesId];
uint256 tokenId = seriesId * _tokenIdSeriesMultiplier + series.numMinted;
lastTokenMinted = tokenId;
tokenConfigs[tokenId] = TokenConfig({
paletteChanges: 0,
paletteBy: address(0),
paletteApproval: address(0),
paletteReset: 0,
palette: new bytes(0)
});
seriesConfigs[seriesId].numMinted++;
_safeMint(_msgSender(), tokenId);
emit TokenBMPChanged(tokenId);
}
/**
* @dev Emitted when the address is approved to change a token's palette.
*/
event PaletteApproval(uint256 indexed tokenId, address approved);
/**
* @dev Approve the address to change the token's palette.
*
* Set to 0x00 address to revoke. Token owner and ERC721 approved already
* have palette approval. This is to allow someone else to modify a palette
* without the risk of them transferring the token.
*
* Revoked upon token transfer.
*/
function approveForPalette(uint256 tokenId, address approved) external {
require(_isApprovedOrOwner(_msgSender(), tokenId), "Only owner or approver");
address owner = ownerOf(tokenId);
require(approved != owner, "Approving token owner");
tokenConfigs[tokenId].paletteApproval = approved;
emit PaletteApproval(tokenId, approved);
}
/**
* @dev Emitted to signal changing of a token's BMP.
*/
event TokenBMPChanged(uint256 indexed tokenId);
/**
* @dev Require that the message sender is approved for palette changes.
*/
modifier approvedForPalette(uint256 tokenId) {
require(
_isApprovedOrOwner(_msgSender(), tokenId) ||
tokenConfigs[tokenId].paletteApproval == _msgSender(),
"Not approved for palette"
);
_;
}
/**
* @dev Clear a token's palette, using the series default instead.
*
* Does not reset the paletteChanges count, but increments it.
*
* Emits TokenBMPChanged(tokenId);
*/
function resetPalette(uint256 tokenId) approvedForPalette(tokenId) external {
require(tokenConfigs[tokenId].paletteReset == 0, "Already reset");
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = address(0);
// Initial palette setting costs about 0.01 ETH at 30 gas but changes
// are a little over 25% of that. Using a boolean for reset adds
// negligible cost to the reset, in exchange for greater savings on the
// next setPalette() call.
tokenConfigs[tokenId].paletteReset = 1;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Set a token's palette if an owner or has approval.
*
* Emits TokenBMPChanged(tokenId).
*/
function setPalette(uint256 tokenId, bytes memory palette) approvedForPalette(tokenId) external {
require(palette.length == 768, "256 colours required");
tokenConfigs[tokenId].palette = palette;
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = _msgSender();
tokenConfigs[tokenId].paletteReset = 0;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Concatenates a series' patches into a single array.
*/
function seriesPixels(uint256 seriesId) public view seriesMustExist(seriesId) returns (bytes memory) {
return _brots.concatenatePatches(seriesConfigs[seriesId].patches);
}
/**
* @dev Token equivalent of seriesPixels().
*/
function pixelsOf(uint256 tokenId) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
return seriesPixels(tokenSeries(tokenId));
}
/**
* @dev Returns the effective token palette, considering resets.
*
* Boolean flag indicates whether it's the original palette; i.e. nothing is
* set or the palette has been explicitly reset().
*/
function _tokenPalette(uint256 tokenId) private view returns (bytes memory, bool) {
TokenConfig memory token = tokenConfigs[tokenId];
bytes memory palette = token.palette;
bool original = token.paletteReset == 1 || palette.length == 0;
if (original) {
palette = seriesConfigs[tokenSeries(tokenId)].defaultPalette;
if (palette.length == 0) {
palette = _bmp.grayscale();
}
}
return (palette, original);
}
/**
* @dev Returns the BMP-encoded token image, scaling pixels in both dimensions.
*
* Scale of 0 is treated as 1.
*/
function bmpOf(uint256 tokenId, uint32 scale) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
(bytes memory palette, ) = _tokenPalette(tokenId);
bytes memory pixels = pixelsOf(tokenId);
if (scale > 1) {
return _bmp.bmp(
_bmp.scalePixels(pixels, series.width, series.height, scale),
series.width * scale,
series.height * scale,
palette
);
}
return _bmp.bmp(pixels, series.width, series.height, palette);
}
/**
* @dev Equivalent to bmpOf() but encoded as a data URI to view in a browser.
*/
function bmpDataURIOf(uint256 tokenId, uint32 scale) public view returns (string memory) {
return _bmp.bmpDataURI(bmpOf(tokenId, scale));
}
/**
* @dev Renders the token as an ASCII brot.
*
* This is an homage to Robert W Brooks and Peter Matelski who were the
* first to render the Mandelbrot, in this form.
*/
function brooksMatelskiOf(uint256 tokenId, string memory characters) external view returns (string memory) {
bytes memory charset = abi.encodePacked(characters);
require(charset.length == 256, "256 characters");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
// Include newlines except for the end.
bytes memory ascii = new bytes((series.width+1)*series.height - 1);
bytes memory pixels = pixelsOf(tokenId);
uint col;
uint a; // ascii index
for (uint p = 0; p < pixels.length; p++) {
ascii[a] = charset[uint8(pixels[p])];
a++;
col++;
if (col == series.width && a < ascii.length) {
ascii[a] = 0x0a; // Not compatible with Windows and typewriters.
a++;
col = 0;
}
}
return string(ascii);
}
/**
* @dev Base URL for external_url metadata field.
*/
string private _baseExternalUrl = "https://brotchain.art/brot/";
/**
* @dev Set the base URL for external_url metadata field.
*/
function setBaseExternalUrl(string memory url) public onlyOwner {
_baseExternalUrl = url;
}
/**
* @dev Returns data URI of token metadata.
*
* The BMP-encoded image is included in its own base64-encoded data URI.
*/
function tokenURI(uint256 tokenId) public override view returns (string memory) {
TokenConfig memory token = tokenConfigs[tokenId];
Series memory series = seriesConfigs[tokenSeries(tokenId)];
uint256 editionNum = tokenEditionNum(tokenId);
bytes memory data = abi.encodePacked(
'data:application/json,{',
'"name":"', series.name, ' #', Strings.toString(editionNum) ,'",',
'"description":"', series.description, '",'
'"external_url":"', _baseExternalUrl, Strings.toString(tokenId),'",'
);
// Combining this packing with the one above would result in the stack
// being too deep and a failure to compile.
data = abi.encodePacked(
data,
'"attributes":['
'{"value":"', series.name, '"},'
'{',
'"trait_type":"Palette Changes",',
'"value":', Strings.toString(token.paletteChanges),
'}'
);
if (token.paletteBy != address(0)) {
data = abi.encodePacked(
data,
',{',
'"trait_type":"Palette By",',
'"value":"', Strings.toHexString(uint256(uint160(token.paletteBy)), 20),'"',
'}'
);
}
(, bool original) = _tokenPalette(tokenId);
if (original) {
data = abi.encodePacked(
data,
',{"value":"Original Palette"}'
);
}
if (editionNum == 0) {
data = abi.encodePacked(
data,
',{"value":"Genesis"}'
);
}
return string(abi.encodePacked(
data,
'],',
'"image":"', bmpDataURIOf(tokenId, 1), '"',
'}'
));
}
/**
* @dev Pause the contract.
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Unpause the contract.
*/
function unpause() external onlyOwner {
_unpause();
}
function isApprovedForAll(address owner, address operator) public view override returns (bool) {
return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
}
/**
* @dev OpenSea collection config.
*
* https://docs.opensea.io/docs/contract-level-metadata
*/
function setContractURI(string memory contractURI) external onlyOwner {
_setContractURI(contractURI);
}
/**
* @dev Revoke palette approval upon token transfer.
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable, ERC721Pausable) {
tokenConfigs[tokenId].paletteApproval = address(0);
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override (ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
} | setContractURI | function setContractURI(string memory contractURI) external onlyOwner {
_setContractURI(contractURI);
}
| /**
* @dev OpenSea collection config.
*
* https://docs.opensea.io/docs/contract-level-metadata
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
20201,
20320
]
} | 3,809 |
||||
GermanBakery | /contracts/Brotchain.sol | 0x5721be2b7b1403daaea264daa26c29c51398bc2f | Solidity | Brotchain | contract Brotchain is BaseOpenSea, ERC721Enumerable, ERC721Pausable, Ownable, PullPayment {
/**
* @dev A BMP pixel encoder, supporting arbitrary colour palettes.
*/
BMP public immutable _bmp;
/**
* @dev A Mandelbrot-and-friends fractal generator.
*/
Mandelbrot public immutable _brots;
/**
* @dev Maximum number of editions per series.
*/
uint256 public constant MAX_PER_SERIES = 64;
/**
* @dev Mint price = pi/10.
*/
uint256 public constant MINT_PRICE = (314159 ether) / 1000000;
constructor(string memory name, string memory symbol, address brots, address openSeaProxyRegistry) ERC721(name, symbol) {
_bmp = new BMP();
_brots = Mandelbrot(brots);
if (openSeaProxyRegistry != address(0)) {
_setOpenSeaRegistry(openSeaProxyRegistry);
}
}
/**
* @dev Base config for pricing + all tokens in a series.
*/
struct Series {
uint256[] patches;
uint256 numMinted;
uint32 width;
uint32 height;
bytes defaultPalette;
bool locked;
string name;
string description;
}
/**
* @dev All existing series configs.
*/
Series[] public seriesConfigs;
/**
* @dev Require that the series exists.
*/
modifier seriesMustExist(uint256 seriesId) {
require(seriesId < seriesConfigs.length, "Series doesn't exist");
_;
}
/**
* @dev Creates a new series of brots, based on the precomputed patches.
*
* The seriesId MUST be equal to seriesConfigs.length. This is a safety
* measure for automated deployment of multiple series in case an earlier
* transaction fails as series would otherwise be created out of order. This
* effectively makes newSeries() idempotent.
*/
function newSeries(uint256 seriesId, string memory name, string memory description, uint256[] memory patches, uint32 width, uint32 height) external onlyOwner {
require(seriesId == seriesConfigs.length, "Invalid new series ID");
seriesConfigs.push(Series({
name: name,
description: description,
patches: patches,
width: width,
height: height,
numMinted: 0,
locked: false,
defaultPalette: new bytes(0)
}));
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Require that the series isn't locked to updates.
*/
modifier seriesNotLocked(uint256 seriesId) {
require(!seriesConfigs[seriesId].locked, "Series locked");
_;
}
/**
* @dev Permanently lock the series to changes in pixels.
*/
function lockSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
Series memory series = seriesConfigs[seriesId];
uint256 length;
for (uint i = 0; i < series.patches.length; i++) {
length += _brots.cachedPatch(series.patches[i]).pixels.length;
}
require(series.width * series.height == length, "Invalid dimensions");
seriesConfigs[seriesId].locked = true;
}
/**
* @dev Emitted when a series' patches or dimensions change.
*/
event SeriesPixelsChanged(uint256 indexed seriesId);
/**
* @dev Update the patches that govern series pixels.
*/
function setSeriesPatches(uint256 seriesId, uint256[] memory patches) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].patches = patches;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the dimensions of the series.
*/
function setSeriesDimensions(uint256 seriesId, uint32 width, uint32 height) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
seriesConfigs[seriesId].width = width;
seriesConfigs[seriesId].height = height;
emit SeriesPixelsChanged(seriesId);
}
/**
* @dev Update the default palette for a series when the token doesn't have one.
*/
function setSeriesDefaultPalette(uint256 seriesId, bytes memory palette) external seriesMustExist(seriesId) seriesNotLocked(seriesId) onlyOwner {
require(palette.length == 768, "256 colours required");
seriesConfigs[seriesId].defaultPalette = palette;
}
/**
* @dev Update the series name.
*/
function setSeriesName(uint256 seriesId, string memory name) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].name = name;
}
/**
* @dev Update the series description.
*/
function setSeriesDescription(uint256 seriesId, string memory description) external seriesMustExist(seriesId) onlyOwner {
seriesConfigs[seriesId].description = description;
}
/**
* @dev Token configuration such as series (pixels).
*/
struct TokenConfig {
uint256 paletteChanges;
address paletteBy;
address paletteApproval;
// paletteReset is actually a boolean, but sized to align with a 256-bit
// boundary for better storage. See resetPalette();
uint192 paletteReset;
bytes palette;
}
/**
* @dev All existing token configs.
*/
mapping(uint256 => TokenConfig) public tokenConfigs;
/**
* @dev Whether to limit minting only to those in _earlyAccess mapping.
*/
bool public onlyEarlyAccess = true;
/**
* @dev Addresses with early minting access.
*/
mapping(address => uint256) private _earlyAccess;
/**
* @dev Emitted when setOnlyEarlyAccess(to) is called.
*/
event OnlyEarlyAccess();
/**
* @dev Set the onlyEarlyAccess flag.
*/
function setOnlyEarlyAccess(bool to) external onlyOwner {
onlyEarlyAccess = to;
emit OnlyEarlyAccess();
}
/**
* @dev Call parameter for early access because mapping()s are disallowed.
*/
struct EarlyAccess {
address addr;
uint256 totalAllowed;
}
/**
* @dev Set early-access granting or revocation for the addresses.
*
* The supply is not the amount left, but the total in the early-access
* phase.
*/
function setEarlyAccessGrants(EarlyAccess[] calldata addresses) external onlyOwner {
for (uint i = 0; i < addresses.length; i++) {
_earlyAccess[addresses[i].addr] = addresses[i].totalAllowed;
}
}
/**
* @dev Returns the total early-access allocation for the address.
*/
function earlyAccessFor(address addr) public view returns (uint256) {
return _earlyAccess[addr];
}
/**
* @dev Max number that the contract owner can mint in a specific series.
*/
uint256 public constant OWNER_ALLOCATION = 2;
/**
* @dev Allow minting of the genesis pieces.
*/
function safeMintInSeries(uint256 seriesId) external seriesMustExist(seriesId) onlyOwner {
require(seriesConfigs[seriesId].numMinted < OWNER_ALLOCATION, "Don't be greedy");
_safeMintInSeries(seriesId);
}
/**
* @dev Mint one edition, from a randomly selected series.
*
* # NB see the bug described in _safeMintInSeries().
*/
function safeMint() external payable {
require(msg.value >= MINT_PRICE, "Insufficient payment");
_asyncTransfer(owner(), msg.value);
uint256 numSeries = seriesConfigs.length;
// We need some sort of randomness to choose which series is issued
// next. sha3 is, by nature of being a cryptographic hash, a good PRNG.
// Although this can technically be manipulated by someone in control of
// block.timestamp, they're in a race against other blocks and also the
// last minted (which is also random). If you can control this and care
// enough to do so, then you deserve to choose which series you get!
uint256 rand = uint256(keccak256(abi.encodePacked(
_msgSender(),
block.timestamp,
lastTokenMinted
))) % numSeries; // uniform if numSeries is a power of 2 (it is)
// Try each, starting from a random index, until a series with
// capacity is found.
for (uint256 i = 0; i < numSeries; i++) {
uint256 seriesId = (rand + i) % numSeries;
if (seriesConfigs[seriesId].numMinted < MAX_PER_SERIES) {
_safeMintInSeries(seriesId);
return;
}
}
revert("All series sold out");
}
/**
* @dev Last tokenId minted.
*
* This doesn't increment because the series could be different to the one
* before. It's useful for randomly choosing the next token and for testing
* too. Even at a gas price of 100, updating this only costs 0.0005 ETH.
*/
uint256 public lastTokenMinted;
/**
* @dev Value by which seriesId is multiplied for the prefix of a tokenId.
*
* Series 0 will have tokens 0, 1, 2…; series 1 will have tokens 1000, 1001,
* etc.
*/
uint256 private constant _tokenIdSeriesMultiplier = 1e4;
/**
* @dev Returns the seriesId of a token. The token may not exist.
*/
function tokenSeries(uint256 tokenId) public pure returns (uint256) {
return tokenId / _tokenIdSeriesMultiplier;
}
/**
* @dev Returns a token's edition within its series. The token may not exist.
*/
function tokenEditionNum(uint256 tokenId) public pure returns (uint256) {
return tokenId % _tokenIdSeriesMultiplier;
}
/**
* @dev Mints the next token in the series.
*/
function _safeMintInSeries(uint256 seriesId) internal seriesMustExist(seriesId) {
/**
* ################################
* There is a bug in this code that we only discovered after deployment.
* A minter can move their piece to a different wallet, reducing their
* balance, and then mint again. See GermanBakery.sol for the fix.
* ################################
*/
if (_msgSender() != owner()) {
if (onlyEarlyAccess) {
require(balanceOf(_msgSender()) < _earlyAccess[_msgSender()], "Early access exhausted for wallet");
} else {
require(balanceOf(_msgSender()) < seriesConfigs.length, "Wallet cap reached");
}
}
Series memory series = seriesConfigs[seriesId];
uint256 tokenId = seriesId * _tokenIdSeriesMultiplier + series.numMinted;
lastTokenMinted = tokenId;
tokenConfigs[tokenId] = TokenConfig({
paletteChanges: 0,
paletteBy: address(0),
paletteApproval: address(0),
paletteReset: 0,
palette: new bytes(0)
});
seriesConfigs[seriesId].numMinted++;
_safeMint(_msgSender(), tokenId);
emit TokenBMPChanged(tokenId);
}
/**
* @dev Emitted when the address is approved to change a token's palette.
*/
event PaletteApproval(uint256 indexed tokenId, address approved);
/**
* @dev Approve the address to change the token's palette.
*
* Set to 0x00 address to revoke. Token owner and ERC721 approved already
* have palette approval. This is to allow someone else to modify a palette
* without the risk of them transferring the token.
*
* Revoked upon token transfer.
*/
function approveForPalette(uint256 tokenId, address approved) external {
require(_isApprovedOrOwner(_msgSender(), tokenId), "Only owner or approver");
address owner = ownerOf(tokenId);
require(approved != owner, "Approving token owner");
tokenConfigs[tokenId].paletteApproval = approved;
emit PaletteApproval(tokenId, approved);
}
/**
* @dev Emitted to signal changing of a token's BMP.
*/
event TokenBMPChanged(uint256 indexed tokenId);
/**
* @dev Require that the message sender is approved for palette changes.
*/
modifier approvedForPalette(uint256 tokenId) {
require(
_isApprovedOrOwner(_msgSender(), tokenId) ||
tokenConfigs[tokenId].paletteApproval == _msgSender(),
"Not approved for palette"
);
_;
}
/**
* @dev Clear a token's palette, using the series default instead.
*
* Does not reset the paletteChanges count, but increments it.
*
* Emits TokenBMPChanged(tokenId);
*/
function resetPalette(uint256 tokenId) approvedForPalette(tokenId) external {
require(tokenConfigs[tokenId].paletteReset == 0, "Already reset");
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = address(0);
// Initial palette setting costs about 0.01 ETH at 30 gas but changes
// are a little over 25% of that. Using a boolean for reset adds
// negligible cost to the reset, in exchange for greater savings on the
// next setPalette() call.
tokenConfigs[tokenId].paletteReset = 1;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Set a token's palette if an owner or has approval.
*
* Emits TokenBMPChanged(tokenId).
*/
function setPalette(uint256 tokenId, bytes memory palette) approvedForPalette(tokenId) external {
require(palette.length == 768, "256 colours required");
tokenConfigs[tokenId].palette = palette;
tokenConfigs[tokenId].paletteChanges++;
tokenConfigs[tokenId].paletteBy = _msgSender();
tokenConfigs[tokenId].paletteReset = 0;
emit TokenBMPChanged(tokenId);
}
/**
* @dev Concatenates a series' patches into a single array.
*/
function seriesPixels(uint256 seriesId) public view seriesMustExist(seriesId) returns (bytes memory) {
return _brots.concatenatePatches(seriesConfigs[seriesId].patches);
}
/**
* @dev Token equivalent of seriesPixels().
*/
function pixelsOf(uint256 tokenId) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
return seriesPixels(tokenSeries(tokenId));
}
/**
* @dev Returns the effective token palette, considering resets.
*
* Boolean flag indicates whether it's the original palette; i.e. nothing is
* set or the palette has been explicitly reset().
*/
function _tokenPalette(uint256 tokenId) private view returns (bytes memory, bool) {
TokenConfig memory token = tokenConfigs[tokenId];
bytes memory palette = token.palette;
bool original = token.paletteReset == 1 || palette.length == 0;
if (original) {
palette = seriesConfigs[tokenSeries(tokenId)].defaultPalette;
if (palette.length == 0) {
palette = _bmp.grayscale();
}
}
return (palette, original);
}
/**
* @dev Returns the BMP-encoded token image, scaling pixels in both dimensions.
*
* Scale of 0 is treated as 1.
*/
function bmpOf(uint256 tokenId, uint32 scale) public view returns (bytes memory) {
require(_exists(tokenId), "Token doesn't exist");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
(bytes memory palette, ) = _tokenPalette(tokenId);
bytes memory pixels = pixelsOf(tokenId);
if (scale > 1) {
return _bmp.bmp(
_bmp.scalePixels(pixels, series.width, series.height, scale),
series.width * scale,
series.height * scale,
palette
);
}
return _bmp.bmp(pixels, series.width, series.height, palette);
}
/**
* @dev Equivalent to bmpOf() but encoded as a data URI to view in a browser.
*/
function bmpDataURIOf(uint256 tokenId, uint32 scale) public view returns (string memory) {
return _bmp.bmpDataURI(bmpOf(tokenId, scale));
}
/**
* @dev Renders the token as an ASCII brot.
*
* This is an homage to Robert W Brooks and Peter Matelski who were the
* first to render the Mandelbrot, in this form.
*/
function brooksMatelskiOf(uint256 tokenId, string memory characters) external view returns (string memory) {
bytes memory charset = abi.encodePacked(characters);
require(charset.length == 256, "256 characters");
Series memory series = seriesConfigs[tokenSeries(tokenId)];
// Include newlines except for the end.
bytes memory ascii = new bytes((series.width+1)*series.height - 1);
bytes memory pixels = pixelsOf(tokenId);
uint col;
uint a; // ascii index
for (uint p = 0; p < pixels.length; p++) {
ascii[a] = charset[uint8(pixels[p])];
a++;
col++;
if (col == series.width && a < ascii.length) {
ascii[a] = 0x0a; // Not compatible with Windows and typewriters.
a++;
col = 0;
}
}
return string(ascii);
}
/**
* @dev Base URL for external_url metadata field.
*/
string private _baseExternalUrl = "https://brotchain.art/brot/";
/**
* @dev Set the base URL for external_url metadata field.
*/
function setBaseExternalUrl(string memory url) public onlyOwner {
_baseExternalUrl = url;
}
/**
* @dev Returns data URI of token metadata.
*
* The BMP-encoded image is included in its own base64-encoded data URI.
*/
function tokenURI(uint256 tokenId) public override view returns (string memory) {
TokenConfig memory token = tokenConfigs[tokenId];
Series memory series = seriesConfigs[tokenSeries(tokenId)];
uint256 editionNum = tokenEditionNum(tokenId);
bytes memory data = abi.encodePacked(
'data:application/json,{',
'"name":"', series.name, ' #', Strings.toString(editionNum) ,'",',
'"description":"', series.description, '",'
'"external_url":"', _baseExternalUrl, Strings.toString(tokenId),'",'
);
// Combining this packing with the one above would result in the stack
// being too deep and a failure to compile.
data = abi.encodePacked(
data,
'"attributes":['
'{"value":"', series.name, '"},'
'{',
'"trait_type":"Palette Changes",',
'"value":', Strings.toString(token.paletteChanges),
'}'
);
if (token.paletteBy != address(0)) {
data = abi.encodePacked(
data,
',{',
'"trait_type":"Palette By",',
'"value":"', Strings.toHexString(uint256(uint160(token.paletteBy)), 20),'"',
'}'
);
}
(, bool original) = _tokenPalette(tokenId);
if (original) {
data = abi.encodePacked(
data,
',{"value":"Original Palette"}'
);
}
if (editionNum == 0) {
data = abi.encodePacked(
data,
',{"value":"Genesis"}'
);
}
return string(abi.encodePacked(
data,
'],',
'"image":"', bmpDataURIOf(tokenId, 1), '"',
'}'
));
}
/**
* @dev Pause the contract.
*/
function pause() external onlyOwner {
_pause();
}
/**
* @dev Unpause the contract.
*/
function unpause() external onlyOwner {
_unpause();
}
function isApprovedForAll(address owner, address operator) public view override returns (bool) {
return super.isApprovedForAll(owner, operator) || isOwnersOpenSeaProxy(owner, operator);
}
/**
* @dev OpenSea collection config.
*
* https://docs.opensea.io/docs/contract-level-metadata
*/
function setContractURI(string memory contractURI) external onlyOwner {
_setContractURI(contractURI);
}
/**
* @dev Revoke palette approval upon token transfer.
*/
function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable, ERC721Pausable) {
tokenConfigs[tokenId].paletteApproval = address(0);
super._beforeTokenTransfer(from, to, tokenId);
}
function supportsInterface(bytes4 interfaceId) public view override (ERC721, ERC721Enumerable) returns (bool) {
return super.supportsInterface(interfaceId);
}
} | _beforeTokenTransfer | function _beforeTokenTransfer(address from, address to, uint256 tokenId) internal virtual override(ERC721Enumerable, ERC721Pausable) {
tokenConfigs[tokenId].paletteApproval = address(0);
super._beforeTokenTransfer(from, to, tokenId);
}
| /**
* @dev Revoke palette approval upon token transfer.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | {
"func_code_index": [
20395,
20654
]
} | 3,810 |
||||
NametagToken | contracts/NametagToken.sol | 0x534ccee849a688581d1b0c65e7ff317ed10c5ed3 | Solidity | NametagToken | contract NametagToken is ERC165, ERC721, IERC721Metadata {
// Token name
string internal _name;
// Token symbol
string internal _symbol;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
/**
* @dev Constructor function
*/
constructor(string name, string symbol) public {
_name = name;
_symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata);
}
function claimNametagToken(
address to,
bytes32 name
)
public
returns (bool)
{
uint256 tokenId = (uint256) (keccak256(name));
string memory metadata = bytes32ToString(name);
_mint(to, tokenId);
_setTokenURI(tokenId, metadata);
return true;
}
function bytes32ToTokenId(bytes32 x) public constant returns (uint256) {
return (uint256) (keccak256(x));
}
function bytes32ToString(bytes32 x) public constant returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/
function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
} | name | function name() external view returns (string) {
return _name;
}
| /**
* @dev Gets the token name
* @return string representing the token name
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://c0a733cbe4c09a4bc5ce58392de591b6a194abca0a37694cc8a96d772c7807e6 | {
"func_code_index": [
1884,
1959
]
} | 3,811 |
|||
NametagToken | contracts/NametagToken.sol | 0x534ccee849a688581d1b0c65e7ff317ed10c5ed3 | Solidity | NametagToken | contract NametagToken is ERC165, ERC721, IERC721Metadata {
// Token name
string internal _name;
// Token symbol
string internal _symbol;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
/**
* @dev Constructor function
*/
constructor(string name, string symbol) public {
_name = name;
_symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata);
}
function claimNametagToken(
address to,
bytes32 name
)
public
returns (bool)
{
uint256 tokenId = (uint256) (keccak256(name));
string memory metadata = bytes32ToString(name);
_mint(to, tokenId);
_setTokenURI(tokenId, metadata);
return true;
}
function bytes32ToTokenId(bytes32 x) public constant returns (uint256) {
return (uint256) (keccak256(x));
}
function bytes32ToString(bytes32 x) public constant returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/
function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
} | symbol | function symbol() external view returns (string) {
return _symbol;
}
| /**
* @dev Gets the token symbol
* @return string representing the token symbol
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://c0a733cbe4c09a4bc5ce58392de591b6a194abca0a37694cc8a96d772c7807e6 | {
"func_code_index": [
2060,
2139
]
} | 3,812 |
|||
NametagToken | contracts/NametagToken.sol | 0x534ccee849a688581d1b0c65e7ff317ed10c5ed3 | Solidity | NametagToken | contract NametagToken is ERC165, ERC721, IERC721Metadata {
// Token name
string internal _name;
// Token symbol
string internal _symbol;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
/**
* @dev Constructor function
*/
constructor(string name, string symbol) public {
_name = name;
_symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata);
}
function claimNametagToken(
address to,
bytes32 name
)
public
returns (bool)
{
uint256 tokenId = (uint256) (keccak256(name));
string memory metadata = bytes32ToString(name);
_mint(to, tokenId);
_setTokenURI(tokenId, metadata);
return true;
}
function bytes32ToTokenId(bytes32 x) public constant returns (uint256) {
return (uint256) (keccak256(x));
}
function bytes32ToString(bytes32 x) public constant returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/
function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
} | tokenURI | function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
| /**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://c0a733cbe4c09a4bc5ce58392de591b6a194abca0a37694cc8a96d772c7807e6 | {
"func_code_index": [
2336,
2474
]
} | 3,813 |
|||
NametagToken | contracts/NametagToken.sol | 0x534ccee849a688581d1b0c65e7ff317ed10c5ed3 | Solidity | NametagToken | contract NametagToken is ERC165, ERC721, IERC721Metadata {
// Token name
string internal _name;
// Token symbol
string internal _symbol;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
/**
* @dev Constructor function
*/
constructor(string name, string symbol) public {
_name = name;
_symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata);
}
function claimNametagToken(
address to,
bytes32 name
)
public
returns (bool)
{
uint256 tokenId = (uint256) (keccak256(name));
string memory metadata = bytes32ToString(name);
_mint(to, tokenId);
_setTokenURI(tokenId, metadata);
return true;
}
function bytes32ToTokenId(bytes32 x) public constant returns (uint256) {
return (uint256) (keccak256(x));
}
function bytes32ToString(bytes32 x) public constant returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/
function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
} | _setTokenURI | function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
| /**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://c0a733cbe4c09a4bc5ce58392de591b6a194abca0a37694cc8a96d772c7807e6 | {
"func_code_index": [
2704,
2837
]
} | 3,814 |
|||
NametagToken | contracts/NametagToken.sol | 0x534ccee849a688581d1b0c65e7ff317ed10c5ed3 | Solidity | NametagToken | contract NametagToken is ERC165, ERC721, IERC721Metadata {
// Token name
string internal _name;
// Token symbol
string internal _symbol;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
bytes4 private constant InterfaceId_ERC721Metadata = 0x5b5e139f;
/**
* 0x5b5e139f ===
* bytes4(keccak256('name()')) ^
* bytes4(keccak256('symbol()')) ^
* bytes4(keccak256('tokenURI(uint256)'))
*/
/**
* @dev Constructor function
*/
constructor(string name, string symbol) public {
_name = name;
_symbol = symbol;
// register the supported interfaces to conform to ERC721 via ERC165
_registerInterface(InterfaceId_ERC721Metadata);
}
function claimNametagToken(
address to,
bytes32 name
)
public
returns (bool)
{
uint256 tokenId = (uint256) (keccak256(name));
string memory metadata = bytes32ToString(name);
_mint(to, tokenId);
_setTokenURI(tokenId, metadata);
return true;
}
function bytes32ToTokenId(bytes32 x) public constant returns (uint256) {
return (uint256) (keccak256(x));
}
function bytes32ToString(bytes32 x) public constant returns (string) {
bytes memory bytesString = new bytes(32);
uint charCount = 0;
for (uint j = 0; j < 32; j++) {
byte char = byte(bytes32(uint(x) * 2 ** (8 * j)));
if (char != 0) {
bytesString[charCount] = char;
charCount++;
}
}
bytes memory bytesStringTrimmed = new bytes(charCount);
for (j = 0; j < charCount; j++) {
bytesStringTrimmed[j] = bytesString[j];
}
return string(bytesStringTrimmed);
}
/**
* @dev Gets the token name
* @return string representing the token name
*/
function name() external view returns (string) {
return _name;
}
/**
* @dev Gets the token symbol
* @return string representing the token symbol
*/
function symbol() external view returns (string) {
return _symbol;
}
/**
* @dev Returns an URI for a given token ID
* Throws if the token ID does not exist. May return an empty string.
* @param tokenId uint256 ID of the token to query
*/
function tokenURI(uint256 tokenId) public view returns (string) {
require(_exists(tokenId));
return _tokenURIs[tokenId];
}
/**
* @dev Internal function to set the token URI for a given token
* Reverts if the token ID does not exist
* @param tokenId uint256 ID of the token to set its URI
* @param uri string URI to assign
*/
function _setTokenURI(uint256 tokenId, string uri) internal {
require(_exists(tokenId));
_tokenURIs[tokenId] = uri;
}
/**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/
function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
} | _burn | function _burn(address owner, uint256 tokenId) internal {
super._burn(owner, tokenId);
// Clear metadata (if any)
if (bytes(_tokenURIs[tokenId]).length != 0) {
delete _tokenURIs[tokenId];
}
}
| /**
* @dev Internal function to burn a specific token
* Reverts if the token does not exist
* @param owner owner of the token to burn
* @param tokenId uint256 ID of the token being burned by the msg.sender
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | bzzr://c0a733cbe4c09a4bc5ce58392de591b6a194abca0a37694cc8a96d772c7807e6 | {
"func_code_index": [
3072,
3298
]
} | 3,815 |
|||
MasterChef | contracts/OreToken.sol | 0x895c75efea36658c2fb452202743208d3d802f34 | Solidity | OreToken | contract OreToken is ERC20("BeeToken", "BEE"), Ownable {
/// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef).
function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
}
} | // OreToken with Governance. | LineComment | mint | function mint(address _to, uint256 _amount) public onlyOwner {
_mint(_to, _amount);
}
| /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (MasterChef). | NatSpecSingleLine | v0.6.12+commit.27d51765 | MIT | ipfs://f102d7fbb97a406fe49d459cf680abdff8e28afe69695a205f3089f8484aa9ee | {
"func_code_index": [
156,
260
]
} | 3,816 |
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mul | function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
| /**
* @dev Multiplies two numbers, reverts on overflow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
94,
497
]
} | 3,817 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | div | function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
609,
897
]
} | 3,818 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | sub | function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
| /**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1012,
1157
]
} | 3,819 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | add | function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
| /**
* @dev Adds two numbers, reverts on overflow.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1222,
1366
]
} | 3,820 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 _a, uint256 _b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (_a == 0) {
return 0;
}
uint256 c = _a * _b;
require(c / _a == _b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = _a / _b;
// assert(_a == _b * c + _a % _b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
require(_b <= _a);
uint256 c = _a - _b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 _a, uint256 _b) internal pure returns (uint256) {
uint256 c = _a + _b;
require(c >= _a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/ | NatSpecMultiLine | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
| /**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1501,
1618
]
} | 3,821 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return totalSupply_;
}
| /**
* @dev total number of tokens in existence
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
199,
287
]
} | 3,822 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
445,
777
]
} | 3,823 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
983,
1087
]
} | 3,824 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
399,
856
]
} | 3,825 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1488,
1683
]
} | 3,826 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
2007,
2138
]
} | 3,827 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
2604,
2883
]
} | 3,828 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = (
allowed[msg.sender][_spender].add(_addedValue));
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | decreaseApproval | function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
3354,
3773
]
} | 3,829 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Role | contract Role is StandardToken {
using SafeMath for uint256;
address public owner;
address public admin;
uint256 public contractDeployed = now;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event AdminshipTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
require(msg.sender == admin);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Allows the current admin to transfer control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function transferAdminship(address _newAdmin) external onlyAdmin {
_transferAdminship(_newAdmin);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
balances[owner] = balances[owner].sub(balances[owner]);
balances[_newOwner] = balances[_newOwner].add(balances[owner]);
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
/**
* @dev Transfers control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function _transferAdminship(address _newAdmin) internal {
require(_newAdmin != address(0));
emit AdminshipTransferred(admin, _newAdmin);
admin = _newAdmin;
}
} | transferOwnership | function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
916,
1035
]
} | 3,830 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Role | contract Role is StandardToken {
using SafeMath for uint256;
address public owner;
address public admin;
uint256 public contractDeployed = now;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event AdminshipTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
require(msg.sender == admin);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Allows the current admin to transfer control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function transferAdminship(address _newAdmin) external onlyAdmin {
_transferAdminship(_newAdmin);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
balances[owner] = balances[owner].sub(balances[owner]);
balances[_newOwner] = balances[_newOwner].add(balances[owner]);
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
/**
* @dev Transfers control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function _transferAdminship(address _newAdmin) internal {
require(_newAdmin != address(0));
emit AdminshipTransferred(admin, _newAdmin);
admin = _newAdmin;
}
} | transferAdminship | function transferAdminship(address _newAdmin) external onlyAdmin {
_transferAdminship(_newAdmin);
}
| /**
* @dev Allows the current admin to transfer control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1205,
1323
]
} | 3,831 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Role | contract Role is StandardToken {
using SafeMath for uint256;
address public owner;
address public admin;
uint256 public contractDeployed = now;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event AdminshipTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
require(msg.sender == admin);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Allows the current admin to transfer control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function transferAdminship(address _newAdmin) external onlyAdmin {
_transferAdminship(_newAdmin);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
balances[owner] = balances[owner].sub(balances[owner]);
balances[_newOwner] = balances[_newOwner].add(balances[owner]);
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
/**
* @dev Transfers control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function _transferAdminship(address _newAdmin) internal {
require(_newAdmin != address(0));
emit AdminshipTransferred(admin, _newAdmin);
admin = _newAdmin;
}
} | _transferOwnership | function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
balances[owner] = balances[owner].sub(balances[owner]);
balances[_newOwner] = balances[_newOwner].add(balances[owner]);
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
| /**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1466,
1798
]
} | 3,832 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Role | contract Role is StandardToken {
using SafeMath for uint256;
address public owner;
address public admin;
uint256 public contractDeployed = now;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event AdminshipTransferred(
address indexed previousAdmin,
address indexed newAdmin
);
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Throws if called by any account other than the admin.
*/
modifier onlyAdmin() {
require(msg.sender == admin);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) external onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Allows the current admin to transfer control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function transferAdminship(address _newAdmin) external onlyAdmin {
_transferAdminship(_newAdmin);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
balances[owner] = balances[owner].sub(balances[owner]);
balances[_newOwner] = balances[_newOwner].add(balances[owner]);
owner = _newOwner;
emit OwnershipTransferred(owner, _newOwner);
}
/**
* @dev Transfers control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/
function _transferAdminship(address _newAdmin) internal {
require(_newAdmin != address(0));
emit AdminshipTransferred(admin, _newAdmin);
admin = _newAdmin;
}
} | _transferAdminship | function _transferAdminship(address _newAdmin) internal {
require(_newAdmin != address(0));
emit AdminshipTransferred(admin, _newAdmin);
admin = _newAdmin;
}
| /**
* @dev Transfers control of the contract to a newAdmin.
* @param _newAdmin The address to transfer adminship to.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1941,
2135
]
} | 3,833 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Pausable | contract Pausable is Role {
event Pause();
event Unpause();
event NotPausable();
bool public paused = false;
bool public canPause = true;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused || msg.sender == owner);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
**/
function pause() onlyOwner whenNotPaused public {
require(canPause == true);
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
require(paused == true);
paused = false;
emit Unpause();
}
/**
* @dev Prevent the token from ever being paused again
**/
function notPausable() onlyOwner public{
paused = false;
canPause = false;
emit NotPausable();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | pause | function pause() onlyOwner whenNotPaused public {
require(canPause == true);
paused = true;
emit Pause();
}
| /**
* @dev called by the owner to pause, triggers stopped state
**/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
592,
736
]
} | 3,834 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Pausable | contract Pausable is Role {
event Pause();
event Unpause();
event NotPausable();
bool public paused = false;
bool public canPause = true;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused || msg.sender == owner);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
**/
function pause() onlyOwner whenNotPaused public {
require(canPause == true);
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
require(paused == true);
paused = false;
emit Unpause();
}
/**
* @dev Prevent the token from ever being paused again
**/
function notPausable() onlyOwner public{
paused = false;
canPause = false;
emit NotPausable();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | unpause | function unpause() onlyOwner whenPaused public {
require(paused == true);
paused = false;
emit Unpause();
}
| /**
* @dev called by the owner to unpause, returns to normal state
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
820,
948
]
} | 3,835 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | Pausable | contract Pausable is Role {
event Pause();
event Unpause();
event NotPausable();
bool public paused = false;
bool public canPause = true;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused || msg.sender == owner);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
**/
function pause() onlyOwner whenNotPaused public {
require(canPause == true);
paused = true;
emit Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
require(paused == true);
paused = false;
emit Unpause();
}
/**
* @dev Prevent the token from ever being paused again
**/
function notPausable() onlyOwner public{
paused = false;
canPause = false;
emit NotPausable();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | notPausable | function notPausable() onlyOwner public{
paused = false;
canPause = false;
emit NotPausable();
}
| /**
* @dev Prevent the token from ever being paused again
**/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1030,
1163
]
} | 3,836 |
|
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | lockedTokens | function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
| /**
* @dev Locked number of tokens in existence
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1395,
1491
]
} | 3,837 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | isContract | function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
| /**
* @dev function to check whether passed address is a contract address
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1579,
1867
]
} | 3,838 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | burn | function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
| /**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
1973,
2243
]
} | 3,839 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | burnFrom | function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
| /**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
2474,
2861
]
} | 3,840 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | transferAnyERC20Token | function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
| /**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/ | NatSpecMultiLine | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
3216,
3466
]
} | 3,841 |
|||
SamToken | SamToken.sol | 0x99ed1f3fab1b072764098d5ed88ca79836c3bdaa | Solidity | SamToken | contract SamToken is Pausable {
using SafeMath for uint;
uint256 _lockedTokens;
bool isLocked = true ;
bool releasedForOwner ;
uint256 public ownerPercent = 10;
uint256 public ownerSupply;
uint256 public adminPercent = 90;
uint256 public adminSupply ;
//The name of the token
string public constant name = "SAM Token";
//The token symbol
string public constant symbol = "SAM";
//The precision used in the balance calculations in contract
uint public constant decimals = 0;
event Burn(address indexed burner, uint256 value);
event CompanyTokenReleased( address indexed _company, uint256 indexed _tokens );
constructor(
address _owner,
address _admin,
uint256 _totalsupply
) public {
owner = _owner;
admin = _admin;
_totalsupply = _totalsupply ;
totalSupply_ = totalSupply_.add(_totalsupply);
adminSupply = 900000000 ;
ownerSupply = 100000000 ;
_lockedTokens = _lockedTokens.add(ownerSupply);
balances[admin] = balances[admin].add(adminSupply);
isLocked = true;
emit Transfer(address(0), admin, adminSupply );
}
modifier onlyPayloadSize(uint numWords) {
assert(msg.data.length >= numWords * 32 + 4);
_;
}
/**
* @dev Locked number of tokens in existence
*/
function lockedTokens() public view returns (uint256) {
return _lockedTokens;
}
/**
* @dev function to check whether passed address is a contract address
*/
function isContract(address _address) private view returns (bool is_contract) {
uint256 length;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_address)
}
return (length > 0);
}
/**
* @dev Burns a specific amount of tokens.
* @param _value The amount of token to be burned.
*/
function burn(uint _value) public returns (bool success) {
require(balances[msg.sender] >= _value);
balances[msg.sender] = balances[msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(msg.sender, _value);
return true;
}
/**
* @dev Burns a specific amount of tokens from the target address and decrements allowance
* @param from address The address which you want to send tokens from
* @param _value uint256 The amount of token to be burned
*/
function burnFrom(address from, uint _value) public returns (bool success) {
require(balances[from] >= _value);
require(_value <= allowed[from][msg.sender]);
balances[from] = balances[from].sub(_value);
allowed[from][msg.sender] = allowed[from][msg.sender].sub(_value);
totalSupply_ = totalSupply_.sub(_value);
emit Burn(from, _value);
return true;
}
function () public payable {
revert();
}
/**
* @dev Function to transfer any ERC20 token to owner address which gets accidentally transferred to this contract
* @param tokenAddress The address of the ERC20 contract
* @param tokens The amount of tokens to transfer.
* @return A boolean that indicates if the operation was successful.
*/
function transferAnyERC20Token(address tokenAddress, uint tokens) public onlyOwner returns (bool success) {
require(tokenAddress != address(0));
require(isContract(tokenAddress));
return ERC20(tokenAddress).transfer(owner, tokens);
}
// Transfer token to team
function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
} | companyTokensRelease | function companyTokensRelease(address _company) external onlyAdmin returns(bool) {
require(_company != address(0), "Address is not valid");
require(!releasedForOwner, "Team release has already done");
if (now > contractDeployed.add(365 days) && releasedForOwner == false ) {
balances[_company] = balances[_company].add(_lockedTokens);
isLocked = false;
releasedForOwner = true;
emit CompanyTokenReleased(_company, _lockedTokens);
return true;
}
}
| // Transfer token to team | LineComment | v0.4.24+commit.e67f0147 | bzzr://02611edbd857c0500732e3b8d3014e11f527e446f3c7fff324114ed4427f3629 | {
"func_code_index": [
3497,
4036
]
} | 3,842 |
|||
LostApes | lostapes.sol | 0x0e70916c835cea8c78b58bc36dfd056fae97d535 | Solidity | LostApes | contract LostApes is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.07 ether;
uint256 public maxSupply = 3500;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 5;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function withdraw() public payable onlyOwner {
// This will pay 5% of the initial sale for Marketing.
// =============================================================================
(bool hs, ) = payable(0x2A398cD7B5F1c618280cC3DFF55dE1Cc1444a73c).call{value: address(this).balance * 5 / 100}("");
require(hs);
// =============================================================================
// This will payout the owner 95% of the contract balance.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================
}
} | _baseURI | function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
| // internal | LineComment | v0.8.7+commit.e28d00a7 | GNU GPLv3 | ipfs://e59dce6ace3462900ee47bdca3a1129861f367b477155460bf9205af4e74a412 | {
"func_code_index": [
815,
920
]
} | 3,843 |
||
LostApes | lostapes.sol | 0x0e70916c835cea8c78b58bc36dfd056fae97d535 | Solidity | LostApes | contract LostApes is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.07 ether;
uint256 public maxSupply = 3500;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 5;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function withdraw() public payable onlyOwner {
// This will pay 5% of the initial sale for Marketing.
// =============================================================================
(bool hs, ) = payable(0x2A398cD7B5F1c618280cC3DFF55dE1Cc1444a73c).call{value: address(this).balance * 5 / 100}("");
require(hs);
// =============================================================================
// This will payout the owner 95% of the contract balance.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================
}
} | mint | function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
| // public | LineComment | v0.8.7+commit.e28d00a7 | GNU GPLv3 | ipfs://e59dce6ace3462900ee47bdca3a1129861f367b477155460bf9205af4e74a412 | {
"func_code_index": [
936,
1876
]
} | 3,844 |
||
LostApes | lostapes.sol | 0x0e70916c835cea8c78b58bc36dfd056fae97d535 | Solidity | LostApes | contract LostApes is ERC721Enumerable, Ownable {
using Strings for uint256;
string public baseURI;
string public baseExtension = ".json";
string public notRevealedUri;
uint256 public cost = 0.07 ether;
uint256 public maxSupply = 3500;
uint256 public maxMintAmount = 20;
uint256 public nftPerAddressLimit = 5;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
address[] public whitelistedAddresses;
mapping(address => uint256) public addressMintedBalance;
constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);
}
// internal
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
// public
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
function isWhitelisted(address _user) public view returns (bool) {
for (uint i = 0; i < whitelistedAddresses.length; i++) {
if (whitelistedAddresses[i] == _user) {
return true;
}
}
return false;
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
public
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return notRevealedUri;
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension))
: "";
}
//only owner
function reveal() public onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) public onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) public onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function setBaseExtension(string memory _newBaseExtension) public onlyOwner {
baseExtension = _newBaseExtension;
}
function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
notRevealedUri = _notRevealedURI;
}
function pause(bool _state) public onlyOwner {
paused = _state;
}
function setOnlyWhitelisted(bool _state) public onlyOwner {
onlyWhitelisted = _state;
}
function whitelistUsers(address[] calldata _users) public onlyOwner {
delete whitelistedAddresses;
whitelistedAddresses = _users;
}
function withdraw() public payable onlyOwner {
// This will pay 5% of the initial sale for Marketing.
// =============================================================================
(bool hs, ) = payable(0x2A398cD7B5F1c618280cC3DFF55dE1Cc1444a73c).call{value: address(this).balance * 5 / 100}("");
require(hs);
// =============================================================================
// This will payout the owner 95% of the contract balance.
// Do not remove this otherwise you will not be able to withdraw the funds.
// =============================================================================
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
// =============================================================================
}
} | reveal | function reveal() public onlyOwner {
revealed = true;
}
| //only owner | LineComment | v0.8.7+commit.e28d00a7 | GNU GPLv3 | ipfs://e59dce6ace3462900ee47bdca3a1129861f367b477155460bf9205af4e74a412 | {
"func_code_index": [
2999,
3067
]
} | 3,845 |
||
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | _checkValidity | function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
| // XXX DO NOT add the same LP token more than once. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
4835,
5089
]
} | 3,846 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | add | function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
| // Add a new lp to the pool. Can only be called by the admin. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
5159,
6050
]
} | 3,847 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | set | function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
| // Update the given pool's SAKE allocation point. Can only be called by the admin. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
6141,
6547
]
} | 3,848 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setSakeLockSwitch | function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
| // set sake withdraw switch. Can only be called by the admin. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
6968,
7303
]
} | 3,849 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | getMultiplier | function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
| // Return reward multiplier over the given _from to _to block. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
7374,
8509
]
} | 3,850 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | handoverSakeMintage | function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
| // Handover the saketoken mintage right. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
9162,
9282
]
} | 3,851 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | pendingSake | function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
| // View function to see pending SAKEs on frontend. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
9341,
10520
]
} | 3,852 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | massUpdatePools | function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
| // Update reward vairables for all pools. Be careful of gas spending! | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
10598,
10783
]
} | 3,853 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | updatePool | function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
| // Update reward variables of the given pool to be up-to-date. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
10854,
12160
]
} | 3,854 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | deposit | function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
| // Deposit LP tokens to SakeMasterV2 for SAKE allocation. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
12226,
14666
]
} | 3,855 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | withdraw | function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
| // Withdraw LP tokens from SakeMaster. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
14713,
16617
]
} | 3,856 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | emergencyWithdraw | function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
| // Withdraw without caring about rewards. EMERGENCY ONLY. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
16683,
17669
]
} | 3,857 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | _safeSakeTransfer | function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
| // Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
17778,
18062
]
} | 3,858 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setAdmin | function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
| // Update admin address by owner. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
18104,
18264
]
} | 3,859 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setSakeMaker | function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
| // Update sakeMaker address by admin. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
18310,
18540
]
} | 3,860 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setSakeFeeAddress | function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
| // Update sakeFee address by admin. | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
18584,
18839
]
} | 3,861 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setTradeMiningSpeedUpEndBlock | function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
| // update tradeMiningSpeedUpEndBlock by owner | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
18893,
19156
]
} | 3,862 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setYieldFarmingIIEndBlock | function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
| // update yieldFarmingIIEndBlock by owner | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
19206,
19459
]
} | 3,863 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setTradeMiningEndBlock | function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
| // update tradeMiningEndBlock by owner | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
19506,
19753
]
} | 3,864 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setSakePerBlockYieldFarming | function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
| // set sakePerBlock phase II yield farming | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
20460,
20779
]
} | 3,865 |
SakeVoterCalc | contracts/SakeMasterV2.sol | 0x44d84a9da47fd8f4a06ad66b197d1441fca53f92 | Solidity | SakeMasterV2 | contract SakeMasterV2 is Ownable {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// Info of each user.
struct UserInfo {
uint256 amount; // How many LP tokens the user has provided.
uint256 amountStoken; // How many S tokens the user has provided.
uint256 amountLPtoken; // How many LP tokens the user has provided.
uint256 pengdingSake; // record sake amount when user withdraw lp.
uint256 rewardDebt; // Reward debt. See explanation below.
uint256 lastWithdrawBlock; // user last withdraw time;
//
// We do some fancy math here. Basically, any point in time, the amount of SAKEs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accSakePerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws LP tokens to a pool. Here's what happens:
// 1. The pool's `accSakePerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 lpToken; // Address of LP token contract.
IERC20 sToken; // Address of S token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. SAKEs to distribute per block.
uint256 lastRewardBlock; // Last block number that SAKEs distribution occurs.
uint256 accSakePerShare; // Accumulated SAKEs per share, times 1e12. See below.
uint256 multiplierSToken; // times 1e8;
bool sakeLockSwitch; // true-have sake withdraw interval,default 1 months;false-no withdraw interval,but have sake withdraw fee,default 10%
}
// The SAKE TOKEN!
SakeToken public sake;
// sakeMaker address.
address public sakeMaker;
// admin address.
address public admin;
// receive sake fee address
address public sakeFeeAddress;
// Block number when trade mining speed up period ends.
uint256 public tradeMiningSpeedUpEndBlock;
// Block number when phase II yield farming period ends.
uint256 public yieldFarmingIIEndBlock;
// Block number when trade mining period ends.
uint256 public tradeMiningEndBlock;
// trade mining speed end block num,about 1 months.
uint256 public tradeMiningSpeedUpEndBlockNum = 192000;
// phase II yield farming end block num,about 6 months.
uint256 public yieldFarmingIIEndBlockNum = 1152000;
// trade mining end block num,about 12 months.
uint256 public tradeMiningEndBlockNum = 2304000;
// SAKE tokens created per block for phase II yield farming.
uint256 public sakePerBlockYieldFarming = 5 * 10**18;
// SAKE tokens created per block for trade mining.
uint256 public sakePerBlockTradeMining = 10 * 10**18;
// Bonus muliplier for trade mining.
uint256 public constant BONUS_MULTIPLIER = 2;
// withdraw block num interval,about 1 months.
uint256 public withdrawInterval = 192000;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint = 0;
// The block number when SAKE mining starts.
uint256 public startBlock;
// The ratio of withdraw lp fee(default is 0%)
uint8 public lpFeeRatio = 0;
// The ratio of withdraw sake fee if no withdraw interval(default is 10%)
uint8 public sakeFeeRatio = 10;
// Info of each pool.
PoolInfo[] public poolInfo;
// Info of each user that stakes LP tokens and S tokens.
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
event Deposit(address indexed user, uint256 indexed pid, uint256 amountLPtoken, uint256 amountStoken);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amountLPtoken);
constructor(
SakeToken _sake,
address _admin,
address _sakeMaker,
address _sakeFeeAddress,
uint256 _startBlock
) public {
sake = _sake;
admin = _admin;
sakeMaker = _sakeMaker;
sakeFeeAddress = _sakeFeeAddress;
startBlock = _startBlock;
tradeMiningSpeedUpEndBlock = startBlock.add(tradeMiningSpeedUpEndBlockNum);
yieldFarmingIIEndBlock = startBlock.add(yieldFarmingIIEndBlockNum);
tradeMiningEndBlock = startBlock.add(tradeMiningEndBlockNum);
}
function poolLength() external view returns (uint256) {
return poolInfo.length;
}
// XXX DO NOT add the same LP token more than once.
function _checkValidity(IERC20 _lpToken, IERC20 _sToken) internal view {
for (uint256 i = 0; i < poolInfo.length; i++) {
require(poolInfo[i].lpToken != _lpToken && poolInfo[i].sToken != _sToken, "pool exist");
}
}
// Add a new lp to the pool. Can only be called by the admin.
function add(
uint256 _allocPoint,
uint256 _multiplierSToken,
IERC20 _lpToken,
IERC20 _sToken,
bool _withUpdate
) public {
require(msg.sender == admin, "add:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
_checkValidity(_lpToken, _sToken);
uint256 lastRewardBlock = block.number > startBlock ? block.number : startBlock;
totalAllocPoint = totalAllocPoint.add(_allocPoint);
poolInfo.push(
PoolInfo({
lpToken: _lpToken,
sToken: _sToken,
allocPoint: _allocPoint,
multiplierSToken: _multiplierSToken,
lastRewardBlock: lastRewardBlock,
accSakePerShare: 0,
sakeLockSwitch: true
})
);
}
// Update the given pool's SAKE allocation point. Can only be called by the admin.
function set(
uint256 _pid,
uint256 _allocPoint,
bool _withUpdate
) public {
require(msg.sender == admin, "set:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
totalAllocPoint = totalAllocPoint.sub(poolInfo[_pid].allocPoint).add(_allocPoint);
poolInfo[_pid].allocPoint = _allocPoint;
}
function setMultiplierSToken(
uint256 _pid,
uint256 _multiplierSToken,
bool _withUpdate
) public {
require(msg.sender == admin, "sms:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].multiplierSToken = _multiplierSToken;
}
// set sake withdraw switch. Can only be called by the admin.
function setSakeLockSwitch(
uint256 _pid,
bool _sakeLockSwitch,
bool _withUpdate
) public {
require(msg.sender == admin, "s:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
poolInfo[_pid].sakeLockSwitch = _sakeLockSwitch;
}
// Return reward multiplier over the given _from to _to block.
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256 multipY, uint256 multipT) {
uint256 _toFinalY = _to > yieldFarmingIIEndBlock ? yieldFarmingIIEndBlock : _to;
uint256 _toFinalT = _to > tradeMiningEndBlock ? tradeMiningEndBlock : _to;
// phase II yield farming multiplier
if (_from >= yieldFarmingIIEndBlock) {
multipY = 0;
} else {
multipY = _toFinalY.sub(_from);
}
// trade mining multiplier
if (_from >= tradeMiningEndBlock) {
multipT = 0;
} else {
if (_toFinalT <= tradeMiningSpeedUpEndBlock) {
multipT = _toFinalT.sub(_from).mul(BONUS_MULTIPLIER);
} else {
if (_from < tradeMiningSpeedUpEndBlock) {
multipT = tradeMiningSpeedUpEndBlock.sub(_from).mul(BONUS_MULTIPLIER).add(
_toFinalT.sub(tradeMiningSpeedUpEndBlock)
);
} else {
multipT = _toFinalT.sub(_from);
}
}
}
}
function getSakePerBlock(uint256 blockNum) public view returns (uint256) {
if (blockNum <= tradeMiningSpeedUpEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining.mul(BONUS_MULTIPLIER));
} else if (blockNum > tradeMiningSpeedUpEndBlock && blockNum <= yieldFarmingIIEndBlock) {
return sakePerBlockYieldFarming.add(sakePerBlockTradeMining);
} else if (blockNum > yieldFarmingIIEndBlock && blockNum <= tradeMiningEndBlock) {
return sakePerBlockTradeMining;
} else {
return 0;
}
}
// Handover the saketoken mintage right.
function handoverSakeMintage(address newOwner) public onlyOwner {
sake.transferOwnership(newOwner);
}
// View function to see pending SAKEs on frontend.
function pendingSake(uint256 _pid, address _user) external view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accSakePerShare = pool.accSakePerShare;
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (block.number > pool.lastRewardBlock && lpTokenSupply != 0) {
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
accSakePerShare = accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
}
return user.amount.mul(accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = poolInfo.length;
for (uint256 pid = 0; pid < length; ++pid) {
updatePool(pid);
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
if (block.number <= pool.lastRewardBlock) {
return;
}
uint256 lpTokenSupply = pool.lpToken.balanceOf(address(this));
uint256 sTokenSupply = pool.sToken.balanceOf(address(this));
if (lpTokenSupply == 0) {
pool.lastRewardBlock = block.number;
return;
}
(uint256 multipY, uint256 multipT) = getMultiplier(pool.lastRewardBlock, block.number);
if (multipY == 0 && multipT == 0) {
pool.lastRewardBlock = block.number;
return;
}
uint256 sakeRewardY = multipY.mul(sakePerBlockYieldFarming).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeRewardT = multipT.mul(sakePerBlockTradeMining).mul(pool.allocPoint).div(totalAllocPoint);
uint256 sakeReward = sakeRewardY.add(sakeRewardT);
uint256 totalSupply = lpTokenSupply.add(sTokenSupply.mul(pool.multiplierSToken).div(1e8));
if (sake.owner() == address(this)) {
sake.mint(address(this), sakeRewardT);
}
pool.accSakePerShare = pool.accSakePerShare.add(sakeReward.mul(1e12).div(totalSupply));
pool.lastRewardBlock = block.number;
}
// Deposit LP tokens to SakeMasterV2 for SAKE allocation.
function deposit(
uint256 _pid,
uint256 _amountlpToken,
uint256 _amountsToken
) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
if (_amountlpToken <= 0 && user.pengdingSake == 0) {
require(user.amountLPtoken > 0, "deposit:invalid");
}
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
uint256 _originAmountStoken = user.amountStoken;
user.amountLPtoken = user.amountLPtoken.add(_amountlpToken);
user.amountStoken = user.amountStoken.add(_amountsToken);
user.amount = user.amount.add(_amountlpToken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8)));
user.pengdingSake = pending;
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
user.amountStoken = _amountsToken;
user.amount = user.amountLPtoken.add(_amountsToken.mul(pool.multiplierSToken).div(1e8));
pool.sToken.safeTransfer(address(1), _originAmountStoken);
if (pending > 0) {
_safeSakeTransfer(msg.sender, pending);
}
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
if (_amountlpToken == 0 && _amountsToken == 0) {
user.amountStoken = 0;
user.amount = user.amountLPtoken;
pool.sToken.safeTransfer(address(1), _originAmountStoken);
}
if (pending > 0) {
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
}
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
pool.lpToken.safeTransferFrom(address(msg.sender), address(this), _amountlpToken);
pool.sToken.safeTransferFrom(address(msg.sender), address(this), _amountsToken);
emit Deposit(msg.sender, _pid, _amountlpToken, _amountsToken);
}
// Withdraw LP tokens from SakeMaster.
function withdraw(uint256 _pid, uint256 _amountLPtoken) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken >= _amountLPtoken, "withdraw: LP amount not enough");
updatePool(_pid);
uint256 pending = user.amount.mul(pool.accSakePerShare).div(1e12).add(user.pengdingSake).sub(user.rewardDebt);
user.amountLPtoken = user.amountLPtoken.sub(_amountLPtoken);
uint256 _amountStoken = user.amountStoken;
user.amountStoken = 0;
user.amount = user.amountLPtoken;
user.rewardDebt = user.amount.mul(pool.accSakePerShare).div(1e12);
if (pool.sakeLockSwitch) {
if (block.number > (user.lastWithdrawBlock.add(withdrawInterval))) {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
_safeSakeTransfer(msg.sender, pending);
} else {
user.pengdingSake = pending;
}
} else {
user.lastWithdrawBlock = block.number;
user.pengdingSake = 0;
uint256 sakeFee = pending.mul(sakeFeeRatio).div(100);
uint256 sakeToUser = pending.sub(sakeFee);
_safeSakeTransfer(msg.sender, sakeToUser);
_safeSakeTransfer(sakeFeeAddress, sakeFee);
}
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit Withdraw(msg.sender, _pid, lpTokenToUser);
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
function emergencyWithdraw(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
require(user.amountLPtoken > 0, "withdraw: LP amount not enough");
uint256 _amountLPtoken = user.amountLPtoken;
uint256 _amountStoken = user.amountStoken;
user.amount = 0;
user.amountLPtoken = 0;
user.amountStoken = 0;
user.rewardDebt = 0;
uint256 lpTokenFee;
uint256 lpTokenToUser;
if (block.number < tradeMiningEndBlock) {
lpTokenFee = _amountLPtoken.mul(lpFeeRatio).div(100);
pool.lpToken.safeTransfer(sakeMaker, lpTokenFee);
}
lpTokenToUser = _amountLPtoken.sub(lpTokenFee);
pool.lpToken.safeTransfer(address(msg.sender), lpTokenToUser);
pool.sToken.safeTransfer(address(1), _amountStoken);
emit EmergencyWithdraw(msg.sender, _pid, lpTokenToUser);
}
// Safe sake transfer function, just in case if rounding error causes pool to not have enough SAKEs.
function _safeSakeTransfer(address _to, uint256 _amount) internal {
uint256 sakeBal = sake.balanceOf(address(this));
if (_amount > sakeBal) {
sake.transfer(_to, sakeBal);
} else {
sake.transfer(_to, _amount);
}
}
// Update admin address by owner.
function setAdmin(address _adminaddr) public onlyOwner {
require(_adminaddr != address(0), "invalid address");
admin = _adminaddr;
}
// Update sakeMaker address by admin.
function setSakeMaker(address _sakeMaker) public {
require(msg.sender == admin, "sm:Call must come from admin.");
require(_sakeMaker != address(0), "invalid address");
sakeMaker = _sakeMaker;
}
// Update sakeFee address by admin.
function setSakeFeeAddress(address _sakeFeeAddress) public {
require(msg.sender == admin, "sf:Call must come from admin.");
require(_sakeFeeAddress != address(0), "invalid address");
sakeFeeAddress = _sakeFeeAddress;
}
// update tradeMiningSpeedUpEndBlock by owner
function setTradeMiningSpeedUpEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tmsu:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningSpeedUpEndBlock = _endBlock;
}
// update yieldFarmingIIEndBlock by owner
function setYieldFarmingIIEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "yf:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
yieldFarmingIIEndBlock = _endBlock;
}
// update tradeMiningEndBlock by owner
function setTradeMiningEndBlock(uint256 _endBlock) public {
require(msg.sender == admin, "tm:Call must come from admin.");
require(_endBlock > startBlock, "invalid endBlock");
tradeMiningEndBlock = _endBlock;
}
function setSakeFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "sfr:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
sakeFeeRatio = newRatio;
}
function setLpFeeRatio(uint8 newRatio) public {
require(msg.sender == admin, "lp:Call must come from admin.");
require(newRatio >= 0 && newRatio <= 100, "invalid ratio");
lpFeeRatio = newRatio;
}
function setWithdrawInterval(uint256 _blockNum) public {
require(msg.sender == admin, "i:Call must come from admin.");
withdrawInterval = _blockNum;
}
// set sakePerBlock phase II yield farming
function setSakePerBlockYieldFarming(uint256 _sakePerBlockYieldFarming, bool _withUpdate) public {
require(msg.sender == admin, "yield:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockYieldFarming = _sakePerBlockYieldFarming;
}
// set sakePerBlock trade mining
function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
} | // SakeMaster is the master of Sake. He can make Sake and he is a fair guy.
//
// Note that it's ownable and the owner wields tremendous power. The ownership
// will be transferred to a governance smart contract once SAKE is sufficiently
// distributed and the community can show to govern itself.
//
// Have fun reading it. Hopefully it's bug-free. God bless. | LineComment | setSakePerBlockTradeMining | function setSakePerBlockTradeMining(uint256 _sakePerBlockTradeMining, bool _withUpdate) public {
require(msg.sender == admin, "trade:Call must come from admin.");
if (_withUpdate) {
massUpdatePools();
}
sakePerBlockTradeMining = _sakePerBlockTradeMining;
}
| // set sakePerBlock trade mining | LineComment | v0.6.12+commit.27d51765 | None | ipfs://5d4700996a40376e16d7d09f63c9d6b8ef633b28dd8203c5297833f9286dce20 | {
"func_code_index": [
20820,
21135
]
} | 3,866 |
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
286,
639
]
} | 3,867 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public constant returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
859,
983
]
} | 3,868 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
411,
897
]
} | 3,869 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
1541,
1747
]
} | 3,870 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
2083,
2236
]
} | 3,871 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
2493,
2782
]
} | 3,872 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
return allowed[_owner][_spender];
}
/**
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
*/
function increaseApproval (address _spender, uint _addedValue) public returns (bool success) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | decreaseApproval | function decreaseApproval (address _spender, uint _subtractedValue) public returns (bool success) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
3265,
3724
]
} | 3,873 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | Ownable | function Ownable() {
owner = msg.sender;
}
| /**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
267,
328
]
} | 3,874 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | Ownable | contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
} | /**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
| /**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
673,
865
]
} | 3,875 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | Pausable | contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | pause | function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
| /**
* @dev called by the owner to pause, triggers stopped state
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
557,
660
]
} | 3,876 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | Pausable | contract Pausable is Ownable {
event Pause();
event Unpause();
bool public paused = false;
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*/
modifier whenNotPaused() {
require(!paused);
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*/
modifier whenPaused() {
require(paused);
_;
}
/**
* @dev called by the owner to pause, triggers stopped state
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
}
/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
} | /**
* @title Pausable
* @dev Base contract which allows children to implement an emergency stop mechanism.
*/ | NatSpecMultiLine | unpause | function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
}
| /**
* @dev called by the owner to unpause, returns to normal state
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
750,
855
]
} | 3,877 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | UnionChain | contract UnionChain is StandardToken, Pausable {
string public constant name = 'Union Chain';
string public constant symbol = 'UNC';
uint8 public constant decimals = 6;
uint256 public constant INITIAL_SUPPLY = 100000000 * 10**uint256(decimals);
/**
* @dev SesnseToken Constructor
* Runs only on initial contract creation.
*/
function UnionChain() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
/**
* @dev Transfer token for a specified address when not paused
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transfer(_to, _value);
}
/**
* @dev Transfer tokens from one address to another when not paused
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transferFrom(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender when not paused.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
} | /**
* @title UnionChain
* @dev ERC20 UnionChain (UNC)
*/ | NatSpecMultiLine | UnionChain | function UnionChain() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
| /**
* @dev SesnseToken Constructor
* Runs only on initial contract creation.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
371,
545
]
} | 3,878 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | UnionChain | contract UnionChain is StandardToken, Pausable {
string public constant name = 'Union Chain';
string public constant symbol = 'UNC';
uint8 public constant decimals = 6;
uint256 public constant INITIAL_SUPPLY = 100000000 * 10**uint256(decimals);
/**
* @dev SesnseToken Constructor
* Runs only on initial contract creation.
*/
function UnionChain() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
/**
* @dev Transfer token for a specified address when not paused
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transfer(_to, _value);
}
/**
* @dev Transfer tokens from one address to another when not paused
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transferFrom(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender when not paused.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
} | /**
* @title UnionChain
* @dev ERC20 UnionChain (UNC)
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transfer(_to, _value);
}
| /**
* @dev Transfer token for a specified address when not paused
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
733,
904
]
} | 3,879 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | UnionChain | contract UnionChain is StandardToken, Pausable {
string public constant name = 'Union Chain';
string public constant symbol = 'UNC';
uint8 public constant decimals = 6;
uint256 public constant INITIAL_SUPPLY = 100000000 * 10**uint256(decimals);
/**
* @dev SesnseToken Constructor
* Runs only on initial contract creation.
*/
function UnionChain() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
/**
* @dev Transfer token for a specified address when not paused
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transfer(_to, _value);
}
/**
* @dev Transfer tokens from one address to another when not paused
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transferFrom(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender when not paused.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
} | /**
* @title UnionChain
* @dev ERC20 UnionChain (UNC)
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transferFrom(_from, _to, _value);
}
| /**
* @dev Transfer tokens from one address to another when not paused
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
1212,
1413
]
} | 3,880 |
|
UnionChain | UnionChain.sol | 0x83116523962c3f3fdd9812fd097ba7ab75d8f9c4 | Solidity | UnionChain | contract UnionChain is StandardToken, Pausable {
string public constant name = 'Union Chain';
string public constant symbol = 'UNC';
uint8 public constant decimals = 6;
uint256 public constant INITIAL_SUPPLY = 100000000 * 10**uint256(decimals);
/**
* @dev SesnseToken Constructor
* Runs only on initial contract creation.
*/
function UnionChain() {
totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
/**
* @dev Transfer token for a specified address when not paused
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transfer(_to, _value);
}
/**
* @dev Transfer tokens from one address to another when not paused
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) whenNotPaused returns (bool) {
require(_to != address(0));
return super.transferFrom(_from, _to, _value);
}
/**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender when not paused.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
} | /**
* @title UnionChain
* @dev ERC20 UnionChain (UNC)
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) whenNotPaused returns (bool) {
return super.approve(_spender, _value);
}
| /**
* @dev Aprove the passed address to spend the specified amount of tokens on behalf of msg.sender when not paused.
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.13+commit.fb4cb1a | bzzr://c690bad62524d4fc86e43b5d20ea7a69ac99c9cc3d0f0028ebd0852bf9ea8855 | {
"func_code_index": [
1674,
1816
]
} | 3,881 |
|
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
| /**
* @dev Multiplies two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
89,
272
]
} | 3,882 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Integer division of two numbers, truncating the quotient.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
356,
629
]
} | 3,883 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
| /**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
744,
860
]
} | 3,884 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | SafeMath | library SafeMath {
/**
* @dev Multiplies two numbers, throws on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers, truncating the quotient.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
/**
* @dev Adds two numbers, throws on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
} | /**
* @title SafeMath
* @dev Math operations with safety checks that throw on error
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
| /**
* @dev Adds two numbers, throws on overflow.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
924,
1060
]
} | 3,885 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() public view returns (uint256) {
return totalSupply_;
}
| /**
* @dev total number of tokens in existence
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
199,
287
]
} | 3,886 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | transfer | function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
| /**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
445,
841
]
} | 3,887 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | BasicToken | contract BasicToken is ERC20Basic {
using SafeMath for uint256;
mapping(address => uint256) balances;
uint256 totalSupply_;
/**
* @dev total number of tokens in existence
*/
function totalSupply() public view returns (uint256) {
return totalSupply_;
}
/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
* @param _value The amount to be transferred.
*/
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
emit Transfer(msg.sender, _to, _value);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
} | /**
* @title Basic token
* @dev Basic version of StandardToken, with no allowances.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
| /**
* @dev Gets the balance of the specified address.
* @param _owner The address to query the the balance of.
* @return An uint256 representing the amount owned by the passed address.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
1047,
1159
]
} | 3,888 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
| /**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
401,
858
]
} | 3,889 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | approve | function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
| /**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
1490,
1751
]
} | 3,890 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | allowance | function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
| /**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
2075,
2206
]
} | 3,891 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | increaseApproval | function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
2672,
2941
]
} | 3,892 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | StandardToken | contract StandardToken is ERC20, BasicToken {
mapping (address => mapping (address => uint256)) internal allowed;
/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
* @param _to address The address which you want to transfer to
* @param _value uint256 the amount of tokens to be transferred
*/
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
emit Transfer(_from, _to, _value);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
*
* Beware that changing an allowance with this method brings the risk that someone may use both the old
* and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
* race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
* @param _spender The address which will spend the funds.
* @param _value The amount of tokens to be spent.
*/
function approve(address _spender, uint256 _value) public returns (bool) {
require((_value == 0) || allowed[msg.sender][_spender]== 0);
allowed[msg.sender][_spender] = _value;
emit Approval(msg.sender, _spender, _value);
return true;
}
/**
* @dev Function to check the amount of tokens that an owner allowed to a spender.
* @param _owner address The address which owns the funds.
* @param _spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address _owner, address _spender) public view returns (uint256) {
return allowed[_owner][_spender];
}
/**
* @dev Increase the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To increment
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _addedValue The amount of tokens to increase the allowance by.
*/
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
/**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
} | /**
* @title Standard ERC20 token
*
* @dev Implementation of the basic standard token.
* @dev https://github.com/ethereum/EIPs/issues/20
* @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
*/ | NatSpecMultiLine | decreaseApproval | function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
emit Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
| /**
* @dev Decrease the amount of tokens that an owner allowed to a spender.
*
* approve should be called when allowed[_spender] == 0. To decrement
* allowed value is better to use this function to avoid 2 calls (and wait until
* the first transaction is mined)
* From MonolithDAO Token.sol
* @param _spender The address which will spend the funds.
* @param _subtractedValue The amount of tokens to decrease the allowance by.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
3412,
3827
]
} | 3,893 |
PtcToken | PtcToken.sol | 0x8a8cfb9cd03da7c88f21a7836d0edbcdf5055188 | Solidity | PtcToken | contract PtcToken is StandardToken {
string public constant name = "PatEx"; // solium-disable-line uppercase
string public constant symbol = "PTC"; // solium-disable-line uppercase
uint8 public constant decimals = 18; // solium-disable-line uppercase
uint256 public constant INITIAL_SUPPLY = 49*(10 ** 8) * (10 ** uint256(decimals));
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
function PtcToken() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
emit Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
} | /**
* @title SimpleToken
* @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `StandardToken` functions.
*/ | NatSpecMultiLine | PtcToken | function PtcToken() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
emit Transfer(0x0, msg.sender, INITIAL_SUPPLY);
}
| /**
* @dev Constructor that gives msg.sender all of existing tokens.
*/ | NatSpecMultiLine | v0.4.21+commit.dfe3193c | None | bzzr://ce57b47b5b4f8a4ee4a7af103f10bd80247af3bc54288ecfe226b0a9d3e39427 | {
"func_code_index": [
448,
633
]
} | 3,894 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
94,
154
]
} | 3,895 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
237,
310
]
} | 3,896 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
534,
616
]
} | 3,897 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
895,
983
]
} | 3,898 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
1647,
1726
]
} | 3,899 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | IERC20 | interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
} | /**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/ | NatSpecMultiLine | transferFrom | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
2039,
2141
]
} | 3,900 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | add | function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
| /**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
259,
445
]
} | 3,901 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
723,
864
]
} | 3,902 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
1162,
1359
]
} | 3,903 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
1613,
2089
]
} | 3,904 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
2560,
2697
]
} | 3,905 |
Proposal | Proposal.sol | 0x706f53175d91cf03381e31df39728c6bac352f2c | Solidity | SafeMath | library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | /**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/ | NatSpecMultiLine | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division 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 Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.5.15+commit.6a57276f | GNU GPLv3 | bzzr://e9694d5d6ccdcfcb104da2e9f5a2c114de30049a1a75c3f378ac1116666957cd | {
"func_code_index": [
3188,
3471
]
} | 3,906 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.