// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @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 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 (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 2 of 13: Conviction.sol
/*********************************************************************************
Conviction (CONV)
_ _
(_) _ (_)
____ ___ ____ _ _ _ ____ _| |_ _ ___ ____
/ ___) _ \| _ \ | | | |/ ___|_ _) |/ _ \| _ \
( (__| |_| | | | \ V /| ( (___ | |_| | |_| | | | |
\____)___/|_| |_|\_/ |_|\____) \__)_|\___/|_| |_|
Live your life with conviction. Conviction can catalyze your dreams becoming reality
and determine whether you make it or not. We're here to completely upend the
scene with conviction for the culture by building the biggest
degen ecosystem to ever show it's face in crypto. With CONV's tokenomics,
innovative tapering jeet tax, and buyer incentive lottery program,
you can have a shot at winning massive amounts of ETH every hour. In
conjunction with Chainlink verifiable random functions and a little creativity,
we built an innovative mechanism to reward buyers of CONV and those who
execute the lottery draw function each buy period.
TOKEN DISTRIBUTION
Fixed supply: 1,000,000,000 CONV
100% supply went into the liquidity pool on day 1
- No VCs
- No team tokens
- No funny business
TOKENOMICS
buy: 5% tax
- 2.5% reward pool
- 2.5% auto LP
sell: 5-20% tax (see JEET SELL TAX below)
BUYER INCENTIVE PROGRAM
When you buy CONV you are entered into an hourly lottery drawn by Chainlink VRFs
that will reward 5 buyers who bought during that hour with 20% (4% each) of the current
buyer incentive pool, which is the amount of ETH in the token contract.
Every hour 5 new winners will be drawn, and the pool of buyers will then
reset to be drawn from again for the next hour for buyers during that next hour period.
DRAW THE WINNERS
In order for the winners of the lottery to be drawn, either
`drawWinnerAtPreviousBuyPeriod` or `drawWinnerAt` need to be executed on this contract.
Anyone who wants can execute these functions when a buy period is over and winners have
not been drawn yet. The lottery drawer will be rewarded 2% of the buyer
incentive pool at that point in time.
JEET SELL TAX
We're building something massive: one of the largest decentralized
lottery mechanisms to exist in crypto. In order to support
this vision we want fellow CONVers to hold their CONV or get punished
accordingly. We implemented a tapering sell tax that rewards you by taxing
less the longer you hold your CONV.
At the point you buy, to sell you will be charged 4x the standard tax (20%).
Every hour your sell tax will decrease from 20% all the way down to the standard tax
if you hold for >=72 hours.
See below for an example of how tax is calculated:
Your calculated sell tax amount based on when you sell:
- 0-1 hours after buy: 20%
- 1-2 hour after buy: 19.93%
- 2-3 hours after buy: 19.86%
- 3-4 hours after buy: 19.79%
...
- 72+ hours after buy: 5%
COMMUNITY
Our vision is CONV will become a community-owned, organically grown project. We
want the community and holders to take over, create the website & socials, and
when we grow the dev will reenter the scene for a full DAO build-out to empower the
community to vote on the future of CONV and it's ecosystem.
*********************************************************************************/// SPDX-License-Identifier: Unlicensedpragmasolidity ^0.8.4;import'@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol';
import'@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol';
import'@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol';
import'@openzeppelin/contracts/token/ERC20/ERC20.sol';
import'@openzeppelin/contracts/access/Ownable.sol';
import'@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol';
import'@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import'@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol';
contractConvictionisERC20, Ownable, VRFConsumerBaseV2{
uint256privateconstant ONE_HOUR =60*60;
uint256privateconstant PERCENT_DENOMENATOR =1000;
// FUCK THE JEETSuint256publicconstant JEET_TAX_MULTIPLIER =4;
uint256publicconstant JEET_TAPER_HOURS =72;
VRFCoordinatorV2Interface vrfCoord;
LinkTokenInterface link;
uint64private _vrfSubscriptionId;
bytes32private _vrfKeyHash;
uint32private _vrfCallbackGasLimit =600000;
mapping(uint256=>uint256) private _buyInitiators;
mapping(uint256=>address[]) private _buyWinners;
uint16public numBuyWinners =5;
uint256public percentTreasuryBuyerPool =200; // 20%uint256public percentTreasuryInitiatorPool =20; // 2%addresspayablepublic treasury;
mapping(address=>bool) private _isTaxExcluded;
boolprivate _taxesOff;
uint256private _taxBuyerIncent =25; // 2.5%uint256private _taxLp =25; // 2.5%uint256private _totalTax;
uint256private _liquifyRate =10;
uint256public launchTime;
IUniswapV2Router02 public uniswapV2Router;
addresspublic uniswapV2Pair;
mapping(address=>uint256) private _lastBuy;
uint256public buyDrawSeconds = ONE_HOUR;
mapping(uint256=>address[]) public buyPeriodBuyers;
mapping(uint256=>mapping(address=>bool)) public buyPeriodBuyersIndexed;
mapping(address=>bool) private _isFucker;
address[] private _confirmedFuckers;
uint256private _lastNuke;
uint256private _nukeFreq =60*10;
boolprivate _swapEnabled =true;
boolprivate _swapping =false;
eventInitiatedBuyWinner(uint256indexed requestId,
uint256indexed buyPeriod
);
eventSelectedBuyWinner(uint256indexed requestId, uint256indexed buyPeriod);
modifierlockTheFuckingSwap() {
_swapping =true;
_;
_swapping =false;
}
constructor(address _vrfCoordinator,
uint64 _subscriptionId,
address _linkToken,
bytes32 _keyHash
) ERC20('Conviction', 'CONV') VRFConsumerBaseV2(_vrfCoordinator) {
_mint(address(this), 1_000_000_000*10**18);
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(
address(this),
_uniswapV2Router.WETH()
);
uniswapV2Router = _uniswapV2Router;
_setTotalTax();
_isTaxExcluded[address(this)] =true;
_isTaxExcluded[msg.sender] =true;
vrfCoord = VRFCoordinatorV2Interface(_vrfCoordinator);
link = LinkTokenInterface(_linkToken);
_vrfSubscriptionId = _subscriptionId;
_vrfKeyHash = _keyHash;
}
functionlaunch() externalpayableonlyOwner{
require(launchTime ==0, 'already launched');
require(msg.value>0, 'need ETH for initial LP');
_addLp(totalSupply(), msg.value);
launchTime =block.timestamp;
}
functiongetBuyPeriodWinners(uint256 _period)
externalviewreturns (address[] memory)
{
return _buyWinners[_period];
}
functiondrawWinnerAtPreviousBuyPeriod() external{
uint256 _period = getBuyPeriod() -1;
_drawWinnerAtBuyPeriod(_period);
}
functiondrawWinnerAt(uint256 _period) external{
_drawWinnerAtBuyPeriod(_period);
}
function_drawWinnerAtBuyPeriod(uint256 _period) internal{
require(address(this).balance>0, 'nothing to give winners');
require(getBuyPeriod() > _period, 'buyPeriod is not complete');
require(getAllBuyPeriodBuyerAmount(_period) >0, 'no buyers during period');
uint256 requestId = vrfCoord.requestRandomWords(
_vrfKeyHash,
_vrfSubscriptionId,
uint16(3),
_vrfCallbackGasLimit,
numBuyWinners
);
require(_buyInitiators[requestId] ==0, 'already initiated');
_buyInitiators[requestId] = _period;
uint256 _balanceBefore =address(this).balance;
uint256 _initiatorAmount = (_balanceBefore * percentTreasuryInitiatorPool) /
PERCENT_DENOMENATOR;
payable(msg.sender).call{ value: _initiatorAmount }('');
require(
address(this).balance>= _balanceBefore - _initiatorAmount,
'took too much'
);
emit InitiatedBuyWinner(requestId, _period);
}
functionfulfillRandomWords(uint256 requestId, uint256[] memory randomWords)
internaloverride{
uint256 _period = _buyInitiators[requestId];
uint256 _allBuyerLength = getAllBuyPeriodBuyerAmount(_period);
uint256 _balanceBefore =address(this).balance;
uint256 _amountETHTotal = (_balanceBefore * percentTreasuryBuyerPool) /
PERCENT_DENOMENATOR;
uint256 _amountETHPerWinner = _amountETHTotal / randomWords.length;
for (uint256 i =0; i < randomWords.length; i++) {
uint256 _word = randomWords[i];
uint256 _winnerIdx = _word % _allBuyerLength;
_buyWinners[_period].push(buyPeriodBuyers[_period][_winnerIdx]);
payable(_buyWinners[_period][i]).call{ value: _amountETHPerWinner }('');
}
require(address(this).balance>= _balanceBefore - _amountETHTotal);
emit SelectedBuyWinner(requestId, _period);
}
function_transfer(address sender,
address recipient,
uint256 amount
) internalvirtualoverride{
bool _isOwner = sender == owner() || recipient == owner();
require(
_isOwner || amount <= _maxTx(sender, recipient),
'ERC20: exceed amx txn'
);
require(!_isFucker[recipient], 'Stop fucker!');
require(!_isFucker[sender], 'Stop fucker!');
require(!_isFucker[_msgSender()], 'Stop fucker!');
uint256 contractTokenBalance = balanceOf(address(this));
bool _isBuy = sender == uniswapV2Pair &&
recipient !=address(uniswapV2Router);
bool _isSell = recipient == uniswapV2Pair;
bool _isSwap = _isBuy || _isSell;
if (_isSwap) {
if (block.timestamp== launchTime) {
_isFucker[recipient] =true;
_confirmedFuckers.push(recipient);
}
}
if (_isBuy) {
_lastBuy[recipient] =block.timestamp;
uint256 _period = getBuyPeriod();
if (!buyPeriodBuyersIndexed[_period][recipient]) {
buyPeriodBuyersIndexed[_period][recipient] =true;
buyPeriodBuyers[_period].push(recipient);
}
}
uint256 _minSwap = (balanceOf(uniswapV2Pair) * _liquifyRate) /
PERCENT_DENOMENATOR;
bool _overMin = contractTokenBalance >= _minSwap;
if (
_swapEnabled &&!_swapping &&!_isOwner &&
_overMin &&
launchTime !=0&&
sender != uniswapV2Pair
) {
_swap(_minSwap);
}
uint256 tax =0;
if (
launchTime !=0&&!_taxesOff &&!(_isTaxExcluded[sender] || _isTaxExcluded[recipient])
) {
tax = (amount * _totalTax) / PERCENT_DENOMENATOR;
if (tax >0) {
if (_isSell) {
tax = calculateJeetTax(sender, tax);
}
super._transfer(sender, address(this), tax);
}
}
super._transfer(sender, recipient, amount - tax);
}
functiongetAllBuyPeriodBuyerAmount(uint256 _period)
publicviewreturns (uint256)
{
return buyPeriodBuyers[_period].length;
}
function_maxTx(address sender, address recipient)
privateviewreturns (uint256)
{
bool _isOwner = sender == owner() || recipient == owner();
uint256 expiration =60*15; // 15 minutesif (
_isOwner || launchTime ==0||block.timestamp> launchTime + expiration
) {
return totalSupply();
}
return totalSupply() /100; // 1%
}
function_swap(uint256 contractTokenBalance) privatelockTheFuckingSwap{
uint256 balBefore =address(this).balance;
uint256 liquidityTokens = (contractTokenBalance * _taxLp) / _totalTax /2;
uint256 tokensToSwap = contractTokenBalance - liquidityTokens;
// generate the uniswap pair path of token -> wethaddress[] memory path =newaddress[](2);
path[0] =address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokensToSwap);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokensToSwap,
0,
path,
address(this),
block.timestamp
);
uint256 balToProcess =address(this).balance- balBefore;
if (balToProcess >0) {
_processFees(balToProcess, liquidityTokens);
}
}
function_addLp(uint256 tokenAmount, uint256 ethAmount) private{
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{ value: ethAmount }(
address(this),
tokenAmount,
0,
0,
treasury ==address(0) ? owner() : treasury,
block.timestamp
);
}
function_processFees(uint256 amountETH, uint256 amountLpTokens) private{
uint256 lpETH = (amountETH * _taxLp) / _totalTax;
if (amountLpTokens >0) {
_addLp(amountLpTokens, lpETH);
}
}
function_setTotalTax() private{
_totalTax = _taxBuyerIncent + _taxLp;
require(
_totalTax <= (PERCENT_DENOMENATOR *20) /100,
'tax cannot be above 20%'
);
}
// fuck you jeetsfunctioncalculateJeetTax(address _sender, uint256 _tax)
publicviewreturns (uint256)
{
if (block.timestamp< calculateJeetExpiration(_sender)) {
uint256 _hoursAfterBuy = (block.timestamp- _lastBuy[_sender]) / ONE_HOUR;
return
(_tax * ((JEET_TAX_MULTIPLIER * JEET_TAPER_HOURS) - _hoursAfterBuy)) /
JEET_TAPER_HOURS;
}
return _tax;
}
functioncalculateJeetExpiration(address _sender)
publicviewreturns (uint256)
{
return _lastBuy[_sender] + (JEET_TAPER_HOURS * ONE_HOUR);
}
functiongetBuyPeriod() publicviewreturns (uint256) {
uint256 secondsSinceLaunch =block.timestamp- launchTime;
return1+ (secondsSinceLaunch / buyDrawSeconds);
}
functionisFuckerRemoved(address account) externalviewreturns (bool) {
return _isFucker[account];
}
functionblacklistFucker(address account) externalonlyOwner{
require(
account !=address(uniswapV2Router),
'cannot not blacklist Uniswap'
);
require(!_isFucker[account], 'user is already blacklisted');
_isFucker[account] =true;
_confirmedFuckers.push(account);
}
functionforgiveFucker(address account) externalonlyOwner{
require(_isFucker[account], 'user is not blacklisted');
for (uint256 i =0; i < _confirmedFuckers.length; i++) {
if (_confirmedFuckers[i] == account) {
_confirmedFuckers[i] = _confirmedFuckers[_confirmedFuckers.length-1];
_isFucker[account] =false;
_confirmedFuckers.pop();
break;
}
}
}
functionsetTaxBuyerIncent(uint256 _tax) externalonlyOwner{
_taxBuyerIncent = _tax;
_setTotalTax();
}
functionsetTaxLp(uint256 _tax) externalonlyOwner{
_taxLp = _tax;
_setTotalTax();
}
functionsetTreasury(address _treasury) externalonlyOwner{
treasury =payable(_treasury);
}
functionsetLiquifyRate(uint256 _rate) externalonlyOwner{
require(_rate <= PERCENT_DENOMENATOR /10, 'cannot be more than 10%');
_liquifyRate = _rate;
}
functionsetIsTaxExcluded(address _wallet, bool _isExcluded)
externalonlyOwner{
_isTaxExcluded[_wallet] = _isExcluded;
}
functionsetTaxesOff(bool _areOff) externalonlyOwner{
_taxesOff = _areOff;
}
functionsetSwapEnabled(bool _enabled) externalonlyOwner{
_swapEnabled = _enabled;
}
functionsetNukeFreq(uint256 _seconds) externalonlyOwner{
_nukeFreq = _seconds;
}
functionsetBuyDrawSeconds(uint256 _seconds) externalonlyOwner{
buyDrawSeconds = _seconds;
}
functionsetPercentTreasuryBuyerPool(uint256 _percent) externalonlyOwner{
require(_percent <= PERCENT_DENOMENATOR, 'cannot be more than 100%');
percentTreasuryBuyerPool = _percent;
}
functionsetPercentTreasuryInitiatorPool(uint256 _percent)
externalonlyOwner{
require(
_percent <= (PERCENT_DENOMENATOR *20) /100,
'cannot be more than 20%'
);
percentTreasuryInitiatorPool = _percent;
}
functionsetNumBuyerWinners(uint16 _winners) externalonlyOwner{
require(_winners <=20, 'no more than 20 winners at a time');
numBuyWinners = _winners;
}
functionsetVrfCallbackGasLimit(uint32 _gas) externalonlyOwner{
_vrfCallbackGasLimit = _gas;
}
functionmanualNuke(uint256 _percent, address _to) externalonlyOwner{
require(block.timestamp> _lastNuke + _nukeFreq, 'cooldown please');
require(_percent <= PERCENT_DENOMENATOR /10, 'cannot nuke more than 10%');
_lastNuke =block.timestamp;
uint256 amountToBurn = (balanceOf(uniswapV2Pair) * _percent) /
PERCENT_DENOMENATOR;
if (amountToBurn >0) {
address receiver = _to ==address(0) ? address(0xdead) : _to;
super._transfer(uniswapV2Pair, receiver, amountToBurn);
}
IUniswapV2Pair pair = IUniswapV2Pair(uniswapV2Pair);
pair.sync();
}
functionwithdrawETH() externalonlyOwner{
payable(owner()).call{ value: address(this).balance }('');
}
receive() externalpayable{}
}
Contract Source Code
File 3 of 13: ERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/ERC20.sol)pragmasolidity ^0.8.0;import"./IERC20.sol";
import"./extensions/IERC20Metadata.sol";
import"../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20, IERC20Metadata{
mapping(address=>uint256) private _balances;
mapping(address=>mapping(address=>uint256)) private _allowances;
uint256private _totalSupply;
stringprivate _name;
stringprivate _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_, stringmemory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/functionname() publicviewvirtualoverridereturns (stringmemory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/functionsymbol() publicviewvirtualoverridereturns (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 this function is
* overridden;
*
* 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() publicviewvirtualoverridereturns (uint8) {
return18;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewvirtualoverridereturns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewvirtualoverridereturns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address to, uint256 amount) publicvirtualoverridereturns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner, address spender) publicviewvirtualoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
address owner = _msgSender();
_approve(owner, 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}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) publicvirtualoverridereturns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
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) {
address owner = _msgSender();
_approve(owner, spender, _allowances[owner][spender] + addedValue);
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) {
address owner = _msgSender();
uint256 currentAllowance = _allowances[owner][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
returntrue;
}
/**
* @dev Moves `amount` of tokens from `sender` to `recipient`.
*
* This 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:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/function_transfer(addressfrom,
address to,
uint256 amount
) internalvirtual{
require(from!=address(0), "ERC20: transfer from the zero address");
require(to !=address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
}
_balances[to] += amount;
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, 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:
*
* - `account` 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 += amount;
_balances[account] += amount;
emit Transfer(address(0), account, amount);
_afterTokenTransfer(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);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(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 Spend `amount` form the allowance of `owner` toward `spender`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/function_spendAllowance(address owner,
address spender,
uint256 amount
) internalvirtual{
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance !=type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @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 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{}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been 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_afterTokenTransfer(addressfrom,
address to,
uint256 amount
) internalvirtual{}
}
Contract Source Code
File 4 of 13: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, 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 `from` to `to` 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(addressfrom,
address to,
uint256 amount
) 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);
}
Contract Source Code
File 5 of 13: IERC20Metadata.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)pragmasolidity ^0.8.0;import"../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/interfaceIERC20MetadataisIERC20{
/**
* @dev Returns the name of the token.
*/functionname() externalviewreturns (stringmemory);
/**
* @dev Returns the symbol of the token.
*/functionsymbol() externalviewreturns (stringmemory);
/**
* @dev Returns the decimals places of the token.
*/functiondecimals() externalviewreturns (uint8);
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (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{
_transferOwnership(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");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 12 of 13: VRFConsumerBaseV2.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/** ****************************************************************************
* @notice Interface for contracts using VRF randomness
* *****************************************************************************
* @dev PURPOSE
*
* @dev Reggie the Random Oracle (not his real job) wants to provide randomness
* @dev to Vera the verifier in such a way that Vera can be sure he's not
* @dev making his output up to suit himself. Reggie provides Vera a public key
* @dev to which he knows the secret key. Each time Vera provides a seed to
* @dev Reggie, he gives back a value which is computed completely
* @dev deterministically from the seed and the secret key.
*
* @dev Reggie provides a proof by which Vera can verify that the output was
* @dev correctly computed once Reggie tells it to her, but without that proof,
* @dev the output is indistinguishable to her from a uniform random sample
* @dev from the output space.
*
* @dev The purpose of this contract is to make it easy for unrelated contracts
* @dev to talk to Vera the verifier about the work Reggie is doing, to provide
* @dev simple access to a verifiable source of randomness. It ensures 2 things:
* @dev 1. The fulfillment came from the VRFCoordinator
* @dev 2. The consumer contract implements fulfillRandomWords.
* *****************************************************************************
* @dev USAGE
*
* @dev Calling contracts must inherit from VRFConsumerBase, and can
* @dev initialize VRFConsumerBase's attributes in their constructor as
* @dev shown:
*
* @dev contract VRFConsumer {
* @dev constructor(<other arguments>, address _vrfCoordinator, address _link)
* @dev VRFConsumerBase(_vrfCoordinator) public {
* @dev <initialization with other arguments goes here>
* @dev }
* @dev }
*
* @dev The oracle will have given you an ID for the VRF keypair they have
* @dev committed to (let's call it keyHash). Create subscription, fund it
* @dev and your consumer contract as a consumer of it (see VRFCoordinatorInterface
* @dev subscription management functions).
* @dev Call requestRandomWords(keyHash, subId, minimumRequestConfirmations,
* @dev callbackGasLimit, numWords),
* @dev see (VRFCoordinatorInterface for a description of the arguments).
*
* @dev Once the VRFCoordinator has received and validated the oracle's response
* @dev to your request, it will call your contract's fulfillRandomWords method.
*
* @dev The randomness argument to fulfillRandomWords is a set of random words
* @dev generated from your requestId and the blockHash of the request.
*
* @dev If your contract could have concurrent requests open, you can use the
* @dev requestId returned from requestRandomWords to track which response is associated
* @dev with which randomness request.
* @dev See "SECURITY CONSIDERATIONS" for principles to keep in mind,
* @dev if your contract could have multiple requests in flight simultaneously.
*
* @dev Colliding `requestId`s are cryptographically impossible as long as seeds
* @dev differ.
*
* *****************************************************************************
* @dev SECURITY CONSIDERATIONS
*
* @dev A method with the ability to call your fulfillRandomness method directly
* @dev could spoof a VRF response with any random value, so it's critical that
* @dev it cannot be directly called by anything other than this base contract
* @dev (specifically, by the VRFConsumerBase.rawFulfillRandomness method).
*
* @dev For your users to trust that your contract's random behavior is free
* @dev from malicious interference, it's best if you can write it so that all
* @dev behaviors implied by a VRF response are executed *during* your
* @dev fulfillRandomness method. If your contract must store the response (or
* @dev anything derived from it) and use it later, you must ensure that any
* @dev user-significant behavior which depends on that stored value cannot be
* @dev manipulated by a subsequent VRF request.
*
* @dev Similarly, both miners and the VRF oracle itself have some influence
* @dev over the order in which VRF responses appear on the blockchain, so if
* @dev your contract could have multiple VRF requests in flight simultaneously,
* @dev you must ensure that the order in which the VRF responses arrive cannot
* @dev be used to manipulate your contract's user-significant behavior.
*
* @dev Since the block hash of the block which contains the requestRandomness
* @dev call is mixed into the input to the VRF *last*, a sufficiently powerful
* @dev miner could, in principle, fork the blockchain to evict the block
* @dev containing the request, forcing the request to be included in a
* @dev different block with a different hash, and therefore a different input
* @dev to the VRF. However, such an attack would incur a substantial economic
* @dev cost. This cost scales with the number of blocks the VRF oracle waits
* @dev until it calls responds to a request. It is for this reason that
* @dev that you can signal to an oracle you'd like them to wait longer before
* @dev responding to the request (however this is not enforced in the contract
* @dev and so remains effective only in the case of unmodified oracle software).
*/abstractcontractVRFConsumerBaseV2{
errorOnlyCoordinatorCanFulfill(address have, address want);
addressprivateimmutable vrfCoordinator;
/**
* @param _vrfCoordinator address of VRFCoordinator contract
*/constructor(address _vrfCoordinator) {
vrfCoordinator = _vrfCoordinator;
}
/**
* @notice fulfillRandomness handles the VRF response. Your contract must
* @notice implement it. See "SECURITY CONSIDERATIONS" above for important
* @notice principles to keep in mind when implementing your fulfillRandomness
* @notice method.
*
* @dev VRFConsumerBaseV2 expects its subcontracts to have a method with this
* @dev signature, and will call it once it has verified the proof
* @dev associated with the randomness. (It is triggered via a call to
* @dev rawFulfillRandomness, below.)
*
* @param requestId The Id initially returned by requestRandomness
* @param randomWords the VRF output expanded to the requested number of words
*/functionfulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internalvirtual;
// rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF// proof. rawFulfillRandomness then calls fulfillRandomness, after validating// the origin of the callfunctionrawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external{
if (msg.sender!= vrfCoordinator) {
revert OnlyCoordinatorCanFulfill(msg.sender, vrfCoordinator);
}
fulfillRandomWords(requestId, randomWords);
}
}
Contract Source Code
File 13 of 13: VRFCoordinatorV2Interface.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;interfaceVRFCoordinatorV2Interface{
/**
* @notice Get configuration relevant for making requests
* @return minimumRequestConfirmations global min for request confirmations
* @return maxGasLimit global max for request gas limit
* @return s_provingKeyHashes list of registered key hashes
*/functiongetRequestConfig()
externalviewreturns (uint16,
uint32,
bytes32[] memory);
/**
* @notice Request a set of random words.
* @param keyHash - Corresponds to a particular oracle job which uses
* that key for generating the VRF proof. Different keyHash's have different gas price
* ceilings, so you can select a specific one to bound your maximum per request cost.
* @param subId - The ID of the VRF subscription. Must be funded
* with the minimum subscription balance required for the selected keyHash.
* @param minimumRequestConfirmations - How many blocks you'd like the
* oracle to wait before responding to the request. See SECURITY CONSIDERATIONS
* for why you may want to request more. The acceptable range is
* [minimumRequestBlockConfirmations, 200].
* @param callbackGasLimit - How much gas you'd like to receive in your
* fulfillRandomWords callback. Note that gasleft() inside fulfillRandomWords
* may be slightly less than this amount because of gas used calling the function
* (argument decoding etc.), so you may need to request slightly more than you expect
* to have inside fulfillRandomWords. The acceptable range is
* [0, maxGasLimit]
* @param numWords - The number of uint256 random values you'd like to receive
* in your fulfillRandomWords callback. Note these numbers are expanded in a
* secure way by the VRFCoordinator from a single random value supplied by the oracle.
* @return requestId - A unique identifier of the request. Can be used to match
* a request to a response in fulfillRandomWords.
*/functionrequestRandomWords(bytes32 keyHash,
uint64 subId,
uint16 minimumRequestConfirmations,
uint32 callbackGasLimit,
uint32 numWords
) externalreturns (uint256 requestId);
/**
* @notice Create a VRF subscription.
* @return subId - A unique subscription id.
* @dev You can manage the consumer set dynamically with addConsumer/removeConsumer.
* @dev Note to fund the subscription, use transferAndCall. For example
* @dev LINKTOKEN.transferAndCall(
* @dev address(COORDINATOR),
* @dev amount,
* @dev abi.encode(subId));
*/functioncreateSubscription() externalreturns (uint64 subId);
/**
* @notice Get a VRF subscription.
* @param subId - ID of the subscription
* @return balance - LINK balance of the subscription in juels.
* @return reqCount - number of requests for this subscription, determines fee tier.
* @return owner - owner of the subscription.
* @return consumers - list of consumer address which are able to use this subscription.
*/functiongetSubscription(uint64 subId)
externalviewreturns (uint96 balance,
uint64 reqCount,
address owner,
address[] memory consumers
);
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @param newOwner - proposed new owner of the subscription
*/functionrequestSubscriptionOwnerTransfer(uint64 subId, address newOwner) external;
/**
* @notice Request subscription owner transfer.
* @param subId - ID of the subscription
* @dev will revert if original owner of subId has
* not requested that msg.sender become the new owner.
*/functionacceptSubscriptionOwnerTransfer(uint64 subId) external;
/**
* @notice Add a consumer to a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - New consumer which can use the subscription
*/functionaddConsumer(uint64 subId, address consumer) external;
/**
* @notice Remove a consumer from a VRF subscription.
* @param subId - ID of the subscription
* @param consumer - Consumer to remove from the subscription
*/functionremoveConsumer(uint64 subId, address consumer) external;
/**
* @notice Cancel a subscription
* @param subId - ID of the subscription
* @param to - Where to send the remaining LINK to
*/functioncancelSubscription(uint64 subId, address to) external;
}