g8keepToken
g8keepToken
Inherits: Ownable
An ERC20 implementation for the g8keep platform.
Key features of g8keepToken include:
Fee collection for deployers and guardrails for traders.
Fees may only be lowered by the deployer, never raised.
Automated snipe protection with a linear release of tokens without snipe penalties and exponential increase of penalty based on the purchase amount.
State Variables
name
Name of the token.
symbol
Symbol of the token.
decimals
Token decimals.
totalSupply
Total supply of the token.
G8KEEP
g8keep factory address to deposit g8keep fees.
PENALTY_TAX_RECEIVER
Address that will receive penalty taxes.
UNISWAP_V2_PAIR
Address of the Uniswap V2 pair.
PAIRED_TOKEN
Address of the paired token.
BPS
Constant value for BPS.
MAX_DEPLOYER_RESERVE
Constant value for the maximum deployer reserve of total supply in BPS.
GENESIS_TIME
Timestamp of the token deployment - used for calculating snipe protection.
SNIPE_PENALTY_BASE_EXPONENT
The base penalty exponent for snipe protection.
SNIPE_PROTECTION_SECONDS
Amount of time in seconds that snipe protection is enabled for.
SNIPE_PROTECTION_END
Timestamp of when snipe protection for the token ends.
SNIPE_PROTECTION_HEAVY_EXPONENT_START
Starting exponent for heavy snipe penalties.
SNIPE_PROTECTION_HEAVY_PENALTY_SECONDS
Amount of time in seconds that heavy snipe penalties are enabled for.
G8KEEP_FEE
Fee in BPS assessed by g8keep for trades.
buyFee
Fee in BPS assessed by the deployer for buys.
sellFee
Fee in BPS assessed by the deployer for sells.
treasuryWallet
Address that will receive deployer trading fees.
_balances
Mapping of token balances for token owners.
_allowances
Mapping of spender approvals.
lpBalanceBaseline
Baseline balance of the LP - used for calculating snipe protection.
lastLPTotalSupply
Amount of LP token total supply last recorded - used for calculating thirdPartyLPAmount
.
thirdPartyLPAmount
Amount of token added to the LP by third parties.
cachedLPReserve1
Cached value of the LP token reserve - used for calculating thirdPartyLPAmount
.
Functions
constructor
Constructs the g8keep token.
Parameters
maxSnipeProtectionBuyWithoutPenalty
Calculates the amount of tokens that may be purchased without a snipe protection penalty.
Returns
expectedAmount1Out
Calculates the expected output amounts to buyer, penalty and fees for the amount0In
, accounts for snipe protection penalties and current fee settings.
Parameters
Returns
balanceOf
Returns the token balance of account
.
Parameters
Returns
allowance
Returns the amount owner
has authorized spender
to transfer.
An allowance of type(uint256).max
is considered an unlimited allowance.
Parameters
Returns
approve
Sets the allowed amount that spender
may transfer on behalf of the caller.
An amount
of type(uint256).max
is considered an unlimited allowance.
Parameters
transfer
Transfers amount
of tokens from the caller to recipient
.
Parameters
transferFrom
Transfers amount
of tokens from sender
to recipient
if the caller has a sufficient allowance set by sender
.
Parameters
updateTreasuryWallet
Admin function for the token owner to set a new treasury wallet to receive fees.
The address may not be set to the zero address or the Uniswap V2 Pair.
Parameters
updateFees
Admin function for the token owner to set new buy and sell fees.
The buy and sell fees may not be set higher than the current fees.
Parameters
withdrawToken
Admin function for the token owner to recover tokens mistakenly sent to the token contract.
Will withdraw the entire balance of the token.
Parameters
withdrawToken
Admin function for the token owner to recover tokens mistakenly sent to the token contract.
Will withdraw the specified amount
of token.
Parameters
_approve
Internal function to handle approvals.
Updates the _allowances
mapping and emits an Approval
event.
Parameters
_transfer
Internal function to handle transfers.
Adjusts amount
based on snipe protection calculations while enabled.
Applies fees when the transfer is going to or coming from the Uniswap V2 Pair.
Updates the _balances
mapping for from
and to
and emits a Transfer
event.
Parameters
_applyFees
Internal function to apply buy and sell fees.
Updates the _balances
mapping for _treasuryWallet
and G8KEEP
and emits Transfer
events if their calculated fees are greater than zero.
Parameters
Returns
_applySnipeProtection
Internal function to check if snipe protection is enabled and adjust the output amount if it is and the amount
exceeds the maximum buy without a snipe penalty.
Parameters
_checkLPForIncrease
Internal function used during snipe protection to determine if tokens have been added to the LP by a third party so that snipe protection can be applied appropriately.
Returns the LP reserves for use in _adjustAmountOut
for efficiency.
Returns the third party LP amount for use in _adjustAmountOut
for efficiency.
Returns
_checkLPForIncreaseView
Internal function used in view functions to determine if tokens have been added to the LP by a third party so that snipe protection calculations can be applied appropriately.
Returns the LP reserves for use in _adjustAmountOut
for efficiency.
Returns the third party LP amount for use in _adjustAmountOut
for efficiency.
Returns
_adjustAmountOut
Internal function to adjust the amount of tokens being purchased from the Uniswap V2 Pair during snipe protection when the purchase amount exceeds the maximum amount that can be purchased without a penalty.
Tokens are released for purchase without snipe protection penalty linearly during the snipe protection window and penalties increase exponentially when exceeding the expected balance of the Uniswap V2 Pair.
For example:
A token with 100,000 tokens in the initial LP and snipe protection timeof 60 minutes will have 25,000 tokens available to purchase without penalty after the token has been deployed for 15 minutes for an expected LP balance of 75,000 tokens.
A buyer that attempts to purchase 62,500 tokens would result in a 37,500 token balance in the LP which is 50% of expected balance.
Their adjustedAmount1Out would equal 62,500 * 0.5^2 = 15,625 tokens (75% penalty).
Instead of attempting to buy 62,500 tokens, the user should buy the 25,000 tokens that are available without snipe protection to avoid penalty.
Within the regular snipe protection window there is also a heavy penalty window. During the heavy penalty window the exponent for applying the penalty starts at a higher value and decreases linearly until it reaches the base exponent of 2.
For example:
Using the example from above with a heavy snipe window of 10 minutes and a starting penalty exponent of 12. After 6 minutes, there will be 10,000 tokens available to purchase, expected balance 90,000 tokens, and the snipe penalty exponent will be 6.
A buyer that attempts to purchase 55,000 tokens would result in a 45,000 token balance in the LP which is 50% of the expected balance.
Their adjustedAmount1Out would equal 55,000 * 0.5^6 = 859.375 tokens (98.5% penalty).
Instead of attempting to purchase 55,0000 tokens, the user should buy the 10,000 tokens that are available without snipe protection to avoid penalty.
Parameters
Returns
_getTokenReserves
Internal function to get the token reserve balances from the Uniswap V2 Pair.
Returns
_getAmountOut
Internal function to calculate the amount of tokens expected to be received from a purchase with amountIn
. This is the same formula used by the Uniswap V2 Router when calculating output amount.
Parameters
Returns
Events
Approval
Emitted when an approval is updated.
DeployerFeesUpdated
Emitted when deployer fees are updated.
Transfer
Emitted when a token balance is transfered.
TreasuryWalletUpdated
Emitted when the treasury wallet is updated.
Errors
CannotBurnLiquidityDuringSnipeProtection
Thrown when attempting to burn an LP position during snipe protection.
CannotIncreaseFees
Thrown when deployer attempts to set fees higher than the current settings.
CannotTransferFromAndToUniswapV2Pair
Thrown when attempting to transfer tokens from and to the Uniswap V2 Pair.
ExcessiveAmountOut
Thrown when the transfer amount on a buy exceeds the value the Uniswap V2 Router calculates.
InsufficientAllowance
Thrown when the spender does not have a sufficient allowance for the transfer being made.
InsufficientBalance
Thrown when a transfer amount exceeds the sender's balance.
InsufficientPoolInput
Thrown during snipe protection when purchasing tokens and the paired token balance decreases.
InvalidHeavySnipeParameters
Thrown during deployment if the heavy snipe exponent exceeds type(uint8).max or is less than the base snipe exponent.
InvalidReserves
Thrown when calculating maximum amount out and the reserve balances are zero.
InvalidTokenAddress
Thrown during deployment if the token address is not greater than the paired token address.
ReserveExceedsMax
Thrown during deployment if the deployer requests a deployer reserve greater than the maximum setting.
SnipeProtectionTimeOverflow
Thrown during deployment if the snipe protection time will overflow a uint40 value.
InvalidTreasuryAddress
Thrown when attempting to set the treasury wallet address to the zero address or the Uniswap V2 pair.
SupplyExceedsMax
Thrown during deployment if the supply exceeds the maximum allowed by Uniswap V2.
ZeroAddress
Thrown when setting an approval or attempting to transfer tokens to the zero address.
Last updated