¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.8.19+commit.7dd6d404
Idioma
Solidity
Ethereum
1,3 gwei
¡El código fuente de este contrato está verificado!
Metadatos del Contrato
Compilador
0.7.0+commit.9e61f92b
Idioma
Solidity
Código Fuente del Contrato
Archivo 1 de 10: Context.sol
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (addresspayable) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
Código Fuente del Contrato
Archivo 2 de 10: IERC165.sol
pragmasolidity ^0.7.0;/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/interfaceIERC165{
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/functionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Código Fuente del Contrato
Archivo 3 de 10: IERC20.sol
pragmasolidity ^0.7.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (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.
*/functiontransfer(address recipient, uint256 amount) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (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.
*/functionapprove(address spender, uint256 amount) externalreturns (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.
*/functiontransferFrom(address sender, address recipient, uint256 amount) externalreturns (bool);
/**
* TODO: Add comment
*/functionburn(uint256 burnQuantity) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
}
Código Fuente del Contrato
Archivo 4 de 10: IERC721.sol
import"./ERC165/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/interfaceIERC721isIERC165{
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/eventApproval(addressindexed owner, addressindexed approved, uint256indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/eventApprovalForAll(addressindexed owner, addressindexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/functionbalanceOf(address owner) externalviewreturns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functionownerOf(uint256 tokenId) externalviewreturns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/functionapprove(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/functiongetApproved(uint256 tokenId) externalviewreturns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/functionsetApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/functionisApprovedForAll(address owner, address operator) externalviewreturns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/functionsafeTransferFrom(addressfrom, address to, uint256 tokenId, bytescalldata data) external;
}
Código Fuente del Contrato
Archivo 5 de 10: IERC721Enumerable.sol
import"./IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/interfaceIERC721EnumerableisIERC721{
/**
* @dev Returns the total amount of tokens stored by the contract.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/functiontokenOfOwnerByIndex(address owner, uint256 index) externalviewreturns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/functiontokenByIndex(uint256 index) externalviewreturns (uint256);
}
pragmasolidity ^0.7.0;import"./Context.sol";
contractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewreturns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
emit OwnershipTransferred(_owner, address(0));
_owner =address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
Código Fuente del Contrato
Archivo 9 de 10: SFT.sol
pragmasolidity ^0.7.0;import"./ERC165/IERC165.sol";
import"./utils/SafeMath.sol";
import"./IERC20.sol";
import"./ISFT.sol";
import"./IFaces.sol";
import"./utils/Context.sol";
import"./utils/Ownable.sol";
/**
*
* SFT Contract (The native token of SatoshiFaces)
* @dev Extends standard ERC20 contract
*/contractSFTisContext, Ownable, ISFT{
usingSafeMathforuint256;
// Constantsuint256publicconstant SECONDS_IN_A_DAY =86400;
uint256publicconstant SECONDS_IN_A_YEAR = SECONDS_IN_A_DAY *365;
uint256publicconstant INITIAL_ALLOTMENT =500* (10**18);
// Public variablesuint256publicconstant EMISSION_START =1617667200; // Tuesday, April 6, 2021 0:00:00 GMTuint256publicconstant EMISSION_END = EMISSION_START + (SECONDS_IN_A_YEAR *10); // 10 years// emission rate decreases with a reduction factor of 0.75 per yearuint256publicconstant EMISSION_PER_DAY_YEAR_0 =5.00* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_1 =3.75* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_2 =2.81* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_3 =2.11* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_4 =1.58* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_5 =1.19* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_6 =0.89* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_7 =0.67* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_8 =0.50* (10**18);
uint256publicconstant EMISSION_PER_DAY_YEAR_9 =0.36* (10**18);
uint256[10] public EMISSION_PER_DAY_YEARS = [ EMISSION_PER_DAY_YEAR_0,
EMISSION_PER_DAY_YEAR_1,
EMISSION_PER_DAY_YEAR_2,
EMISSION_PER_DAY_YEAR_3,
EMISSION_PER_DAY_YEAR_4,
EMISSION_PER_DAY_YEAR_5,
EMISSION_PER_DAY_YEAR_6,
EMISSION_PER_DAY_YEAR_7,
EMISSION_PER_DAY_YEAR_8,
EMISSION_PER_DAY_YEAR_9];
mapping (address=>uint256) private _balances;
mapping (address=>mapping (address=>uint256)) private _allowances;
mapping(uint256=>uint256) private _lastClaim;
mapping(uint256=>uint256) private _claimedAmount;
uint256private _totalSupply;
stringprivate _name;
stringprivate _symbol;
uint8private _decimals;
addressprivate _facesAddress;
addressprivate _addonsAddress;
/**
* @dev Sets the values for {name} and {symbol}, initializes {decimals} with
* a default value of 18.
*
* To select a different value for {decimals}, use {_setupDecimals}.
*
* All three of these values are immutable: they can only be set once during
* construction.
*/constructor () {
_name ="SatoshiFinanceToken";
_symbol ="SFT";
_decimals =18;
}
/**
* @dev Returns the name of the token.
*/functionname() publicviewreturns (stringmemory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/functionsymbol() publicviewreturns (stringmemory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
* called.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/functiondecimals() publicviewreturns (uint8) {
return _decimals;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewoverridereturns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewoverridereturns (uint256) {
return _balances[account];
}
/**
* @dev When accumulated SFTs have last been claimed for a SatoshiFaces index
*/functionlastClaim(uint256 tokenIndex) publicviewreturns (uint256) {
require(IFaces(_facesAddress).ownerOf(tokenIndex) !=address(0), "Owner cannot be 0 address");
require(tokenIndex < IFaces(_facesAddress).totalSupply(), "NFT at index has not been minted yet");
uint256 lastClaimed =uint256(_lastClaim[tokenIndex]) !=0 ? uint256(_lastClaim[tokenIndex]) : EMISSION_START;
return lastClaimed;
}
/**
* @dev Total accumulated SFT tokens for all existing SatoshiFace NFTs.
*/functiontotalAccumulatedSupply() publicviewoverridereturns (uint256) {
require(block.timestamp> EMISSION_START, "Emission has not started yet");
require(IFaces(_facesAddress).ownerOf(0) !=address(0), "Owner of NFT #0 cannot be 0 address");
require(0< IFaces(_facesAddress).totalSupply(), "No NFTs have been minted yet");
uint256 nftSupply = IFaces(_facesAddress).totalSupply();
return nftSupply.mul(totalAccumulated(0));
}
/**
* @dev Accumulated SFT tokens for a SatoshiFaces token index.
*/functionaccumulated(uint256 tokenIndex) publicviewoverridereturns (uint256) {
require(block.timestamp> EMISSION_START, "Emission has not started yet");
require(IFaces(_facesAddress).ownerOf(tokenIndex) !=address(0), "Owner cannot be 0 address");
require(tokenIndex < IFaces(_facesAddress).totalSupply(), "NFT at index has not been minted yet");
uint256 lastClaimed = lastClaim(tokenIndex);
// sanity check if last claim was on or after emission endif (lastClaimed >= EMISSION_END) return0;
uint256 accumulatedQty = totalAccumulated(tokenIndex).sub(totalClaimed(tokenIndex));
return accumulatedQty;
}
/**
* @dev Lifetime Accumulated SFT tokens for a SatoshiFaces token index.
*/functiontotalAccumulated(uint256 tokenIndex) publicviewoverridereturns (uint256) {
require(block.timestamp> EMISSION_START, "Emission has not started yet");
require(IFaces(_facesAddress).ownerOf(tokenIndex) !=address(0), "Owner cannot be 0 address");
require(tokenIndex < IFaces(_facesAddress).totalSupply(), "NFT at index has not been minted yet");
uint256 nowTime =block.timestamp< EMISSION_END ? block.timestamp : EMISSION_END;
uint256 elapsedTime = nowTime.sub(EMISSION_START);
uint256 yearsElapsed = elapsedTime.div(SECONDS_IN_A_YEAR);
uint256 totalAmountAccumulated =0;
uint256 timeAccountedFor =0;
// amount accumulated in each yearfor(uint year =0; year < yearsElapsed; year++) {
uint256 emissionPerDayForYear = EMISSION_PER_DAY_YEARS[year];
uint256 yearAccumulated = emissionPerDayForYear.mul(365);
totalAmountAccumulated = totalAmountAccumulated.add(yearAccumulated);
timeAccountedFor = timeAccountedFor.add(SECONDS_IN_A_YEAR);
}
// amount accumulated since last full yearif(elapsedTime > timeAccountedFor && yearsElapsed <10) {
uint256 remainingTime = elapsedTime.sub(timeAccountedFor);
uint256 currentEmissionRate = EMISSION_PER_DAY_YEARS[yearsElapsed];
uint256 remainingAccumulated = remainingTime.mul(currentEmissionRate).div(SECONDS_IN_A_DAY);
totalAmountAccumulated = totalAmountAccumulated.add(remainingAccumulated);
}
// add initial allotment
totalAmountAccumulated = totalAmountAccumulated.add(INITIAL_ALLOTMENT);
return totalAmountAccumulated;
}
/**
* @dev Lifetime SFT tokens claimed from a token index SatoshiFaces NFT
*/functiontotalClaimed(uint256 tokenIndex) publicviewoverridereturns (uint256) {
require(IFaces(_facesAddress).ownerOf(tokenIndex) !=address(0), "Owner cannot be 0 address");
require(tokenIndex < IFaces(_facesAddress).totalSupply(), "NFT at index has not been minted yet");
uint256 claimed =uint256(_claimedAmount[tokenIndex]) >=0 ? uint256(_claimedAmount[tokenIndex]) : 0;
return claimed;
}
/**
* @dev Set right after deployment and verified
*/functionsetFacesAddress(address facesAddress) onlyOwnerpublic{
require(_facesAddress ==address(0), "Already set");
_facesAddress = facesAddress;
}
/**
* @dev To be set at a later date when the platform is developed
*/functionsetAddonsAddress(address addonsAddress) onlyOwnerpublic{
_addonsAddress = addonsAddress;
}
/**
* @dev Claim mints SFTs and supports multiple SatoshiFaces token indices at once.
*/functionclaim(uint256[] memory tokenIndices) publicreturns (uint256) {
require(block.timestamp> EMISSION_START, "Emission has not started yet");
uint256 totalClaimQty =0;
for (uint i =0; i < tokenIndices.length; i++) {
// Sanity check for non-minted indexrequire(tokenIndices[i] < IFaces(_facesAddress).totalSupply(), "NFT at index has not been minted yet");
// Duplicate token index checkfor (uint j = i +1; j < tokenIndices.length; j++) {
require(tokenIndices[i] != tokenIndices[j], "Duplicate token index");
}
uint tokenIndex = tokenIndices[i];
require(IFaces(_facesAddress).ownerOf(tokenIndex) ==msg.sender, "Sender is not the owner");
uint256 claimQty = accumulated(tokenIndex);
if (claimQty !=0) {
_lastClaim[tokenIndex] =block.timestamp;
uint256 alreadyClaimed = _claimedAmount[tokenIndex];
_claimedAmount[tokenIndex] = alreadyClaimed.add(claimQty);
totalClaimQty = totalClaimQty.add(claimQty);
}
}
require(totalClaimQty !=0, "No accumulated SFT");
_mint(msg.sender, totalClaimQty);
return totalClaimQty;
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(_msgSender(), recipient, amount);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner, address spender) publicviewvirtualoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
_approve(_msgSender(), spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* Requirements:
*
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
* - the caller must have allowance for ``sender``'s tokens of at least
* `amount`.
*/functiontransferFrom(address sender, address recipient, uint256 amount) publicvirtualoverridereturns (bool) {
_transfer(sender, recipient, amount);
// Approval check is skipped if the caller of transferFrom is the SatoshiFaces or SatoshiFaces Addons contract. For better UX.if (msg.sender== _facesAddress) {
// caller of transferFrom is the SatoshiFaces contract
}
elseif(_addonsAddress !=address(0) &&msg.sender== _addonsAddress) {
// addons contract address is set and caller is from the SatoshiFaces Addons contract
}
else {
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
}
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
returntrue;
}
// ++/**
* @dev Burns a quantity of tokens held by the caller.
*
* Emits an {Transfer} event to 0 address
*
*/functionburn(uint256 burnQuantity) publicvirtualoverridereturns (bool) {
_burn(msg.sender, burnQuantity);
returntrue;
}
// ++/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
returntrue;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/function_transfer(address sender, address recipient, uint256 amount) internalvirtual{
require(sender !=address(0), "ERC20: transfer from the zero address");
require(recipient !=address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `to` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
_balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
_totalSupply = _totalSupply.sub(amount);
emit Transfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner, address spender, uint256 amount) internalvirtual{
require(owner !=address(0), "ERC20: approve from the zero address");
require(spender !=address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Sets {decimals} to a value other than the default one of 18.
*
* WARNING: This function should only be called from the constructor. Most
* applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does.
*/function_setupDecimals(uint8 decimals_) internal{
_decimals = decimals_;
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be to transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom, address to, uint256 amount) internalvirtual{ }
}
Código Fuente del Contrato
Archivo 10 de 10: SafeMath.sol
pragmasolidity ^0.7.0;/**
* @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.
*/librarySafeMath{
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (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.
*/functionsub(uint256 a, uint256 b) internalpurereturns (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.
*/functionsub(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (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.
*/functionmul(uint256 a, uint256 b) internalpurereturns (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/522if (a ==0) {
return0;
}
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.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (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.
*/functiondiv(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b >0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn 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.
*/functionmod(uint256 a, uint256 b) internalpurereturns (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.
*/functionmod(uint256 a, uint256 b, stringmemory errorMessage) internalpurereturns (uint256) {
require(b !=0, errorMessage);
return a % b;
}
}