├── AFFI-TOKEN-CONTRACT.sol ├── LIQUIDITY-TREASURY.sol ├── LUCKYDROP-CONTRACT.sol ├── README.md └── TRUM-TOKEN-CONTRACT.sol /AFFI-TOKEN-CONTRACT.sol: -------------------------------------------------------------------------------- 1 | /* 2 | ░█████╗░███████╗███████╗██╗    ██╗░██████╗    ░██████╗░█████╗░███████╗██╗░░░██╗ 3 | ██╔══██╗██╔════╝██╔════╝██║    ██║██╔════╝    ██╔════╝██╔══██╗██╔════╝██║░░░██║ 4 | ███████║█████╗░░█████╗░░██║    ██║╚█████╗░    ╚█████╗░███████║█████╗░░██║░░░██║ 5 | ██╔══██║██╔══╝░░██╔══╝░░██║    ██║░╚═══██╗    ░╚═══██╗██╔══██║██╔══╝░░██║░░░██║ 6 | ██║░░██║██║░░░░░██║░░░░░██║    ██║██████╔╝    ██████╔╝██║░░██║██║░░░░░╚██████╔╝ 7 | 8 | ##CONTRACT FEATURES FOR SAFUU 9 | *Owner cant modify tax 10 | *Owner cant mint tokens 11 | *Owner cant recover own token 12 | *Owner cant edit balance 13 | *Owner cant blacklist users 14 | *Owner cant suspend trading 15 | *Owner cant set max wallet or tx amount 16 | *Permanently fixed 9% Buy and Sell tax 17 | */ 18 | 19 | // SPDX-License-Identifier: MIT 20 | 21 | pragma solidity ^0.8.0; 22 | 23 | /** 24 | * @dev Interface of the ERC20 standard as defined in the EIP. 25 | */ 26 | interface IERC20 { 27 | /** 28 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 29 | * another (`to`). 30 | * 31 | * Note that `value` may be zero. 32 | */ 33 | event Transfer(address indexed from, address indexed to, uint256 value); 34 | 35 | /** 36 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 37 | * a call to {approve}. `value` is the new allowance. 38 | */ 39 | event Approval(address indexed owner, address indexed spender, uint256 value); 40 | 41 | /** 42 | * @dev Returns the amount of tokens in existence. 43 | */ 44 | function totalSupply() external view returns (uint256); 45 | 46 | /** 47 | * @dev Returns the amount of tokens owned by `account`. 48 | */ 49 | function balanceOf(address account) external view returns (uint256); 50 | 51 | /** 52 | * @dev Moves `amount` tokens from the caller's account to `to`. 53 | * 54 | * Returns a boolean value indicating whether the operation succeeded. 55 | * 56 | * Emits a {Transfer} event. 57 | */ 58 | function transfer(address to, uint256 amount) external returns (bool); 59 | 60 | /** 61 | * @dev Returns the remaining number of tokens that `spender` will be 62 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 63 | * zero by default. 64 | * 65 | * This value changes when {approve} or {transferFrom} are called. 66 | */ 67 | function allowance(address owner, address spender) external view returns (uint256); 68 | 69 | /** 70 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 71 | * 72 | * Returns a boolean value indicating whether the operation succeeded. 73 | * 74 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 75 | * that someone may use both the old and the new allowance by unfortunate 76 | * transaction ordering. One possible solution to mitigate this race 77 | * condition is to first reduce the spender's allowance to 0 and set the 78 | * desired value afterwards: 79 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 80 | * 81 | * Emits an {Approval} event. 82 | */ 83 | function approve(address spender, uint256 amount) external returns (bool); 84 | 85 | /** 86 | * @dev Moves `amount` tokens from `from` to `to` using the 87 | * allowance mechanism. `amount` is then deducted from the caller's 88 | * allowance. 89 | * 90 | * Returns a boolean value indicating whether the operation succeeded. 91 | * 92 | * Emits a {Transfer} event. 93 | */ 94 | function transferFrom( 95 | address from, 96 | address to, 97 | uint256 amount 98 | ) external returns (bool); 99 | } 100 | 101 | // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol 102 | 103 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) 104 | 105 | pragma solidity ^0.8.0; 106 | 107 | /** 108 | * @dev Interface for the optional metadata functions from the ERC20 standard. 109 | * 110 | * _Available since v4.1._ 111 | */ 112 | interface IERC20Metadata is IERC20 { 113 | /** 114 | * @dev Returns the name of the token. 115 | */ 116 | function name() external view returns (string memory); 117 | 118 | /** 119 | * @dev Returns the symbol of the token. 120 | */ 121 | function symbol() external view returns (string memory); 122 | 123 | /** 124 | * @dev Returns the decimals places of the token. 125 | */ 126 | function decimals() external view returns (uint8); 127 | } 128 | 129 | // File: @openzeppelin/contracts/utils/Context.sol 130 | 131 | // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 132 | 133 | pragma solidity ^0.8.0; 134 | 135 | /** 136 | * @dev Provides information about the current execution context, including the 137 | * sender of the transaction and its data. While these are generally available 138 | * via msg.sender and msg.data, they should not be accessed in such a direct 139 | * manner, since when dealing with meta-transactions the account sending and 140 | * paying for execution may not be the actual sender (as far as an application 141 | * is concerned). 142 | * 143 | * This contract is only required for intermediate, library-like contracts. 144 | */ 145 | abstract contract Context { 146 | function _msgSender() internal view virtual returns (address) { 147 | return msg.sender; 148 | } 149 | 150 | function _msgData() internal view virtual returns (bytes calldata) { 151 | return msg.data; 152 | } 153 | } 154 | 155 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 156 | 157 | // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) 158 | 159 | pragma solidity ^0.8.0; 160 | 161 | 162 | 163 | /** 164 | * @dev Implementation of the {IERC20} interface. 165 | * 166 | * This implementation is agnostic to the way tokens are created. This means 167 | * that a supply mechanism has to be added in a derived contract using {_mint}. 168 | * For a generic mechanism see {ERC20PresetMinterPauser}. 169 | * 170 | * TIP: For a detailed writeup see our guide 171 | * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How 172 | * to implement supply mechanisms]. 173 | * 174 | * We have followed general OpenZeppelin Contracts guidelines: functions revert 175 | * instead returning `false` on failure. This behavior is nonetheless 176 | * conventional and does not conflict with the expectations of ERC20 177 | * applications. 178 | * 179 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 180 | * This allows applications to reconstruct the allowance for all accounts just 181 | * by listening to said events. Other implementations of the EIP may not emit 182 | * these events, as it isn't required by the specification. 183 | * 184 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 185 | * functions have been added to mitigate the well-known issues around setting 186 | * allowances. See {IERC20-approve}. 187 | */ 188 | contract ERC20 is Context, IERC20, IERC20Metadata { 189 | mapping(address => uint256) private _balances; 190 | 191 | mapping(address => mapping(address => uint256)) private _allowances; 192 | 193 | uint256 private _totalSupply; 194 | 195 | string private _name; 196 | string private _symbol; 197 | 198 | /** 199 | * @dev Sets the values for {name} and {symbol}. 200 | * 201 | * The default value of {decimals} is 18. To select a different value for 202 | * {decimals} you should overload it. 203 | * 204 | * All two of these values are immutable: they can only be set once during 205 | * construction. 206 | */ 207 | constructor(string memory name_, string memory symbol_) { 208 | _name = name_; 209 | _symbol = symbol_; 210 | } 211 | 212 | /** 213 | * @dev Returns the name of the token. 214 | */ 215 | function name() public view virtual override returns (string memory) { 216 | return _name; 217 | } 218 | 219 | /** 220 | * @dev Returns the symbol of the token, usually a shorter version of the 221 | * name. 222 | */ 223 | function symbol() public view virtual override returns (string memory) { 224 | return _symbol; 225 | } 226 | 227 | /** 228 | * @dev Returns the number of decimals used to get its user representation. 229 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 230 | * be displayed to a user as `5.05` (`505 / 10 ** 2`). 231 | * 232 | * Tokens usually opt for a value of 18, imitating the relationship between 233 | * Ether and Wei. This is the value {ERC20} uses, unless this function is 234 | * overridden; 235 | * 236 | * NOTE: This information is only used for _display_ purposes: it in 237 | * no way affects any of the arithmetic of the contract, including 238 | * {IERC20-balanceOf} and {IERC20-transfer}. 239 | */ 240 | function decimals() public view virtual override returns (uint8) { 241 | return 18; 242 | } 243 | 244 | /** 245 | * @dev See {IERC20-totalSupply}. 246 | */ 247 | function totalSupply() public view virtual override returns (uint256) { 248 | return _totalSupply; 249 | } 250 | 251 | /** 252 | * @dev See {IERC20-balanceOf}. 253 | */ 254 | function balanceOf(address account) public view virtual override returns (uint256) { 255 | return _balances[account]; 256 | } 257 | 258 | /** 259 | * @dev See {IERC20-transfer}. 260 | * 261 | * Requirements: 262 | * 263 | * - `to` cannot be the zero address. 264 | * - the caller must have a balance of at least `amount`. 265 | */ 266 | function transfer(address to, uint256 amount) public virtual override returns (bool) { 267 | address owner = _msgSender(); 268 | _transfer(owner, to, amount); 269 | return true; 270 | } 271 | 272 | /** 273 | * @dev See {IERC20-allowance}. 274 | */ 275 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 276 | return _allowances[owner][spender]; 277 | } 278 | 279 | /** 280 | * @dev See {IERC20-approve}. 281 | * 282 | * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on 283 | * `transferFrom`. This is semantically equivalent to an infinite approval. 284 | * 285 | * Requirements: 286 | * 287 | * - `spender` cannot be the zero address. 288 | */ 289 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 290 | address owner = _msgSender(); 291 | _approve(owner, spender, amount); 292 | return true; 293 | } 294 | 295 | /** 296 | * @dev See {IERC20-transferFrom}. 297 | * 298 | * Emits an {Approval} event indicating the updated allowance. This is not 299 | * required by the EIP. See the note at the beginning of {ERC20}. 300 | * 301 | * NOTE: Does not update the allowance if the current allowance 302 | * is the maximum `uint256`. 303 | * 304 | * Requirements: 305 | * 306 | * - `from` and `to` cannot be the zero address. 307 | * - `from` must have a balance of at least `amount`. 308 | * - the caller must have allowance for ``from``'s tokens of at least 309 | * `amount`. 310 | */ 311 | function transferFrom( 312 | address from, 313 | address to, 314 | uint256 amount 315 | ) public virtual override returns (bool) { 316 | address spender = _msgSender(); 317 | _spendAllowance(from, spender, amount); 318 | _transfer(from, to, amount); 319 | return true; 320 | } 321 | 322 | /** 323 | * @dev Atomically increases the allowance granted to `spender` by the caller. 324 | * 325 | * This is an alternative to {approve} that can be used as a mitigation for 326 | * problems described in {IERC20-approve}. 327 | * 328 | * Emits an {Approval} event indicating the updated allowance. 329 | * 330 | * Requirements: 331 | * 332 | * - `spender` cannot be the zero address. 333 | */ 334 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 335 | address owner = _msgSender(); 336 | _approve(owner, spender, allowance(owner, spender) + addedValue); 337 | return true; 338 | } 339 | 340 | /** 341 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 342 | * 343 | * This is an alternative to {approve} that can be used as a mitigation for 344 | * problems described in {IERC20-approve}. 345 | * 346 | * Emits an {Approval} event indicating the updated allowance. 347 | * 348 | * Requirements: 349 | * 350 | * - `spender` cannot be the zero address. 351 | * - `spender` must have allowance for the caller of at least 352 | * `subtractedValue`. 353 | */ 354 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 355 | address owner = _msgSender(); 356 | uint256 currentAllowance = allowance(owner, spender); 357 | require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); 358 | unchecked { 359 | _approve(owner, spender, currentAllowance - subtractedValue); 360 | } 361 | 362 | return true; 363 | } 364 | 365 | /** 366 | * @dev Moves `amount` of tokens from `from` to `to`. 367 | * 368 | * This internal function is equivalent to {transfer}, and can be used to 369 | * e.g. implement automatic token fees, slashing mechanisms, etc. 370 | * 371 | * Emits a {Transfer} event. 372 | * 373 | * Requirements: 374 | * 375 | * - `from` cannot be the zero address. 376 | * - `to` cannot be the zero address. 377 | * - `from` must have a balance of at least `amount`. 378 | */ 379 | function _transfer( 380 | address from, 381 | address to, 382 | uint256 amount 383 | ) internal virtual { 384 | require(from != address(0), "ERC20: transfer from the zero address"); 385 | require(to != address(0), "ERC20: transfer to the zero address"); 386 | 387 | _beforeTokenTransfer(from, to, amount); 388 | 389 | uint256 fromBalance = _balances[from]; 390 | require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); 391 | unchecked { 392 | _balances[from] = fromBalance - amount; 393 | // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by 394 | // decrementing then incrementing. 395 | _balances[to] += amount; 396 | } 397 | 398 | emit Transfer(from, to, amount); 399 | 400 | _afterTokenTransfer(from, to, amount); 401 | } 402 | 403 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 404 | * the total supply. 405 | * 406 | * Emits a {Transfer} event with `from` set to the zero address. 407 | * 408 | * Requirements: 409 | * 410 | * - `account` cannot be the zero address. 411 | */ 412 | function _mint(address account, uint256 amount) internal virtual { 413 | require(account != address(0), "ERC20: mint to the zero address"); 414 | 415 | _beforeTokenTransfer(address(0), account, amount); 416 | 417 | _totalSupply += amount; 418 | unchecked { 419 | // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. 420 | _balances[account] += amount; 421 | } 422 | emit Transfer(address(0), account, amount); 423 | 424 | _afterTokenTransfer(address(0), account, amount); 425 | } 426 | 427 | /** 428 | * @dev Destroys `amount` tokens from `account`, reducing the 429 | * total supply. 430 | * 431 | * Emits a {Transfer} event with `to` set to the zero address. 432 | * 433 | * Requirements: 434 | * 435 | * - `account` cannot be the zero address. 436 | * - `account` must have at least `amount` tokens. 437 | */ 438 | function _burn(address account, uint256 amount) internal virtual { 439 | require(account != address(0), "ERC20: burn from the zero address"); 440 | 441 | _beforeTokenTransfer(account, address(0), amount); 442 | 443 | uint256 accountBalance = _balances[account]; 444 | require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); 445 | unchecked { 446 | _balances[account] = accountBalance - amount; 447 | // Overflow not possible: amount <= accountBalance <= totalSupply. 448 | _totalSupply -= amount; 449 | } 450 | 451 | emit Transfer(account, address(0), amount); 452 | 453 | _afterTokenTransfer(account, address(0), amount); 454 | } 455 | 456 | /** 457 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 458 | * 459 | * This internal function is equivalent to `approve`, and can be used to 460 | * e.g. set automatic allowances for certain subsystems, etc. 461 | * 462 | * Emits an {Approval} event. 463 | * 464 | * Requirements: 465 | * 466 | * - `owner` cannot be the zero address. 467 | * - `spender` cannot be the zero address. 468 | */ 469 | function _approve( 470 | address owner, 471 | address spender, 472 | uint256 amount 473 | ) internal virtual { 474 | require(owner != address(0), "ERC20: approve from the zero address"); 475 | require(spender != address(0), "ERC20: approve to the zero address"); 476 | 477 | _allowances[owner][spender] = amount; 478 | emit Approval(owner, spender, amount); 479 | } 480 | 481 | /** 482 | * @dev Updates `owner` s allowance for `spender` based on spent `amount`. 483 | * 484 | * Does not update the allowance amount in case of infinite allowance. 485 | * Revert if not enough allowance is available. 486 | * 487 | * Might emit an {Approval} event. 488 | */ 489 | function _spendAllowance( 490 | address owner, 491 | address spender, 492 | uint256 amount 493 | ) internal virtual { 494 | uint256 currentAllowance = allowance(owner, spender); 495 | if (currentAllowance != type(uint256).max) { 496 | require(currentAllowance >= amount, "ERC20: insufficient allowance"); 497 | unchecked { 498 | _approve(owner, spender, currentAllowance - amount); 499 | } 500 | } 501 | } 502 | 503 | /** 504 | * @dev Hook that is called before any transfer of tokens. This includes 505 | * minting and burning. 506 | * 507 | * Calling conditions: 508 | * 509 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 510 | * will be transferred to `to`. 511 | * - when `from` is zero, `amount` tokens will be minted for `to`. 512 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 513 | * - `from` and `to` are never both zero. 514 | * 515 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 516 | */ 517 | function _beforeTokenTransfer( 518 | address from, 519 | address to, 520 | uint256 amount 521 | ) internal virtual {} 522 | 523 | /** 524 | * @dev Hook that is called after any transfer of tokens. This includes 525 | * minting and burning. 526 | * 527 | * Calling conditions: 528 | * 529 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 530 | * has been transferred to `to`. 531 | * - when `from` is zero, `amount` tokens have been minted for `to`. 532 | * - when `to` is zero, `amount` of ``from``'s tokens have been burned. 533 | * - `from` and `to` are never both zero. 534 | * 535 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 536 | */ 537 | function _afterTokenTransfer( 538 | address from, 539 | address to, 540 | uint256 amount 541 | ) internal virtual {} 542 | } 543 | 544 | // File: @openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol 545 | 546 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) 547 | 548 | pragma solidity ^0.8.0; 549 | 550 | /** 551 | * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in 552 | * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. 553 | * 554 | * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by 555 | * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't 556 | * need to send a transaction, and thus is not required to hold Ether at all. 557 | */ 558 | interface IERC20Permit { 559 | /** 560 | * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, 561 | * given ``owner``'s signed approval. 562 | * 563 | * IMPORTANT: The same issues {IERC20-approve} has related to transaction 564 | * ordering also apply here. 565 | * 566 | * Emits an {Approval} event. 567 | * 568 | * Requirements: 569 | * 570 | * - `spender` cannot be the zero address. 571 | * - `deadline` must be a timestamp in the future. 572 | * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` 573 | * over the EIP712-formatted function arguments. 574 | * - the signature must use ``owner``'s current nonce (see {nonces}). 575 | * 576 | * For more information on the signature format, see the 577 | * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP 578 | * section]. 579 | */ 580 | function permit( 581 | address owner, 582 | address spender, 583 | uint256 value, 584 | uint256 deadline, 585 | uint8 v, 586 | bytes32 r, 587 | bytes32 s 588 | ) external; 589 | 590 | /** 591 | * @dev Returns the current nonce for `owner`. This value must be 592 | * included whenever a signature is generated for {permit}. 593 | * 594 | * Every successful call to {permit} increases ``owner``'s nonce by one. This 595 | * prevents a signature from being used multiple times. 596 | */ 597 | function nonces(address owner) external view returns (uint256); 598 | 599 | /** 600 | * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. 601 | */ 602 | // solhint-disable-next-line func-name-mixedcase 603 | function DOMAIN_SEPARATOR() external view returns (bytes32); 604 | } 605 | 606 | // File: @openzeppelin/contracts/utils/Address.sol 607 | 608 | // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) 609 | 610 | pragma solidity ^0.8.1; 611 | 612 | /** 613 | * @dev Collection of functions related to the address type 614 | */ 615 | library Address { 616 | /** 617 | * @dev Returns true if `account` is a contract. 618 | * 619 | * [IMPORTANT] 620 | * ==== 621 | * It is unsafe to assume that an address for which this function returns 622 | * false is an externally-owned account (EOA) and not a contract. 623 | * 624 | * Among others, `isContract` will return false for the following 625 | * types of addresses: 626 | * 627 | * - an externally-owned account 628 | * - a contract in construction 629 | * - an address where a contract will be created 630 | * - an address where a contract lived, but was destroyed 631 | * ==== 632 | * 633 | * [IMPORTANT] 634 | * ==== 635 | * You shouldn't rely on `isContract` to protect against flash loan attacks! 636 | * 637 | * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets 638 | * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract 639 | * constructor. 640 | * ==== 641 | */ 642 | function isContract(address account) internal view returns (bool) { 643 | // This method relies on extcodesize/address.code.length, which returns 0 644 | // for contracts in construction, since the code is only stored at the end 645 | // of the constructor execution. 646 | 647 | return account.code.length > 0; 648 | } 649 | 650 | /** 651 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 652 | * `recipient`, forwarding all available gas and reverting on errors. 653 | * 654 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 655 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 656 | * imposed by `transfer`, making them unable to receive funds via 657 | * `transfer`. {sendValue} removes this limitation. 658 | * 659 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 660 | * 661 | * IMPORTANT: because control is transferred to `recipient`, care must be 662 | * taken to not create reentrancy vulnerabilities. Consider using 663 | * {ReentrancyGuard} or the 664 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 665 | */ 666 | function sendValue(address payable recipient, uint256 amount) internal { 667 | require(address(this).balance >= amount, "Address: insufficient balance"); 668 | 669 | (bool success, ) = recipient.call{value: amount}(""); 670 | require(success, "Address: unable to send value, recipient may have reverted"); 671 | } 672 | 673 | /** 674 | * @dev Performs a Solidity function call using a low level `call`. A 675 | * plain `call` is an unsafe replacement for a function call: use this 676 | * function instead. 677 | * 678 | * If `target` reverts with a revert reason, it is bubbled up by this 679 | * function (like regular Solidity function calls). 680 | * 681 | * Returns the raw returned data. To convert to the expected return value, 682 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 683 | * 684 | * Requirements: 685 | * 686 | * - `target` must be a contract. 687 | * - calling `target` with `data` must not revert. 688 | * 689 | * _Available since v3.1._ 690 | */ 691 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 692 | return functionCallWithValue(target, data, 0, "Address: low-level call failed"); 693 | } 694 | 695 | /** 696 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 697 | * `errorMessage` as a fallback revert reason when `target` reverts. 698 | * 699 | * _Available since v3.1._ 700 | */ 701 | function functionCall( 702 | address target, 703 | bytes memory data, 704 | string memory errorMessage 705 | ) internal returns (bytes memory) { 706 | return functionCallWithValue(target, data, 0, errorMessage); 707 | } 708 | 709 | /** 710 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 711 | * but also transferring `value` wei to `target`. 712 | * 713 | * Requirements: 714 | * 715 | * - the calling contract must have an ETH balance of at least `value`. 716 | * - the called Solidity function must be `payable`. 717 | * 718 | * _Available since v3.1._ 719 | */ 720 | function functionCallWithValue( 721 | address target, 722 | bytes memory data, 723 | uint256 value 724 | ) internal returns (bytes memory) { 725 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 726 | } 727 | 728 | /** 729 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 730 | * with `errorMessage` as a fallback revert reason when `target` reverts. 731 | * 732 | * _Available since v3.1._ 733 | */ 734 | function functionCallWithValue( 735 | address target, 736 | bytes memory data, 737 | uint256 value, 738 | string memory errorMessage 739 | ) internal returns (bytes memory) { 740 | require(address(this).balance >= value, "Address: insufficient balance for call"); 741 | (bool success, bytes memory returndata) = target.call{value: value}(data); 742 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 743 | } 744 | 745 | /** 746 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 747 | * but performing a static call. 748 | * 749 | * _Available since v3.3._ 750 | */ 751 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 752 | return functionStaticCall(target, data, "Address: low-level static call failed"); 753 | } 754 | 755 | /** 756 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 757 | * but performing a static call. 758 | * 759 | * _Available since v3.3._ 760 | */ 761 | function functionStaticCall( 762 | address target, 763 | bytes memory data, 764 | string memory errorMessage 765 | ) internal view returns (bytes memory) { 766 | (bool success, bytes memory returndata) = target.staticcall(data); 767 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 768 | } 769 | 770 | /** 771 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 772 | * but performing a delegate call. 773 | * 774 | * _Available since v3.4._ 775 | */ 776 | function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { 777 | return functionDelegateCall(target, data, "Address: low-level delegate call failed"); 778 | } 779 | 780 | /** 781 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 782 | * but performing a delegate call. 783 | * 784 | * _Available since v3.4._ 785 | */ 786 | function functionDelegateCall( 787 | address target, 788 | bytes memory data, 789 | string memory errorMessage 790 | ) internal returns (bytes memory) { 791 | (bool success, bytes memory returndata) = target.delegatecall(data); 792 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 793 | } 794 | 795 | /** 796 | * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling 797 | * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. 798 | * 799 | * _Available since v4.8._ 800 | */ 801 | function verifyCallResultFromTarget( 802 | address target, 803 | bool success, 804 | bytes memory returndata, 805 | string memory errorMessage 806 | ) internal view returns (bytes memory) { 807 | if (success) { 808 | if (returndata.length == 0) { 809 | // only check isContract if the call was successful and the return data is empty 810 | // otherwise we already know that it was a contract 811 | require(isContract(target), "Address: call to non-contract"); 812 | } 813 | return returndata; 814 | } else { 815 | _revert(returndata, errorMessage); 816 | } 817 | } 818 | 819 | /** 820 | * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the 821 | * revert reason or using the provided one. 822 | * 823 | * _Available since v4.3._ 824 | */ 825 | function verifyCallResult( 826 | bool success, 827 | bytes memory returndata, 828 | string memory errorMessage 829 | ) internal pure returns (bytes memory) { 830 | if (success) { 831 | return returndata; 832 | } else { 833 | _revert(returndata, errorMessage); 834 | } 835 | } 836 | 837 | function _revert(bytes memory returndata, string memory errorMessage) private pure { 838 | // Look for revert reason and bubble it up if present 839 | if (returndata.length > 0) { 840 | // The easiest way to bubble the revert reason is using memory via assembly 841 | /// @solidity memory-safe-assembly 842 | assembly { 843 | let returndata_size := mload(returndata) 844 | revert(add(32, returndata), returndata_size) 845 | } 846 | } else { 847 | revert(errorMessage); 848 | } 849 | } 850 | } 851 | 852 | // File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol 853 | 854 | // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) 855 | 856 | pragma solidity ^0.8.0; 857 | 858 | 859 | 860 | /** 861 | * @title SafeERC20 862 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 863 | * contract returns false). Tokens that return no value (and instead revert or 864 | * throw on failure) are also supported, non-reverting calls are assumed to be 865 | * successful. 866 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 867 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 868 | */ 869 | library SafeERC20 { 870 | using Address for address; 871 | 872 | function safeTransfer( 873 | IERC20 token, 874 | address to, 875 | uint256 value 876 | ) internal { 877 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 878 | } 879 | 880 | function safeTransferFrom( 881 | IERC20 token, 882 | address from, 883 | address to, 884 | uint256 value 885 | ) internal { 886 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 887 | } 888 | 889 | /** 890 | * @dev Deprecated. This function has issues similar to the ones found in 891 | * {IERC20-approve}, and its usage is discouraged. 892 | * 893 | * Whenever possible, use {safeIncreaseAllowance} and 894 | * {safeDecreaseAllowance} instead. 895 | */ 896 | function safeApprove( 897 | IERC20 token, 898 | address spender, 899 | uint256 value 900 | ) internal { 901 | // safeApprove should only be called when setting an initial allowance, 902 | // or when resetting it to zero. To increase and decrease it, use 903 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 904 | require( 905 | (value == 0) || (token.allowance(address(this), spender) == 0), 906 | "SafeERC20: approve from non-zero to non-zero allowance" 907 | ); 908 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 909 | } 910 | 911 | function safeIncreaseAllowance( 912 | IERC20 token, 913 | address spender, 914 | uint256 value 915 | ) internal { 916 | uint256 newAllowance = token.allowance(address(this), spender) + value; 917 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 918 | } 919 | 920 | function safeDecreaseAllowance( 921 | IERC20 token, 922 | address spender, 923 | uint256 value 924 | ) internal { 925 | unchecked { 926 | uint256 oldAllowance = token.allowance(address(this), spender); 927 | require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); 928 | uint256 newAllowance = oldAllowance - value; 929 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 930 | } 931 | } 932 | 933 | function safePermit( 934 | IERC20Permit token, 935 | address owner, 936 | address spender, 937 | uint256 value, 938 | uint256 deadline, 939 | uint8 v, 940 | bytes32 r, 941 | bytes32 s 942 | ) internal { 943 | uint256 nonceBefore = token.nonces(owner); 944 | token.permit(owner, spender, value, deadline, v, r, s); 945 | uint256 nonceAfter = token.nonces(owner); 946 | require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); 947 | } 948 | 949 | /** 950 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 951 | * on the return value: the return value is optional (but if data is returned, it must not be false). 952 | * @param token The token targeted by the call. 953 | * @param data The call data (encoded using abi.encode or one of its variants). 954 | */ 955 | function _callOptionalReturn(IERC20 token, bytes memory data) private { 956 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 957 | // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that 958 | // the target address contains contract code and also asserts for success in the low-level call. 959 | 960 | bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 961 | if (returndata.length > 0) { 962 | // Return data is optional 963 | require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); 964 | } 965 | } 966 | } 967 | 968 | // File: @openzeppelin/contracts/access/Ownable.sol 969 | 970 | // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) 971 | 972 | pragma solidity ^0.8.0; 973 | 974 | /** 975 | * @dev Contract module which provides a basic access control mechanism, where 976 | * there is an account (an owner) that can be granted exclusive access to 977 | * specific functions. 978 | * 979 | * By default, the owner account will be the one that deploys the contract. This 980 | * can later be changed with {transferOwnership}. 981 | * 982 | * This module is used through inheritance. It will make available the modifier 983 | * `onlyOwner`, which can be applied to your functions to restrict their use to 984 | * the owner. 985 | */ 986 | abstract contract Ownable is Context { 987 | address private _owner; 988 | 989 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 990 | 991 | /** 992 | * @dev Initializes the contract setting the deployer as the initial owner. 993 | */ 994 | constructor() { 995 | _transferOwnership(_msgSender()); 996 | } 997 | 998 | /** 999 | * @dev Throws if called by any account other than the owner. 1000 | */ 1001 | modifier onlyOwner() { 1002 | _checkOwner(); 1003 | _; 1004 | } 1005 | 1006 | /** 1007 | * @dev Returns the address of the current owner. 1008 | */ 1009 | function owner() public view virtual returns (address) { 1010 | return _owner; 1011 | } 1012 | 1013 | /** 1014 | * @dev Throws if the sender is not the owner. 1015 | */ 1016 | function _checkOwner() internal view virtual { 1017 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 1018 | } 1019 | 1020 | /** 1021 | * @dev Leaves the contract without owner. It will not be possible to call 1022 | * `onlyOwner` functions anymore. Can only be called by the current owner. 1023 | * 1024 | * NOTE: Renouncing ownership will leave the contract without an owner, 1025 | * thereby removing any functionality that is only available to the owner. 1026 | */ 1027 | function renounceOwnership() public virtual onlyOwner { 1028 | _transferOwnership(address(0)); 1029 | } 1030 | 1031 | /** 1032 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 1033 | * Can only be called by the current owner. 1034 | */ 1035 | function transferOwnership(address newOwner) public virtual onlyOwner { 1036 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 1037 | _transferOwnership(newOwner); 1038 | } 1039 | 1040 | /** 1041 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 1042 | * Internal function without access restriction. 1043 | */ 1044 | function _transferOwnership(address newOwner) internal virtual { 1045 | address oldOwner = _owner; 1046 | _owner = newOwner; 1047 | emit OwnershipTransferred(oldOwner, newOwner); 1048 | } 1049 | } 1050 | 1051 | // File: @openzeppelin/contracts/utils/structs/EnumerableSet.sol 1052 | 1053 | // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) 1054 | // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. 1055 | 1056 | pragma solidity ^0.8.0; 1057 | 1058 | /** 1059 | * @dev Library for managing 1060 | * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive 1061 | * types. 1062 | * 1063 | * Sets have the following properties: 1064 | * 1065 | * - Elements are added, removed, and checked for existence in constant time 1066 | * (O(1)). 1067 | * - Elements are enumerated in O(n). No guarantees are made on the ordering. 1068 | * 1069 | * ``` 1070 | * contract Example { 1071 | * // Add the library methods 1072 | * using EnumerableSet for EnumerableSet.AddressSet; 1073 | * 1074 | * // Declare a set state variable 1075 | * EnumerableSet.AddressSet private mySet; 1076 | * } 1077 | * ``` 1078 | * 1079 | * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) 1080 | * and `uint256` (`UintSet`) are supported. 1081 | * 1082 | * [WARNING] 1083 | * ==== 1084 | * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure 1085 | * unusable. 1086 | * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. 1087 | * 1088 | * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an 1089 | * array of EnumerableSet. 1090 | * ==== 1091 | */ 1092 | library EnumerableSet { 1093 | // To implement this library for multiple types with as little code 1094 | // repetition as possible, we write it in terms of a generic Set type with 1095 | // bytes32 values. 1096 | // The Set implementation uses private functions, and user-facing 1097 | // implementations (such as AddressSet) are just wrappers around the 1098 | // underlying Set. 1099 | // This means that we can only create new EnumerableSets for types that fit 1100 | // in bytes32. 1101 | 1102 | struct Set { 1103 | // Storage of set values 1104 | bytes32[] _values; 1105 | // Position of the value in the `values` array, plus 1 because index 0 1106 | // means a value is not in the set. 1107 | mapping(bytes32 => uint256) _indexes; 1108 | } 1109 | 1110 | /** 1111 | * @dev Add a value to a set. O(1). 1112 | * 1113 | * Returns true if the value was added to the set, that is if it was not 1114 | * already present. 1115 | */ 1116 | function _add(Set storage set, bytes32 value) private returns (bool) { 1117 | if (!_contains(set, value)) { 1118 | set._values.push(value); 1119 | // The value is stored at length-1, but we add 1 to all indexes 1120 | // and use 0 as a sentinel value 1121 | set._indexes[value] = set._values.length; 1122 | return true; 1123 | } else { 1124 | return false; 1125 | } 1126 | } 1127 | 1128 | /** 1129 | * @dev Removes a value from a set. O(1). 1130 | * 1131 | * Returns true if the value was removed from the set, that is if it was 1132 | * present. 1133 | */ 1134 | function _remove(Set storage set, bytes32 value) private returns (bool) { 1135 | // We read and store the value's index to prevent multiple reads from the same storage slot 1136 | uint256 valueIndex = set._indexes[value]; 1137 | 1138 | if (valueIndex != 0) { 1139 | // Equivalent to contains(set, value) 1140 | // To delete an element from the _values array in O(1), we swap the element to delete with the last one in 1141 | // the array, and then remove the last element (sometimes called as 'swap and pop'). 1142 | // This modifies the order of the array, as noted in {at}. 1143 | 1144 | uint256 toDeleteIndex = valueIndex - 1; 1145 | uint256 lastIndex = set._values.length - 1; 1146 | 1147 | if (lastIndex != toDeleteIndex) { 1148 | bytes32 lastValue = set._values[lastIndex]; 1149 | 1150 | // Move the last value to the index where the value to delete is 1151 | set._values[toDeleteIndex] = lastValue; 1152 | // Update the index for the moved value 1153 | set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex 1154 | } 1155 | 1156 | // Delete the slot where the moved value was stored 1157 | set._values.pop(); 1158 | 1159 | // Delete the index for the deleted slot 1160 | delete set._indexes[value]; 1161 | 1162 | return true; 1163 | } else { 1164 | return false; 1165 | } 1166 | } 1167 | 1168 | /** 1169 | * @dev Returns true if the value is in the set. O(1). 1170 | */ 1171 | function _contains(Set storage set, bytes32 value) private view returns (bool) { 1172 | return set._indexes[value] != 0; 1173 | } 1174 | 1175 | /** 1176 | * @dev Returns the number of values on the set. O(1). 1177 | */ 1178 | function _length(Set storage set) private view returns (uint256) { 1179 | return set._values.length; 1180 | } 1181 | 1182 | /** 1183 | * @dev Returns the value stored at position `index` in the set. O(1). 1184 | * 1185 | * Note that there are no guarantees on the ordering of values inside the 1186 | * array, and it may change when more values are added or removed. 1187 | * 1188 | * Requirements: 1189 | * 1190 | * - `index` must be strictly less than {length}. 1191 | */ 1192 | function _at(Set storage set, uint256 index) private view returns (bytes32) { 1193 | return set._values[index]; 1194 | } 1195 | 1196 | /** 1197 | * @dev Return the entire set in an array 1198 | * 1199 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1200 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1201 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1202 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1203 | */ 1204 | function _values(Set storage set) private view returns (bytes32[] memory) { 1205 | return set._values; 1206 | } 1207 | 1208 | // Bytes32Set 1209 | 1210 | struct Bytes32Set { 1211 | Set _inner; 1212 | } 1213 | 1214 | /** 1215 | * @dev Add a value to a set. O(1). 1216 | * 1217 | * Returns true if the value was added to the set, that is if it was not 1218 | * already present. 1219 | */ 1220 | function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { 1221 | return _add(set._inner, value); 1222 | } 1223 | 1224 | /** 1225 | * @dev Removes a value from a set. O(1). 1226 | * 1227 | * Returns true if the value was removed from the set, that is if it was 1228 | * present. 1229 | */ 1230 | function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { 1231 | return _remove(set._inner, value); 1232 | } 1233 | 1234 | /** 1235 | * @dev Returns true if the value is in the set. O(1). 1236 | */ 1237 | function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { 1238 | return _contains(set._inner, value); 1239 | } 1240 | 1241 | /** 1242 | * @dev Returns the number of values in the set. O(1). 1243 | */ 1244 | function length(Bytes32Set storage set) internal view returns (uint256) { 1245 | return _length(set._inner); 1246 | } 1247 | 1248 | /** 1249 | * @dev Returns the value stored at position `index` in the set. O(1). 1250 | * 1251 | * Note that there are no guarantees on the ordering of values inside the 1252 | * array, and it may change when more values are added or removed. 1253 | * 1254 | * Requirements: 1255 | * 1256 | * - `index` must be strictly less than {length}. 1257 | */ 1258 | function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { 1259 | return _at(set._inner, index); 1260 | } 1261 | 1262 | /** 1263 | * @dev Return the entire set in an array 1264 | * 1265 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1266 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1267 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1268 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1269 | */ 1270 | function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { 1271 | bytes32[] memory store = _values(set._inner); 1272 | bytes32[] memory result; 1273 | 1274 | /// @solidity memory-safe-assembly 1275 | assembly { 1276 | result := store 1277 | } 1278 | 1279 | return result; 1280 | } 1281 | 1282 | // AddressSet 1283 | 1284 | struct AddressSet { 1285 | Set _inner; 1286 | } 1287 | 1288 | /** 1289 | * @dev Add a value to a set. O(1). 1290 | * 1291 | * Returns true if the value was added to the set, that is if it was not 1292 | * already present. 1293 | */ 1294 | function add(AddressSet storage set, address value) internal returns (bool) { 1295 | return _add(set._inner, bytes32(uint256(uint160(value)))); 1296 | } 1297 | 1298 | /** 1299 | * @dev Removes a value from a set. O(1). 1300 | * 1301 | * Returns true if the value was removed from the set, that is if it was 1302 | * present. 1303 | */ 1304 | function remove(AddressSet storage set, address value) internal returns (bool) { 1305 | return _remove(set._inner, bytes32(uint256(uint160(value)))); 1306 | } 1307 | 1308 | /** 1309 | * @dev Returns true if the value is in the set. O(1). 1310 | */ 1311 | function contains(AddressSet storage set, address value) internal view returns (bool) { 1312 | return _contains(set._inner, bytes32(uint256(uint160(value)))); 1313 | } 1314 | 1315 | /** 1316 | * @dev Returns the number of values in the set. O(1). 1317 | */ 1318 | function length(AddressSet storage set) internal view returns (uint256) { 1319 | return _length(set._inner); 1320 | } 1321 | 1322 | /** 1323 | * @dev Returns the value stored at position `index` in the set. O(1). 1324 | * 1325 | * Note that there are no guarantees on the ordering of values inside the 1326 | * array, and it may change when more values are added or removed. 1327 | * 1328 | * Requirements: 1329 | * 1330 | * - `index` must be strictly less than {length}. 1331 | */ 1332 | function at(AddressSet storage set, uint256 index) internal view returns (address) { 1333 | return address(uint160(uint256(_at(set._inner, index)))); 1334 | } 1335 | 1336 | /** 1337 | * @dev Return the entire set in an array 1338 | * 1339 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1340 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1341 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1342 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1343 | */ 1344 | function values(AddressSet storage set) internal view returns (address[] memory) { 1345 | bytes32[] memory store = _values(set._inner); 1346 | address[] memory result; 1347 | 1348 | /// @solidity memory-safe-assembly 1349 | assembly { 1350 | result := store 1351 | } 1352 | 1353 | return result; 1354 | } 1355 | 1356 | // UintSet 1357 | 1358 | struct UintSet { 1359 | Set _inner; 1360 | } 1361 | 1362 | /** 1363 | * @dev Add a value to a set. O(1). 1364 | * 1365 | * Returns true if the value was added to the set, that is if it was not 1366 | * already present. 1367 | */ 1368 | function add(UintSet storage set, uint256 value) internal returns (bool) { 1369 | return _add(set._inner, bytes32(value)); 1370 | } 1371 | 1372 | /** 1373 | * @dev Removes a value from a set. O(1). 1374 | * 1375 | * Returns true if the value was removed from the set, that is if it was 1376 | * present. 1377 | */ 1378 | function remove(UintSet storage set, uint256 value) internal returns (bool) { 1379 | return _remove(set._inner, bytes32(value)); 1380 | } 1381 | 1382 | /** 1383 | * @dev Returns true if the value is in the set. O(1). 1384 | */ 1385 | function contains(UintSet storage set, uint256 value) internal view returns (bool) { 1386 | return _contains(set._inner, bytes32(value)); 1387 | } 1388 | 1389 | /** 1390 | * @dev Returns the number of values in the set. O(1). 1391 | */ 1392 | function length(UintSet storage set) internal view returns (uint256) { 1393 | return _length(set._inner); 1394 | } 1395 | 1396 | /** 1397 | * @dev Returns the value stored at position `index` in the set. O(1). 1398 | * 1399 | * Note that there are no guarantees on the ordering of values inside the 1400 | * array, and it may change when more values are added or removed. 1401 | * 1402 | * Requirements: 1403 | * 1404 | * - `index` must be strictly less than {length}. 1405 | */ 1406 | function at(UintSet storage set, uint256 index) internal view returns (uint256) { 1407 | return uint256(_at(set._inner, index)); 1408 | } 1409 | 1410 | /** 1411 | * @dev Return the entire set in an array 1412 | * 1413 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1414 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1415 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1416 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1417 | */ 1418 | function values(UintSet storage set) internal view returns (uint256[] memory) { 1419 | bytes32[] memory store = _values(set._inner); 1420 | uint256[] memory result; 1421 | 1422 | /// @solidity memory-safe-assembly 1423 | assembly { 1424 | result := store 1425 | } 1426 | 1427 | return result; 1428 | } 1429 | } 1430 | 1431 | // File: contracts/interfaces/ICamelotFactory.sol 1432 | 1433 | 1434 | pragma solidity >=0.5.0; 1435 | 1436 | interface ICamelotFactory { 1437 | event PairCreated( 1438 | address indexed token0, 1439 | address indexed token1, 1440 | address pair, 1441 | uint256 1442 | ); 1443 | 1444 | function owner() external view returns (address); 1445 | 1446 | function feePercentOwner() external view returns (address); 1447 | 1448 | function setStableOwner() external view returns (address); 1449 | 1450 | function feeTo() external view returns (address); 1451 | 1452 | function ownerFeeShare() external view returns (uint256); 1453 | 1454 | function referrersFeeShare(address) external view returns (uint256); 1455 | 1456 | function getPair( 1457 | address tokenA, 1458 | address tokenB 1459 | ) external view returns (address pair); 1460 | 1461 | function allPairs(uint256) external view returns (address pair); 1462 | 1463 | function allPairsLength() external view returns (uint256); 1464 | 1465 | function createPair( 1466 | address tokenA, 1467 | address tokenB 1468 | ) external returns (address pair); 1469 | 1470 | function setFeeTo(address) external; 1471 | 1472 | function feeInfo() 1473 | external 1474 | view 1475 | returns (uint _ownerFeeShare, address _feeTo); 1476 | } 1477 | 1478 | // File: contracts/interfaces/IUniswapV2Router01.sol 1479 | 1480 | 1481 | pragma solidity >=0.6.2; 1482 | 1483 | interface IUniswapV2Router01 { 1484 | function factory() external pure returns (address); 1485 | 1486 | function WETH() external pure returns (address); 1487 | 1488 | function addLiquidity( 1489 | address tokenA, 1490 | address tokenB, 1491 | uint amountADesired, 1492 | uint amountBDesired, 1493 | uint amountAMin, 1494 | uint amountBMin, 1495 | address to, 1496 | uint deadline 1497 | ) external returns (uint amountA, uint amountB, uint liquidity); 1498 | 1499 | function addLiquidityETH( 1500 | address token, 1501 | uint amountTokenDesired, 1502 | uint amountTokenMin, 1503 | uint amountETHMin, 1504 | address to, 1505 | uint deadline 1506 | ) 1507 | external 1508 | payable 1509 | returns (uint amountToken, uint amountETH, uint liquidity); 1510 | 1511 | function removeLiquidity( 1512 | address tokenA, 1513 | address tokenB, 1514 | uint liquidity, 1515 | uint amountAMin, 1516 | uint amountBMin, 1517 | address to, 1518 | uint deadline 1519 | ) external returns (uint amountA, uint amountB); 1520 | 1521 | function removeLiquidityETH( 1522 | address token, 1523 | uint liquidity, 1524 | uint amountTokenMin, 1525 | uint amountETHMin, 1526 | address to, 1527 | uint deadline 1528 | ) external returns (uint amountToken, uint amountETH); 1529 | 1530 | function removeLiquidityWithPermit( 1531 | address tokenA, 1532 | address tokenB, 1533 | uint liquidity, 1534 | uint amountAMin, 1535 | uint amountBMin, 1536 | address to, 1537 | uint deadline, 1538 | bool approveMax, 1539 | uint8 v, 1540 | bytes32 r, 1541 | bytes32 s 1542 | ) external returns (uint amountA, uint amountB); 1543 | 1544 | function removeLiquidityETHWithPermit( 1545 | address token, 1546 | uint liquidity, 1547 | uint amountTokenMin, 1548 | uint amountETHMin, 1549 | address to, 1550 | uint deadline, 1551 | bool approveMax, 1552 | uint8 v, 1553 | bytes32 r, 1554 | bytes32 s 1555 | ) external returns (uint amountToken, uint amountETH); 1556 | 1557 | function quote( 1558 | uint amountA, 1559 | uint reserveA, 1560 | uint reserveB 1561 | ) external pure returns (uint amountB); 1562 | 1563 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 1564 | uint256 amountIn, 1565 | uint256 amountOutMin, 1566 | address[] calldata path, 1567 | address to, 1568 | uint256 deadline 1569 | ) external; 1570 | 1571 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 1572 | uint amountIn, 1573 | uint amountOutMin, 1574 | address[] calldata path, 1575 | address to, 1576 | uint deadline 1577 | ) external; 1578 | } 1579 | 1580 | // File: contracts/interfaces/ICamelotRouter.sol 1581 | 1582 | 1583 | pragma solidity >=0.6.2; 1584 | 1585 | interface ICamelotRouter is IUniswapV2Router01 { 1586 | function removeLiquidityETHSupportingFeeOnTransferTokens( 1587 | address token, 1588 | uint liquidity, 1589 | uint amountTokenMin, 1590 | uint amountETHMin, 1591 | address to, 1592 | uint deadline 1593 | ) external returns (uint amountETH); 1594 | 1595 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 1596 | address token, 1597 | uint liquidity, 1598 | uint amountTokenMin, 1599 | uint amountETHMin, 1600 | address to, 1601 | uint deadline, 1602 | bool approveMax, 1603 | uint8 v, 1604 | bytes32 r, 1605 | bytes32 s 1606 | ) external returns (uint amountETH); 1607 | 1608 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 1609 | uint amountIn, 1610 | uint amountOutMin, 1611 | address[] calldata path, 1612 | address to, 1613 | address referrer, 1614 | uint deadline 1615 | ) external; 1616 | 1617 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 1618 | uint amountOutMin, 1619 | address[] calldata path, 1620 | address to, 1621 | address referrer, 1622 | uint deadline 1623 | ) external payable; 1624 | 1625 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 1626 | uint amountIn, 1627 | uint amountOutMin, 1628 | address[] calldata path, 1629 | address to, 1630 | address referrer, 1631 | uint deadline 1632 | ) external; 1633 | 1634 | function getAmountsOut( 1635 | uint amountIn, 1636 | address[] calldata path 1637 | ) external view returns (uint[] memory amounts); 1638 | } 1639 | 1640 | // File: contracts/interfaces/IJackpot.sol 1641 | 1642 | 1643 | pragma solidity >=0.5.0; 1644 | 1645 | interface IJackpot { 1646 | function lottery(address sender, uint256 amount) external; 1647 | } 1648 | 1649 | interface IAutoliquidityTreasury { 1650 | function autoAddLiquidity(address contractA, address contractB, uint256 tokenAmountA) external; 1651 | } 1652 | 1653 | interface readDistributor { 1654 | function getPresale(address _address) external view returns (uint256); 1655 | } 1656 | 1657 | // File: contracts/interfaces/IWETH.sol 1658 | 1659 | 1660 | pragma solidity >=0.5.0; 1661 | 1662 | interface IWETH { 1663 | function totalSupply() external view returns (uint256); 1664 | 1665 | function balanceOf(address account) external view returns (uint256); 1666 | 1667 | function allowance(address owner, address spender) external view returns (uint256); 1668 | 1669 | function approve(address spender, uint256 amount) external returns (bool); 1670 | 1671 | function deposit() external payable; 1672 | 1673 | function transfer(address to, uint256 value) external returns (bool); 1674 | 1675 | function withdraw(uint256) external; 1676 | } 1677 | 1678 | 1679 | pragma solidity >=0.5.0; 1680 | 1681 | interface IAffiBonusPool { 1682 | function deposit(uint256 _pid, uint256 _amount) external; 1683 | function withdraw(uint256 _pid, uint256 _amount) external; 1684 | function emergencyWithdraw(uint256 _pid) external; 1685 | function injectRewards(uint256 amount) external; 1686 | function injectRewardsWithTime(uint256 amount, uint256 rewardsSeconds) external; 1687 | } 1688 | 1689 | // File: contracts/token/AFFITRUM.sol 1690 | 1691 | 1692 | pragma solidity =0.8.19; 1693 | 1694 | contract AFFITRUM is ERC20, Ownable { 1695 | using SafeERC20 for IERC20; 1696 | using EnumerableSet for EnumerableSet.AddressSet; 1697 | 1698 | event SwapBack(uint256 burn, uint256 liquidity, uint256 jackpot, uint256 bonus, uint256 dev, uint timestamp); 1699 | event Trade(address user, address pair, uint256 amount, uint side, uint256 circulatingSupply, uint timestamp); 1700 | event AddLiquidity(uint256 tokenAmount, uint256 ethAmount, uint256 timestamp); 1701 | event BuyBack(uint256 ethAmount, uint256 timestamp); 1702 | 1703 | bool public swapEnabled = true; 1704 | bool public addLiquidityEnabled = true; 1705 | bool public autoBuyBackEnabled = true; 1706 | bool public RecordBuyEnabled = false; 1707 | 1708 | bool public inSwap; 1709 | modifier swapping() { 1710 | inSwap = true; 1711 | _; 1712 | inSwap = false; 1713 | } 1714 | 1715 | mapping(address => bool) public isFeeExempt; 1716 | mapping(address => bool) public canAddLiquidityBeforeLaunch; 1717 | mapping(address => address) public referrers; 1718 | mapping(address => uint256) public totalCoinsBought; 1719 | 1720 | uint256 private burnFee; 1721 | uint256 private liquidityFee; 1722 | uint256 private jackpotFee; 1723 | uint256 private bonusFee; 1724 | uint256 private referralFee; 1725 | uint256 private devFee; 1726 | uint256 private totalFee; 1727 | uint256 public feeDenominator = 10000; 1728 | uint256 public mintokenswapback; 1729 | 1730 | // Buy Fees 1731 | uint256 public burnFeeBuy = 100; 1732 | uint256 public liquidityFeeBuy = 100; 1733 | uint256 public jackpotFeeBuy = 100; 1734 | uint256 public bonusFeeBuy = 300; 1735 | uint256 public referralFeeBuy = 100; 1736 | uint256 public devFeeBuy = 200; 1737 | uint256 public totalFeeBuy = 900; 1738 | // Sell Fees 1739 | uint256 public burnFeeSell = 100; 1740 | uint256 public liquidityFeeSell = 100; 1741 | uint256 public jackpotFeeSell = 100; 1742 | uint256 public bonusFeeSell = 300; 1743 | uint256 public referralFeeSell = 100; 1744 | uint256 public devFeeSell = 200; 1745 | uint256 public totalFeeSell = 900; 1746 | 1747 | // Fees receivers 1748 | address private bonusWallet; 1749 | IJackpot public jackpotWallet; 1750 | IAutoliquidityTreasury private AutoLiquidityTreasury; 1751 | 1752 | address private devWallet; 1753 | address private eventWallet; 1754 | address private distributor; 1755 | 1756 | IERC20 public backToken; 1757 | IERC20 public USDT; 1758 | uint256 public launchedAt; 1759 | uint256 public launchedAtTimestamp; 1760 | bool private initialized; 1761 | 1762 | ICamelotFactory private immutable factory; 1763 | ICamelotRouter private immutable swapRouter; 1764 | IWETH private immutable WETH; 1765 | address private constant DEAD = 0x000000000000000000000000000000000000dEaD; 1766 | address private constant ZERO = 0x0000000000000000000000000000000000000000; 1767 | 1768 | EnumerableSet.AddressSet private _pairs; 1769 | 1770 | constructor( 1771 | IERC20 _backToken, 1772 | address _factory, 1773 | address _swapRouter, 1774 | address _weth, 1775 | IERC20 _usdt 1776 | ) ERC20("AFFITRUM", "AFFI") { 1777 | uint256 _totalSupply = 100_000_000 * 1e6; 1778 | backToken = _backToken; 1779 | USDT = _usdt; 1780 | canAddLiquidityBeforeLaunch[_msgSender()] = true; 1781 | canAddLiquidityBeforeLaunch[address(this)] = true; 1782 | isFeeExempt[msg.sender] = true; 1783 | isFeeExempt[address(this)] = true; 1784 | factory = ICamelotFactory(_factory); 1785 | swapRouter = ICamelotRouter(_swapRouter); 1786 | WETH = IWETH(_weth); 1787 | _mint(_msgSender(), _totalSupply); 1788 | } 1789 | 1790 | function setReferrer(address _user, address _referrer) external { 1791 | require(distributor != address(0) && msg.sender == distributor, "Only Distributor can set referrer"); 1792 | referrers[_user] = _referrer; 1793 | } 1794 | 1795 | function initializePair(address _pair) external onlyOwner { 1796 | require(!initialized, "Already initialized"); 1797 | address pair = factory.createPair(_pair, address(this)); 1798 | _pairs.add(pair); 1799 | initialized = true; 1800 | } 1801 | 1802 | function decimals() public view virtual override returns (uint8) { 1803 | return 6; 1804 | } 1805 | 1806 | function transfer(address to, uint256 amount) public virtual override returns (bool) { 1807 | return _AffiTransfer(_msgSender(), to, amount); 1808 | } 1809 | 1810 | function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { 1811 | address spender = _msgSender(); 1812 | _spendAllowance(sender, spender, amount); 1813 | return _AffiTransfer(sender, recipient, amount); 1814 | } 1815 | 1816 | function _AffiTransfer(address sender, address recipient, uint256 amount) internal returns (bool) { 1817 | if (inSwap) { 1818 | _transfer(sender, recipient, amount); 1819 | return true; 1820 | } 1821 | if (!canAddLiquidityBeforeLaunch[sender]) { 1822 | require(launched(), "Trading not open yet"); 1823 | } 1824 | if (distributor != address(0)) { 1825 | uint256 PurchasedAmount = readDistributor(distributor).getPresale(sender); 1826 | require((balanceOf(sender) - amount) >= PurchasedAmount, "ERC20: transfer failed"); 1827 | } 1828 | 1829 | bool shouldTakeFee = (!isFeeExempt[sender] && !isFeeExempt[recipient]) && launched(); 1830 | uint side = 0; 1831 | address user_ = sender; 1832 | address pair_ = recipient; 1833 | // Set Fees 1834 | if (isPair(sender)) { 1835 | buyFees(); 1836 | side = 1; 1837 | user_ = recipient; 1838 | pair_ = sender; 1839 | try jackpotWallet.lottery(recipient, amount) {} catch {} 1840 | 1841 | } else if (isPair(recipient)) { 1842 | sellFees(); 1843 | side = 2; 1844 | } else { 1845 | shouldTakeFee = false; 1846 | } 1847 | 1848 | if (shouldSwapBack(address(sender))) { 1849 | swapBack(); 1850 | } 1851 | 1852 | uint256 amountReceived = shouldTakeFee ? takeFee(sender, amount, user_) : amount; 1853 | _transfer(sender, recipient, amountReceived); 1854 | 1855 | if (side > 0) { 1856 | emit Trade(user_, pair_, amount, side, getCirculatingSupply(), block.timestamp); 1857 | } 1858 | if (side == 1 && RecordBuyEnabled) { 1859 | totalCoinsBought[recipient] += amount; //taken fees? update mapping 1860 | } 1861 | return true; 1862 | } 1863 | 1864 | function shouldSwapBack(address sender) internal view returns (bool) { 1865 | return !inSwap && swapEnabled && launched() && balanceOf(address(this)) > mintokenswapback && !isPair(_msgSender()) && sender != distributor && sender != bonusWallet; 1866 | } 1867 | 1868 | function swapBack() internal swapping { 1869 | uint256 taxAmount = balanceOf(address(this)); 1870 | uint256 ethbalance = address(this).balance; 1871 | _approve(address(this), address(swapRouter), taxAmount); 1872 | 1873 | uint256 _totalFee = totalFee - referralFee; 1874 | 1875 | uint256 amountAffiBurn = (taxAmount * burnFee) / (_totalFee); 1876 | uint256 amountAffiLp = (taxAmount * liquidityFee) / (_totalFee); 1877 | uint256 amountAffiBonus = (taxAmount * bonusFee) / (_totalFee); 1878 | taxAmount -= amountAffiBurn; 1879 | taxAmount -= amountAffiLp; 1880 | taxAmount -= amountAffiBonus; 1881 | 1882 | //SWAP BACK TOKEN > USDT(LP) 1883 | address[] memory path = new address[](3); 1884 | path[0] = address(this); 1885 | path[1] = address(USDT); 1886 | path[2] = address(backToken); 1887 | 1888 | bool success = false; 1889 | uint256 balanceBefore = backToken.balanceOf(address(this)); 1890 | try swapRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(taxAmount,0,path,address(this),block.timestamp) { 1891 | success = true; 1892 | } catch {} 1893 | if (!success) { 1894 | return; 1895 | } 1896 | 1897 | _transfer(address(this), DEAD, amountAffiBurn); 1898 | _transfer(address(this), address(bonusWallet), amountAffiBonus); 1899 | 1900 | uint256 amountBackToken = backToken.balanceOf(address(this)) - balanceBefore; 1901 | uint256 backTokenTotalFee = _totalFee - burnFee - liquidityFee - bonusFee; 1902 | uint256 amountBackTokenJackpot = (amountBackToken * jackpotFee) / backTokenTotalFee; 1903 | uint256 amountBackTokenDev = amountBackToken - amountBackTokenJackpot; 1904 | 1905 | backToken.transfer(address(jackpotWallet), amountBackTokenJackpot); 1906 | backToken.transfer(devWallet, amountBackTokenDev); 1907 | 1908 | if (addLiquidityEnabled) { 1909 | _doAddLp(); 1910 | } 1911 | 1912 | if (autoBuyBackEnabled && ethbalance > 0) { 1913 | _buybackToken(); 1914 | } 1915 | 1916 | emit SwapBack(amountAffiBurn, amountAffiLp, amountBackTokenJackpot, amountAffiBonus, amountBackTokenDev, block.timestamp); 1917 | } 1918 | 1919 | function _doAddLp() internal { 1920 | //swap half tokens to usdt to add LP 1921 | address[] memory pathEth = new address[](2); 1922 | pathEth[0] = address(this); 1923 | pathEth[1] = address(USDT); 1924 | 1925 | uint256 tokenAmount = balanceOf(address(this)); 1926 | uint256 half = tokenAmount / 2; 1927 | if(half < 1000) return; 1928 | 1929 | //swap leftover to usdt 1930 | bool success = false; 1931 | try swapRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(half,0, pathEth,address(AutoLiquidityTreasury),block.timestamp) 1932 | { 1933 | success = true; 1934 | } catch {} 1935 | if (!success) { 1936 | return; 1937 | } 1938 | 1939 | //treasury auto add liquidity 1940 | _transfer(address(this), address(AutoLiquidityTreasury), half); 1941 | _approve(address(AutoLiquidityTreasury), address(swapRouter), half); 1942 | try AutoLiquidityTreasury.autoAddLiquidity(address(this), address(USDT), half) {} catch {} 1943 | } 1944 | 1945 | function _buybackToken() internal swapping { 1946 | address[] memory path = new address[](3); 1947 | path[0] = address(WETH); 1948 | path[1] = address(USDT); 1949 | path[2] = address(this); 1950 | 1951 | uint256 ethAmountBefore = address(this).balance; 1952 | try swapRouter.swapExactETHForTokensSupportingFeeOnTransferTokens{value: ethAmountBefore}(0, path, bonusWallet, block.timestamp) {} catch {} 1953 | emit BuyBack(ethAmountBefore, block.timestamp); 1954 | } 1955 | 1956 | function doSwapBack() public onlyOwner { 1957 | swapBack(); 1958 | } 1959 | 1960 | function launched() internal view returns (bool) { 1961 | return launchedAt != 0; 1962 | } 1963 | 1964 | function buyFees() internal { 1965 | burnFee = burnFeeBuy; 1966 | liquidityFee = liquidityFeeBuy; 1967 | jackpotFee = jackpotFeeBuy; 1968 | bonusFee = bonusFeeBuy; 1969 | referralFee = referralFeeBuy; 1970 | devFee = devFeeBuy; 1971 | totalFee = totalFeeBuy; 1972 | } 1973 | 1974 | function sellFees() internal { 1975 | burnFee = burnFeeSell; 1976 | liquidityFee = liquidityFeeSell; 1977 | jackpotFee = jackpotFeeSell; 1978 | bonusFee = bonusFeeSell; 1979 | referralFee = referralFeeSell; 1980 | devFee = devFeeSell; 1981 | totalFee = totalFeeSell; 1982 | } 1983 | 1984 | function takeFee(address sender, uint256 amount, address user) internal returns (uint256) { 1985 | uint256 feeAmount = (amount * totalFee) / feeDenominator; 1986 | uint256 refAmount = (feeAmount * referralFee) / totalFee; 1987 | address refFeeTo = referrers[user] != address(0) ? referrers[user] : eventWallet; 1988 | _transfer(sender, refFeeTo, refAmount); 1989 | _transfer(sender, address(this), feeAmount - refAmount); 1990 | return amount - feeAmount; 1991 | } 1992 | 1993 | function getCirculatingSupply() public view returns (uint256) { 1994 | return totalSupply() - balanceOf(DEAD) - balanceOf(ZERO); 1995 | } 1996 | 1997 | /*** ADMIN FUNCTIONS ***/ 1998 | function launch() public onlyOwner { 1999 | require(launchedAt == 0, "Already launched"); 2000 | launchedAt = block.number; 2001 | launchedAtTimestamp = block.timestamp; 2002 | } 2003 | 2004 | function rescueToken(address tokenAddress) external onlyOwner { 2005 | require(tokenAddress != address(this), "CANT RESQUE OWN TOKEN"); 2006 | IERC20(tokenAddress).safeTransfer(msg.sender,IERC20(tokenAddress).balanceOf(address(this))); 2007 | } 2008 | 2009 | function clearStuckEthBalance() external onlyOwner { 2010 | uint256 amountETH = address(this).balance; 2011 | (bool success, ) = payable(_msgSender()).call{value: amountETH}(new bytes(0)); 2012 | require(success, "ETH_TRANSFER_FAILED"); 2013 | } 2014 | 2015 | 2016 | function setFeeReceivers( 2017 | address _bonusWallet, 2018 | address _jackpotWallet, 2019 | address _devWallet, 2020 | address _eventWallet 2021 | ) external onlyOwner { 2022 | bonusWallet = _bonusWallet; 2023 | jackpotWallet = IJackpot(_jackpotWallet); 2024 | devWallet = _devWallet; 2025 | eventWallet = _eventWallet; 2026 | } 2027 | 2028 | function setAutoLiquidityTreasury(address _AutoLiquidityTreasury) external onlyOwner { 2029 | require(_AutoLiquidityTreasury != address(0), "Zero address"); 2030 | AutoLiquidityTreasury = IAutoliquidityTreasury(_AutoLiquidityTreasury); 2031 | } 2032 | 2033 | function setDistributor(address _distributor) external onlyOwner { 2034 | require(_distributor != address(0), "Zero address"); 2035 | distributor = _distributor; 2036 | } 2037 | 2038 | function setMinSwapbackAmount(uint256 _minimumswapbackamount) external onlyOwner { 2039 | mintokenswapback = _minimumswapbackamount; 2040 | } 2041 | 2042 | function setIsFeeExempt(address holder, bool exempt) external onlyOwner { 2043 | isFeeExempt[holder] = exempt; 2044 | } 2045 | 2046 | function setSwapBackSettings(bool _enabled) external onlyOwner { 2047 | swapEnabled = _enabled; 2048 | } 2049 | 2050 | function setAddLiquidityEnabled(bool _enabled) external onlyOwner { 2051 | addLiquidityEnabled = _enabled; 2052 | } 2053 | 2054 | function setAutoBuyBackEnabled(bool _enabled) external onlyOwner { 2055 | autoBuyBackEnabled = _enabled; 2056 | } 2057 | 2058 | function setRecordBuyEnabled(bool _enabled) external onlyOwner { 2059 | RecordBuyEnabled = _enabled; 2060 | } 2061 | 2062 | function isPair(address account) public view returns (bool) { 2063 | return _pairs.contains(account); 2064 | } 2065 | 2066 | function addPair(address pair) public onlyOwner returns (bool) { 2067 | require(pair != address(0), "pair is the zero address"); 2068 | return _pairs.add(pair); 2069 | } 2070 | 2071 | function delPair(address pair) public onlyOwner returns (bool) { 2072 | require(pair != address(0), "pair is the zero address"); 2073 | return _pairs.remove(pair); 2074 | } 2075 | 2076 | function getMinterLength() public view returns (uint256) { 2077 | return _pairs.length(); 2078 | } 2079 | 2080 | function getPair(uint256 index) public view returns (address) { 2081 | require(index <= _pairs.length() - 1, "index out of bounds"); 2082 | return _pairs.at(index); 2083 | } 2084 | 2085 | receive() external payable {} 2086 | } -------------------------------------------------------------------------------- /LIQUIDITY-TREASURY.sol: -------------------------------------------------------------------------------- 1 | // $AFFI LIQUIDITY TREASURY 2 | 3 | // SPDX-License-Identifier: MIT 4 | // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) 5 | 6 | pragma solidity ^0.8.0; 7 | 8 | /** 9 | * @dev Interface of the ERC20 standard as defined in the EIP. 10 | */ 11 | interface IERC20 { 12 | /** 13 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 14 | * another (`to`). 15 | * 16 | * Note that `value` may be zero. 17 | */ 18 | event Transfer(address indexed from, address indexed to, uint256 value); 19 | 20 | /** 21 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 22 | * a call to {approve}. `value` is the new allowance. 23 | */ 24 | event Approval(address indexed owner, address indexed spender, uint256 value); 25 | 26 | /** 27 | * @dev Returns the amount of tokens in existence. 28 | */ 29 | function totalSupply() external view returns (uint256); 30 | 31 | /** 32 | * @dev Returns the amount of tokens owned by `account`. 33 | */ 34 | function balanceOf(address account) external view returns (uint256); 35 | 36 | /** 37 | * @dev Moves `amount` tokens from the caller's account to `to`. 38 | * 39 | * Returns a boolean value indicating whether the operation succeeded. 40 | * 41 | * Emits a {Transfer} event. 42 | */ 43 | function transfer(address to, uint256 amount) external returns (bool); 44 | 45 | /** 46 | * @dev Returns the remaining number of tokens that `spender` will be 47 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 48 | * zero by default. 49 | * 50 | * This value changes when {approve} or {transferFrom} are called. 51 | */ 52 | function allowance(address owner, address spender) external view returns (uint256); 53 | 54 | /** 55 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 56 | * 57 | * Returns a boolean value indicating whether the operation succeeded. 58 | * 59 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 60 | * that someone may use both the old and the new allowance by unfortunate 61 | * transaction ordering. One possible solution to mitigate this race 62 | * condition is to first reduce the spender's allowance to 0 and set the 63 | * desired value afterwards: 64 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 65 | * 66 | * Emits an {Approval} event. 67 | */ 68 | function approve(address spender, uint256 amount) external returns (bool); 69 | 70 | /** 71 | * @dev Moves `amount` tokens from `from` to `to` using the 72 | * allowance mechanism. `amount` is then deducted from the caller's 73 | * allowance. 74 | * 75 | * Returns a boolean value indicating whether the operation succeeded. 76 | * 77 | * Emits a {Transfer} event. 78 | */ 79 | function transferFrom( 80 | address from, 81 | address to, 82 | uint256 amount 83 | ) external returns (bool); 84 | } 85 | 86 | // File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol 87 | 88 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) 89 | 90 | pragma solidity ^0.8.0; 91 | 92 | /** 93 | * @dev Interface for the optional metadata functions from the ERC20 standard. 94 | * 95 | * _Available since v4.1._ 96 | */ 97 | interface IERC20Metadata is IERC20 { 98 | /** 99 | * @dev Returns the name of the token. 100 | */ 101 | function name() external view returns (string memory); 102 | 103 | /** 104 | * @dev Returns the symbol of the token. 105 | */ 106 | function symbol() external view returns (string memory); 107 | 108 | /** 109 | * @dev Returns the decimals places of the token. 110 | */ 111 | function decimals() external view returns (uint8); 112 | } 113 | 114 | // File: @openzeppelin/contracts/utils/Context.sol 115 | 116 | // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) 117 | 118 | pragma solidity ^0.8.0; 119 | 120 | /** 121 | * @dev Provides information about the current execution context, including the 122 | * sender of the transaction and its data. While these are generally available 123 | * via msg.sender and msg.data, they should not be accessed in such a direct 124 | * manner, since when dealing with meta-transactions the account sending and 125 | * paying for execution may not be the actual sender (as far as an application 126 | * is concerned). 127 | * 128 | * This contract is only required for intermediate, library-like contracts. 129 | */ 130 | abstract contract Context { 131 | function _msgSender() internal view virtual returns (address) { 132 | return msg.sender; 133 | } 134 | 135 | function _msgData() internal view virtual returns (bytes calldata) { 136 | return msg.data; 137 | } 138 | } 139 | 140 | // File: @openzeppelin/contracts/token/ERC20/ERC20.sol 141 | 142 | // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol) 143 | 144 | pragma solidity ^0.8.0; 145 | 146 | 147 | 148 | /** 149 | * @dev Implementation of the {IERC20} interface. 150 | * 151 | * This implementation is agnostic to the way tokens are created. This means 152 | * that a supply mechanism has to be added in a derived contract using {_mint}. 153 | * For a generic mechanism see {ERC20PresetMinterPauser}. 154 | * 155 | * TIP: For a detailed writeup see our guide 156 | * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How 157 | * to implement supply mechanisms]. 158 | * 159 | * We have followed general OpenZeppelin Contracts guidelines: functions revert 160 | * instead returning `false` on failure. This behavior is nonetheless 161 | * conventional and does not conflict with the expectations of ERC20 162 | * applications. 163 | * 164 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 165 | * This allows applications to reconstruct the allowance for all accounts just 166 | * by listening to said events. Other implementations of the EIP may not emit 167 | * these events, as it isn't required by the specification. 168 | * 169 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 170 | * functions have been added to mitigate the well-known issues around setting 171 | * allowances. See {IERC20-approve}. 172 | */ 173 | contract ERC20 is Context, IERC20, IERC20Metadata { 174 | mapping(address => uint256) private _balances; 175 | 176 | mapping(address => mapping(address => uint256)) private _allowances; 177 | 178 | uint256 private _totalSupply; 179 | 180 | string private _name; 181 | string private _symbol; 182 | 183 | /** 184 | * @dev Sets the values for {name} and {symbol}. 185 | * 186 | * The default value of {decimals} is 18. To select a different value for 187 | * {decimals} you should overload it. 188 | * 189 | * All two of these values are immutable: they can only be set once during 190 | * construction. 191 | */ 192 | constructor(string memory name_, string memory symbol_) { 193 | _name = name_; 194 | _symbol = symbol_; 195 | } 196 | 197 | /** 198 | * @dev Returns the name of the token. 199 | */ 200 | function name() public view virtual override returns (string memory) { 201 | return _name; 202 | } 203 | 204 | /** 205 | * @dev Returns the symbol of the token, usually a shorter version of the 206 | * name. 207 | */ 208 | function symbol() public view virtual override returns (string memory) { 209 | return _symbol; 210 | } 211 | 212 | /** 213 | * @dev Returns the number of decimals used to get its user representation. 214 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 215 | * be displayed to a user as `5.05` (`505 / 10 ** 2`). 216 | * 217 | * Tokens usually opt for a value of 18, imitating the relationship between 218 | * Ether and Wei. This is the value {ERC20} uses, unless this function is 219 | * overridden; 220 | * 221 | * NOTE: This information is only used for _display_ purposes: it in 222 | * no way affects any of the arithmetic of the contract, including 223 | * {IERC20-balanceOf} and {IERC20-transfer}. 224 | */ 225 | function decimals() public view virtual override returns (uint8) { 226 | return 18; 227 | } 228 | 229 | /** 230 | * @dev See {IERC20-totalSupply}. 231 | */ 232 | function totalSupply() public view virtual override returns (uint256) { 233 | return _totalSupply; 234 | } 235 | 236 | /** 237 | * @dev See {IERC20-balanceOf}. 238 | */ 239 | function balanceOf(address account) public view virtual override returns (uint256) { 240 | return _balances[account]; 241 | } 242 | 243 | /** 244 | * @dev See {IERC20-transfer}. 245 | * 246 | * Requirements: 247 | * 248 | * - `to` cannot be the zero address. 249 | * - the caller must have a balance of at least `amount`. 250 | */ 251 | function transfer(address to, uint256 amount) public virtual override returns (bool) { 252 | address owner = _msgSender(); 253 | _transfer(owner, to, amount); 254 | return true; 255 | } 256 | 257 | /** 258 | * @dev See {IERC20-allowance}. 259 | */ 260 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 261 | return _allowances[owner][spender]; 262 | } 263 | 264 | /** 265 | * @dev See {IERC20-approve}. 266 | * 267 | * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on 268 | * `transferFrom`. This is semantically equivalent to an infinite approval. 269 | * 270 | * Requirements: 271 | * 272 | * - `spender` cannot be the zero address. 273 | */ 274 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 275 | address owner = _msgSender(); 276 | _approve(owner, spender, amount); 277 | return true; 278 | } 279 | 280 | /** 281 | * @dev See {IERC20-transferFrom}. 282 | * 283 | * Emits an {Approval} event indicating the updated allowance. This is not 284 | * required by the EIP. See the note at the beginning of {ERC20}. 285 | * 286 | * NOTE: Does not update the allowance if the current allowance 287 | * is the maximum `uint256`. 288 | * 289 | * Requirements: 290 | * 291 | * - `from` and `to` cannot be the zero address. 292 | * - `from` must have a balance of at least `amount`. 293 | * - the caller must have allowance for ``from``'s tokens of at least 294 | * `amount`. 295 | */ 296 | function transferFrom( 297 | address from, 298 | address to, 299 | uint256 amount 300 | ) public virtual override returns (bool) { 301 | address spender = _msgSender(); 302 | _spendAllowance(from, spender, amount); 303 | _transfer(from, to, amount); 304 | return true; 305 | } 306 | 307 | /** 308 | * @dev Atomically increases the allowance granted to `spender` by the caller. 309 | * 310 | * This is an alternative to {approve} that can be used as a mitigation for 311 | * problems described in {IERC20-approve}. 312 | * 313 | * Emits an {Approval} event indicating the updated allowance. 314 | * 315 | * Requirements: 316 | * 317 | * - `spender` cannot be the zero address. 318 | */ 319 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 320 | address owner = _msgSender(); 321 | _approve(owner, spender, allowance(owner, spender) + addedValue); 322 | return true; 323 | } 324 | 325 | /** 326 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 327 | * 328 | * This is an alternative to {approve} that can be used as a mitigation for 329 | * problems described in {IERC20-approve}. 330 | * 331 | * Emits an {Approval} event indicating the updated allowance. 332 | * 333 | * Requirements: 334 | * 335 | * - `spender` cannot be the zero address. 336 | * - `spender` must have allowance for the caller of at least 337 | * `subtractedValue`. 338 | */ 339 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 340 | address owner = _msgSender(); 341 | uint256 currentAllowance = allowance(owner, spender); 342 | require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); 343 | unchecked { 344 | _approve(owner, spender, currentAllowance - subtractedValue); 345 | } 346 | 347 | return true; 348 | } 349 | 350 | /** 351 | * @dev Moves `amount` of tokens from `from` to `to`. 352 | * 353 | * This internal function is equivalent to {transfer}, and can be used to 354 | * e.g. implement automatic token fees, slashing mechanisms, etc. 355 | * 356 | * Emits a {Transfer} event. 357 | * 358 | * Requirements: 359 | * 360 | * - `from` cannot be the zero address. 361 | * - `to` cannot be the zero address. 362 | * - `from` must have a balance of at least `amount`. 363 | */ 364 | function _transfer( 365 | address from, 366 | address to, 367 | uint256 amount 368 | ) internal virtual { 369 | require(from != address(0), "ERC20: transfer from the zero address"); 370 | require(to != address(0), "ERC20: transfer to the zero address"); 371 | 372 | _beforeTokenTransfer(from, to, amount); 373 | 374 | uint256 fromBalance = _balances[from]; 375 | require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); 376 | unchecked { 377 | _balances[from] = fromBalance - amount; 378 | // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by 379 | // decrementing then incrementing. 380 | _balances[to] += amount; 381 | } 382 | 383 | emit Transfer(from, to, amount); 384 | 385 | _afterTokenTransfer(from, to, amount); 386 | } 387 | 388 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 389 | * the total supply. 390 | * 391 | * Emits a {Transfer} event with `from` set to the zero address. 392 | * 393 | * Requirements: 394 | * 395 | * - `account` cannot be the zero address. 396 | */ 397 | function _mint(address account, uint256 amount) internal virtual { 398 | require(account != address(0), "ERC20: mint to the zero address"); 399 | 400 | _beforeTokenTransfer(address(0), account, amount); 401 | 402 | _totalSupply += amount; 403 | unchecked { 404 | // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above. 405 | _balances[account] += amount; 406 | } 407 | emit Transfer(address(0), account, amount); 408 | 409 | _afterTokenTransfer(address(0), account, amount); 410 | } 411 | 412 | /** 413 | * @dev Destroys `amount` tokens from `account`, reducing the 414 | * total supply. 415 | * 416 | * Emits a {Transfer} event with `to` set to the zero address. 417 | * 418 | * Requirements: 419 | * 420 | * - `account` cannot be the zero address. 421 | * - `account` must have at least `amount` tokens. 422 | */ 423 | function _burn(address account, uint256 amount) internal virtual { 424 | require(account != address(0), "ERC20: burn from the zero address"); 425 | 426 | _beforeTokenTransfer(account, address(0), amount); 427 | 428 | uint256 accountBalance = _balances[account]; 429 | require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); 430 | unchecked { 431 | _balances[account] = accountBalance - amount; 432 | // Overflow not possible: amount <= accountBalance <= totalSupply. 433 | _totalSupply -= amount; 434 | } 435 | 436 | emit Transfer(account, address(0), amount); 437 | 438 | _afterTokenTransfer(account, address(0), amount); 439 | } 440 | 441 | /** 442 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 443 | * 444 | * This internal function is equivalent to `approve`, and can be used to 445 | * e.g. set automatic allowances for certain subsystems, etc. 446 | * 447 | * Emits an {Approval} event. 448 | * 449 | * Requirements: 450 | * 451 | * - `owner` cannot be the zero address. 452 | * - `spender` cannot be the zero address. 453 | */ 454 | function _approve( 455 | address owner, 456 | address spender, 457 | uint256 amount 458 | ) internal virtual { 459 | require(owner != address(0), "ERC20: approve from the zero address"); 460 | require(spender != address(0), "ERC20: approve to the zero address"); 461 | 462 | _allowances[owner][spender] = amount; 463 | emit Approval(owner, spender, amount); 464 | } 465 | 466 | /** 467 | * @dev Updates `owner` s allowance for `spender` based on spent `amount`. 468 | * 469 | * Does not update the allowance amount in case of infinite allowance. 470 | * Revert if not enough allowance is available. 471 | * 472 | * Might emit an {Approval} event. 473 | */ 474 | function _spendAllowance( 475 | address owner, 476 | address spender, 477 | uint256 amount 478 | ) internal virtual { 479 | uint256 currentAllowance = allowance(owner, spender); 480 | if (currentAllowance != type(uint256).max) { 481 | require(currentAllowance >= amount, "ERC20: insufficient allowance"); 482 | unchecked { 483 | _approve(owner, spender, currentAllowance - amount); 484 | } 485 | } 486 | } 487 | 488 | /** 489 | * @dev Hook that is called before any transfer of tokens. This includes 490 | * minting and burning. 491 | * 492 | * Calling conditions: 493 | * 494 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 495 | * will be transferred to `to`. 496 | * - when `from` is zero, `amount` tokens will be minted for `to`. 497 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 498 | * - `from` and `to` are never both zero. 499 | * 500 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 501 | */ 502 | function _beforeTokenTransfer( 503 | address from, 504 | address to, 505 | uint256 amount 506 | ) internal virtual {} 507 | 508 | /** 509 | * @dev Hook that is called after any transfer of tokens. This includes 510 | * minting and burning. 511 | * 512 | * Calling conditions: 513 | * 514 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 515 | * has been transferred to `to`. 516 | * - when `from` is zero, `amount` tokens have been minted for `to`. 517 | * - when `to` is zero, `amount` of ``from``'s tokens have been burned. 518 | * - `from` and `to` are never both zero. 519 | * 520 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 521 | */ 522 | function _afterTokenTransfer( 523 | address from, 524 | address to, 525 | uint256 amount 526 | ) internal virtual {} 527 | } 528 | 529 | // File: @openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol 530 | 531 | // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) 532 | 533 | pragma solidity ^0.8.0; 534 | 535 | /** 536 | * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in 537 | * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. 538 | * 539 | * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by 540 | * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't 541 | * need to send a transaction, and thus is not required to hold Ether at all. 542 | */ 543 | interface IERC20Permit { 544 | /** 545 | * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, 546 | * given ``owner``'s signed approval. 547 | * 548 | * IMPORTANT: The same issues {IERC20-approve} has related to transaction 549 | * ordering also apply here. 550 | * 551 | * Emits an {Approval} event. 552 | * 553 | * Requirements: 554 | * 555 | * - `spender` cannot be the zero address. 556 | * - `deadline` must be a timestamp in the future. 557 | * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` 558 | * over the EIP712-formatted function arguments. 559 | * - the signature must use ``owner``'s current nonce (see {nonces}). 560 | * 561 | * For more information on the signature format, see the 562 | * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP 563 | * section]. 564 | */ 565 | function permit( 566 | address owner, 567 | address spender, 568 | uint256 value, 569 | uint256 deadline, 570 | uint8 v, 571 | bytes32 r, 572 | bytes32 s 573 | ) external; 574 | 575 | /** 576 | * @dev Returns the current nonce for `owner`. This value must be 577 | * included whenever a signature is generated for {permit}. 578 | * 579 | * Every successful call to {permit} increases ``owner``'s nonce by one. This 580 | * prevents a signature from being used multiple times. 581 | */ 582 | function nonces(address owner) external view returns (uint256); 583 | 584 | /** 585 | * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. 586 | */ 587 | // solhint-disable-next-line func-name-mixedcase 588 | function DOMAIN_SEPARATOR() external view returns (bytes32); 589 | } 590 | 591 | // File: @openzeppelin/contracts/utils/Address.sol 592 | 593 | // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) 594 | 595 | pragma solidity ^0.8.1; 596 | 597 | /** 598 | * @dev Collection of functions related to the address type 599 | */ 600 | library Address { 601 | /** 602 | * @dev Returns true if `account` is a contract. 603 | * 604 | * [IMPORTANT] 605 | * ==== 606 | * It is unsafe to assume that an address for which this function returns 607 | * false is an externally-owned account (EOA) and not a contract. 608 | * 609 | * Among others, `isContract` will return false for the following 610 | * types of addresses: 611 | * 612 | * - an externally-owned account 613 | * - a contract in construction 614 | * - an address where a contract will be created 615 | * - an address where a contract lived, but was destroyed 616 | * ==== 617 | * 618 | * [IMPORTANT] 619 | * ==== 620 | * You shouldn't rely on `isContract` to protect against flash loan attacks! 621 | * 622 | * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets 623 | * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract 624 | * constructor. 625 | * ==== 626 | */ 627 | function isContract(address account) internal view returns (bool) { 628 | // This method relies on extcodesize/address.code.length, which returns 0 629 | // for contracts in construction, since the code is only stored at the end 630 | // of the constructor execution. 631 | 632 | return account.code.length > 0; 633 | } 634 | 635 | /** 636 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 637 | * `recipient`, forwarding all available gas and reverting on errors. 638 | * 639 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 640 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 641 | * imposed by `transfer`, making them unable to receive funds via 642 | * `transfer`. {sendValue} removes this limitation. 643 | * 644 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 645 | * 646 | * IMPORTANT: because control is transferred to `recipient`, care must be 647 | * taken to not create reentrancy vulnerabilities. Consider using 648 | * {ReentrancyGuard} or the 649 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 650 | */ 651 | function sendValue(address payable recipient, uint256 amount) internal { 652 | require(address(this).balance >= amount, "Address: insufficient balance"); 653 | 654 | (bool success, ) = recipient.call{value: amount}(""); 655 | require(success, "Address: unable to send value, recipient may have reverted"); 656 | } 657 | 658 | /** 659 | * @dev Performs a Solidity function call using a low level `call`. A 660 | * plain `call` is an unsafe replacement for a function call: use this 661 | * function instead. 662 | * 663 | * If `target` reverts with a revert reason, it is bubbled up by this 664 | * function (like regular Solidity function calls). 665 | * 666 | * Returns the raw returned data. To convert to the expected return value, 667 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 668 | * 669 | * Requirements: 670 | * 671 | * - `target` must be a contract. 672 | * - calling `target` with `data` must not revert. 673 | * 674 | * _Available since v3.1._ 675 | */ 676 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 677 | return functionCallWithValue(target, data, 0, "Address: low-level call failed"); 678 | } 679 | 680 | /** 681 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 682 | * `errorMessage` as a fallback revert reason when `target` reverts. 683 | * 684 | * _Available since v3.1._ 685 | */ 686 | function functionCall( 687 | address target, 688 | bytes memory data, 689 | string memory errorMessage 690 | ) internal returns (bytes memory) { 691 | return functionCallWithValue(target, data, 0, errorMessage); 692 | } 693 | 694 | /** 695 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 696 | * but also transferring `value` wei to `target`. 697 | * 698 | * Requirements: 699 | * 700 | * - the calling contract must have an ETH balance of at least `value`. 701 | * - the called Solidity function must be `payable`. 702 | * 703 | * _Available since v3.1._ 704 | */ 705 | function functionCallWithValue( 706 | address target, 707 | bytes memory data, 708 | uint256 value 709 | ) internal returns (bytes memory) { 710 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 711 | } 712 | 713 | /** 714 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 715 | * with `errorMessage` as a fallback revert reason when `target` reverts. 716 | * 717 | * _Available since v3.1._ 718 | */ 719 | function functionCallWithValue( 720 | address target, 721 | bytes memory data, 722 | uint256 value, 723 | string memory errorMessage 724 | ) internal returns (bytes memory) { 725 | require(address(this).balance >= value, "Address: insufficient balance for call"); 726 | (bool success, bytes memory returndata) = target.call{value: value}(data); 727 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 728 | } 729 | 730 | /** 731 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 732 | * but performing a static call. 733 | * 734 | * _Available since v3.3._ 735 | */ 736 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 737 | return functionStaticCall(target, data, "Address: low-level static call failed"); 738 | } 739 | 740 | /** 741 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 742 | * but performing a static call. 743 | * 744 | * _Available since v3.3._ 745 | */ 746 | function functionStaticCall( 747 | address target, 748 | bytes memory data, 749 | string memory errorMessage 750 | ) internal view returns (bytes memory) { 751 | (bool success, bytes memory returndata) = target.staticcall(data); 752 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 753 | } 754 | 755 | /** 756 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 757 | * but performing a delegate call. 758 | * 759 | * _Available since v3.4._ 760 | */ 761 | function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { 762 | return functionDelegateCall(target, data, "Address: low-level delegate call failed"); 763 | } 764 | 765 | /** 766 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 767 | * but performing a delegate call. 768 | * 769 | * _Available since v3.4._ 770 | */ 771 | function functionDelegateCall( 772 | address target, 773 | bytes memory data, 774 | string memory errorMessage 775 | ) internal returns (bytes memory) { 776 | (bool success, bytes memory returndata) = target.delegatecall(data); 777 | return verifyCallResultFromTarget(target, success, returndata, errorMessage); 778 | } 779 | 780 | /** 781 | * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling 782 | * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. 783 | * 784 | * _Available since v4.8._ 785 | */ 786 | function verifyCallResultFromTarget( 787 | address target, 788 | bool success, 789 | bytes memory returndata, 790 | string memory errorMessage 791 | ) internal view returns (bytes memory) { 792 | if (success) { 793 | if (returndata.length == 0) { 794 | // only check isContract if the call was successful and the return data is empty 795 | // otherwise we already know that it was a contract 796 | require(isContract(target), "Address: call to non-contract"); 797 | } 798 | return returndata; 799 | } else { 800 | _revert(returndata, errorMessage); 801 | } 802 | } 803 | 804 | /** 805 | * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the 806 | * revert reason or using the provided one. 807 | * 808 | * _Available since v4.3._ 809 | */ 810 | function verifyCallResult( 811 | bool success, 812 | bytes memory returndata, 813 | string memory errorMessage 814 | ) internal pure returns (bytes memory) { 815 | if (success) { 816 | return returndata; 817 | } else { 818 | _revert(returndata, errorMessage); 819 | } 820 | } 821 | 822 | function _revert(bytes memory returndata, string memory errorMessage) private pure { 823 | // Look for revert reason and bubble it up if present 824 | if (returndata.length > 0) { 825 | // The easiest way to bubble the revert reason is using memory via assembly 826 | /// @solidity memory-safe-assembly 827 | assembly { 828 | let returndata_size := mload(returndata) 829 | revert(add(32, returndata), returndata_size) 830 | } 831 | } else { 832 | revert(errorMessage); 833 | } 834 | } 835 | } 836 | 837 | // File: @openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol 838 | 839 | // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) 840 | 841 | pragma solidity ^0.8.0; 842 | 843 | 844 | 845 | /** 846 | * @title SafeERC20 847 | * @dev Wrappers around ERC20 operations that throw on failure (when the token 848 | * contract returns false). Tokens that return no value (and instead revert or 849 | * throw on failure) are also supported, non-reverting calls are assumed to be 850 | * successful. 851 | * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, 852 | * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. 853 | */ 854 | library SafeERC20 { 855 | using Address for address; 856 | 857 | function safeTransfer( 858 | IERC20 token, 859 | address to, 860 | uint256 value 861 | ) internal { 862 | _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); 863 | } 864 | 865 | function safeTransferFrom( 866 | IERC20 token, 867 | address from, 868 | address to, 869 | uint256 value 870 | ) internal { 871 | _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); 872 | } 873 | 874 | /** 875 | * @dev Deprecated. This function has issues similar to the ones found in 876 | * {IERC20-approve}, and its usage is discouraged. 877 | * 878 | * Whenever possible, use {safeIncreaseAllowance} and 879 | * {safeDecreaseAllowance} instead. 880 | */ 881 | function safeApprove( 882 | IERC20 token, 883 | address spender, 884 | uint256 value 885 | ) internal { 886 | // safeApprove should only be called when setting an initial allowance, 887 | // or when resetting it to zero. To increase and decrease it, use 888 | // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' 889 | require( 890 | (value == 0) || (token.allowance(address(this), spender) == 0), 891 | "SafeERC20: approve from non-zero to non-zero allowance" 892 | ); 893 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); 894 | } 895 | 896 | function safeIncreaseAllowance( 897 | IERC20 token, 898 | address spender, 899 | uint256 value 900 | ) internal { 901 | uint256 newAllowance = token.allowance(address(this), spender) + value; 902 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 903 | } 904 | 905 | function safeDecreaseAllowance( 906 | IERC20 token, 907 | address spender, 908 | uint256 value 909 | ) internal { 910 | unchecked { 911 | uint256 oldAllowance = token.allowance(address(this), spender); 912 | require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); 913 | uint256 newAllowance = oldAllowance - value; 914 | _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); 915 | } 916 | } 917 | 918 | function safePermit( 919 | IERC20Permit token, 920 | address owner, 921 | address spender, 922 | uint256 value, 923 | uint256 deadline, 924 | uint8 v, 925 | bytes32 r, 926 | bytes32 s 927 | ) internal { 928 | uint256 nonceBefore = token.nonces(owner); 929 | token.permit(owner, spender, value, deadline, v, r, s); 930 | uint256 nonceAfter = token.nonces(owner); 931 | require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); 932 | } 933 | 934 | /** 935 | * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement 936 | * on the return value: the return value is optional (but if data is returned, it must not be false). 937 | * @param token The token targeted by the call. 938 | * @param data The call data (encoded using abi.encode or one of its variants). 939 | */ 940 | function _callOptionalReturn(IERC20 token, bytes memory data) private { 941 | // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since 942 | // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that 943 | // the target address contains contract code and also asserts for success in the low-level call. 944 | 945 | bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); 946 | if (returndata.length > 0) { 947 | // Return data is optional 948 | require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); 949 | } 950 | } 951 | } 952 | 953 | // File: @openzeppelin/contracts/access/Ownable.sol 954 | 955 | // OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol) 956 | 957 | pragma solidity ^0.8.0; 958 | 959 | /** 960 | * @dev Contract module which provides a basic access control mechanism, where 961 | * there is an account (an owner) that can be granted exclusive access to 962 | * specific functions. 963 | * 964 | * By default, the owner account will be the one that deploys the contract. This 965 | * can later be changed with {transferOwnership}. 966 | * 967 | * This module is used through inheritance. It will make available the modifier 968 | * `onlyOwner`, which can be applied to your functions to restrict their use to 969 | * the owner. 970 | */ 971 | abstract contract Ownable is Context { 972 | address private _owner; 973 | 974 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 975 | 976 | /** 977 | * @dev Initializes the contract setting the deployer as the initial owner. 978 | */ 979 | constructor() { 980 | _transferOwnership(_msgSender()); 981 | } 982 | 983 | /** 984 | * @dev Throws if called by any account other than the owner. 985 | */ 986 | modifier onlyOwner() { 987 | _checkOwner(); 988 | _; 989 | } 990 | 991 | /** 992 | * @dev Returns the address of the current owner. 993 | */ 994 | function owner() public view virtual returns (address) { 995 | return _owner; 996 | } 997 | 998 | /** 999 | * @dev Throws if the sender is not the owner. 1000 | */ 1001 | function _checkOwner() internal view virtual { 1002 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 1003 | } 1004 | 1005 | /** 1006 | * @dev Leaves the contract without owner. It will not be possible to call 1007 | * `onlyOwner` functions anymore. Can only be called by the current owner. 1008 | * 1009 | * NOTE: Renouncing ownership will leave the contract without an owner, 1010 | * thereby removing any functionality that is only available to the owner. 1011 | */ 1012 | function renounceOwnership() public virtual onlyOwner { 1013 | _transferOwnership(address(0)); 1014 | } 1015 | 1016 | /** 1017 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 1018 | * Can only be called by the current owner. 1019 | */ 1020 | function transferOwnership(address newOwner) public virtual onlyOwner { 1021 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 1022 | _transferOwnership(newOwner); 1023 | } 1024 | 1025 | /** 1026 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 1027 | * Internal function without access restriction. 1028 | */ 1029 | function _transferOwnership(address newOwner) internal virtual { 1030 | address oldOwner = _owner; 1031 | _owner = newOwner; 1032 | emit OwnershipTransferred(oldOwner, newOwner); 1033 | } 1034 | } 1035 | 1036 | // File: @openzeppelin/contracts/utils/structs/EnumerableSet.sol 1037 | 1038 | // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) 1039 | // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. 1040 | 1041 | pragma solidity ^0.8.0; 1042 | 1043 | /** 1044 | * @dev Library for managing 1045 | * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive 1046 | * types. 1047 | * 1048 | * Sets have the following properties: 1049 | * 1050 | * - Elements are added, removed, and checked for existence in constant time 1051 | * (O(1)). 1052 | * - Elements are enumerated in O(n). No guarantees are made on the ordering. 1053 | * 1054 | * ``` 1055 | * contract Example { 1056 | * // Add the library methods 1057 | * using EnumerableSet for EnumerableSet.AddressSet; 1058 | * 1059 | * // Declare a set state variable 1060 | * EnumerableSet.AddressSet private mySet; 1061 | * } 1062 | * ``` 1063 | * 1064 | * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) 1065 | * and `uint256` (`UintSet`) are supported. 1066 | * 1067 | * [WARNING] 1068 | * ==== 1069 | * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure 1070 | * unusable. 1071 | * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. 1072 | * 1073 | * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an 1074 | * array of EnumerableSet. 1075 | * ==== 1076 | */ 1077 | library EnumerableSet { 1078 | // To implement this library for multiple types with as little code 1079 | // repetition as possible, we write it in terms of a generic Set type with 1080 | // bytes32 values. 1081 | // The Set implementation uses private functions, and user-facing 1082 | // implementations (such as AddressSet) are just wrappers around the 1083 | // underlying Set. 1084 | // This means that we can only create new EnumerableSets for types that fit 1085 | // in bytes32. 1086 | 1087 | struct Set { 1088 | // Storage of set values 1089 | bytes32[] _values; 1090 | // Position of the value in the `values` array, plus 1 because index 0 1091 | // means a value is not in the set. 1092 | mapping(bytes32 => uint256) _indexes; 1093 | } 1094 | 1095 | /** 1096 | * @dev Add a value to a set. O(1). 1097 | * 1098 | * Returns true if the value was added to the set, that is if it was not 1099 | * already present. 1100 | */ 1101 | function _add(Set storage set, bytes32 value) private returns (bool) { 1102 | if (!_contains(set, value)) { 1103 | set._values.push(value); 1104 | // The value is stored at length-1, but we add 1 to all indexes 1105 | // and use 0 as a sentinel value 1106 | set._indexes[value] = set._values.length; 1107 | return true; 1108 | } else { 1109 | return false; 1110 | } 1111 | } 1112 | 1113 | /** 1114 | * @dev Removes a value from a set. O(1). 1115 | * 1116 | * Returns true if the value was removed from the set, that is if it was 1117 | * present. 1118 | */ 1119 | function _remove(Set storage set, bytes32 value) private returns (bool) { 1120 | // We read and store the value's index to prevent multiple reads from the same storage slot 1121 | uint256 valueIndex = set._indexes[value]; 1122 | 1123 | if (valueIndex != 0) { 1124 | // Equivalent to contains(set, value) 1125 | // To delete an element from the _values array in O(1), we swap the element to delete with the last one in 1126 | // the array, and then remove the last element (sometimes called as 'swap and pop'). 1127 | // This modifies the order of the array, as noted in {at}. 1128 | 1129 | uint256 toDeleteIndex = valueIndex - 1; 1130 | uint256 lastIndex = set._values.length - 1; 1131 | 1132 | if (lastIndex != toDeleteIndex) { 1133 | bytes32 lastValue = set._values[lastIndex]; 1134 | 1135 | // Move the last value to the index where the value to delete is 1136 | set._values[toDeleteIndex] = lastValue; 1137 | // Update the index for the moved value 1138 | set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex 1139 | } 1140 | 1141 | // Delete the slot where the moved value was stored 1142 | set._values.pop(); 1143 | 1144 | // Delete the index for the deleted slot 1145 | delete set._indexes[value]; 1146 | 1147 | return true; 1148 | } else { 1149 | return false; 1150 | } 1151 | } 1152 | 1153 | /** 1154 | * @dev Returns true if the value is in the set. O(1). 1155 | */ 1156 | function _contains(Set storage set, bytes32 value) private view returns (bool) { 1157 | return set._indexes[value] != 0; 1158 | } 1159 | 1160 | /** 1161 | * @dev Returns the number of values on the set. O(1). 1162 | */ 1163 | function _length(Set storage set) private view returns (uint256) { 1164 | return set._values.length; 1165 | } 1166 | 1167 | /** 1168 | * @dev Returns the value stored at position `index` in the set. O(1). 1169 | * 1170 | * Note that there are no guarantees on the ordering of values inside the 1171 | * array, and it may change when more values are added or removed. 1172 | * 1173 | * Requirements: 1174 | * 1175 | * - `index` must be strictly less than {length}. 1176 | */ 1177 | function _at(Set storage set, uint256 index) private view returns (bytes32) { 1178 | return set._values[index]; 1179 | } 1180 | 1181 | /** 1182 | * @dev Return the entire set in an array 1183 | * 1184 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1185 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1186 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1187 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1188 | */ 1189 | function _values(Set storage set) private view returns (bytes32[] memory) { 1190 | return set._values; 1191 | } 1192 | 1193 | // Bytes32Set 1194 | 1195 | struct Bytes32Set { 1196 | Set _inner; 1197 | } 1198 | 1199 | /** 1200 | * @dev Add a value to a set. O(1). 1201 | * 1202 | * Returns true if the value was added to the set, that is if it was not 1203 | * already present. 1204 | */ 1205 | function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { 1206 | return _add(set._inner, value); 1207 | } 1208 | 1209 | /** 1210 | * @dev Removes a value from a set. O(1). 1211 | * 1212 | * Returns true if the value was removed from the set, that is if it was 1213 | * present. 1214 | */ 1215 | function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { 1216 | return _remove(set._inner, value); 1217 | } 1218 | 1219 | /** 1220 | * @dev Returns true if the value is in the set. O(1). 1221 | */ 1222 | function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { 1223 | return _contains(set._inner, value); 1224 | } 1225 | 1226 | /** 1227 | * @dev Returns the number of values in the set. O(1). 1228 | */ 1229 | function length(Bytes32Set storage set) internal view returns (uint256) { 1230 | return _length(set._inner); 1231 | } 1232 | 1233 | /** 1234 | * @dev Returns the value stored at position `index` in the set. O(1). 1235 | * 1236 | * Note that there are no guarantees on the ordering of values inside the 1237 | * array, and it may change when more values are added or removed. 1238 | * 1239 | * Requirements: 1240 | * 1241 | * - `index` must be strictly less than {length}. 1242 | */ 1243 | function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { 1244 | return _at(set._inner, index); 1245 | } 1246 | 1247 | /** 1248 | * @dev Return the entire set in an array 1249 | * 1250 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1251 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1252 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1253 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1254 | */ 1255 | function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { 1256 | bytes32[] memory store = _values(set._inner); 1257 | bytes32[] memory result; 1258 | 1259 | /// @solidity memory-safe-assembly 1260 | assembly { 1261 | result := store 1262 | } 1263 | 1264 | return result; 1265 | } 1266 | 1267 | // AddressSet 1268 | 1269 | struct AddressSet { 1270 | Set _inner; 1271 | } 1272 | 1273 | /** 1274 | * @dev Add a value to a set. O(1). 1275 | * 1276 | * Returns true if the value was added to the set, that is if it was not 1277 | * already present. 1278 | */ 1279 | function add(AddressSet storage set, address value) internal returns (bool) { 1280 | return _add(set._inner, bytes32(uint256(uint160(value)))); 1281 | } 1282 | 1283 | /** 1284 | * @dev Removes a value from a set. O(1). 1285 | * 1286 | * Returns true if the value was removed from the set, that is if it was 1287 | * present. 1288 | */ 1289 | function remove(AddressSet storage set, address value) internal returns (bool) { 1290 | return _remove(set._inner, bytes32(uint256(uint160(value)))); 1291 | } 1292 | 1293 | /** 1294 | * @dev Returns true if the value is in the set. O(1). 1295 | */ 1296 | function contains(AddressSet storage set, address value) internal view returns (bool) { 1297 | return _contains(set._inner, bytes32(uint256(uint160(value)))); 1298 | } 1299 | 1300 | /** 1301 | * @dev Returns the number of values in the set. O(1). 1302 | */ 1303 | function length(AddressSet storage set) internal view returns (uint256) { 1304 | return _length(set._inner); 1305 | } 1306 | 1307 | /** 1308 | * @dev Returns the value stored at position `index` in the set. O(1). 1309 | * 1310 | * Note that there are no guarantees on the ordering of values inside the 1311 | * array, and it may change when more values are added or removed. 1312 | * 1313 | * Requirements: 1314 | * 1315 | * - `index` must be strictly less than {length}. 1316 | */ 1317 | function at(AddressSet storage set, uint256 index) internal view returns (address) { 1318 | return address(uint160(uint256(_at(set._inner, index)))); 1319 | } 1320 | 1321 | /** 1322 | * @dev Return the entire set in an array 1323 | * 1324 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1325 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1326 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1327 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1328 | */ 1329 | function values(AddressSet storage set) internal view returns (address[] memory) { 1330 | bytes32[] memory store = _values(set._inner); 1331 | address[] memory result; 1332 | 1333 | /// @solidity memory-safe-assembly 1334 | assembly { 1335 | result := store 1336 | } 1337 | 1338 | return result; 1339 | } 1340 | 1341 | // UintSet 1342 | 1343 | struct UintSet { 1344 | Set _inner; 1345 | } 1346 | 1347 | /** 1348 | * @dev Add a value to a set. O(1). 1349 | * 1350 | * Returns true if the value was added to the set, that is if it was not 1351 | * already present. 1352 | */ 1353 | function add(UintSet storage set, uint256 value) internal returns (bool) { 1354 | return _add(set._inner, bytes32(value)); 1355 | } 1356 | 1357 | /** 1358 | * @dev Removes a value from a set. O(1). 1359 | * 1360 | * Returns true if the value was removed from the set, that is if it was 1361 | * present. 1362 | */ 1363 | function remove(UintSet storage set, uint256 value) internal returns (bool) { 1364 | return _remove(set._inner, bytes32(value)); 1365 | } 1366 | 1367 | /** 1368 | * @dev Returns true if the value is in the set. O(1). 1369 | */ 1370 | function contains(UintSet storage set, uint256 value) internal view returns (bool) { 1371 | return _contains(set._inner, bytes32(value)); 1372 | } 1373 | 1374 | /** 1375 | * @dev Returns the number of values in the set. O(1). 1376 | */ 1377 | function length(UintSet storage set) internal view returns (uint256) { 1378 | return _length(set._inner); 1379 | } 1380 | 1381 | /** 1382 | * @dev Returns the value stored at position `index` in the set. O(1). 1383 | * 1384 | * Note that there are no guarantees on the ordering of values inside the 1385 | * array, and it may change when more values are added or removed. 1386 | * 1387 | * Requirements: 1388 | * 1389 | * - `index` must be strictly less than {length}. 1390 | */ 1391 | function at(UintSet storage set, uint256 index) internal view returns (uint256) { 1392 | return uint256(_at(set._inner, index)); 1393 | } 1394 | 1395 | /** 1396 | * @dev Return the entire set in an array 1397 | * 1398 | * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed 1399 | * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that 1400 | * this function has an unbounded cost, and using it as part of a state-changing function may render the function 1401 | * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. 1402 | */ 1403 | function values(UintSet storage set) internal view returns (uint256[] memory) { 1404 | bytes32[] memory store = _values(set._inner); 1405 | uint256[] memory result; 1406 | 1407 | /// @solidity memory-safe-assembly 1408 | assembly { 1409 | result := store 1410 | } 1411 | 1412 | return result; 1413 | } 1414 | } 1415 | 1416 | // File: contracts/interfaces/ICamelotFactory.sol 1417 | 1418 | 1419 | pragma solidity >=0.5.0; 1420 | 1421 | interface ICamelotFactory { 1422 | event PairCreated( 1423 | address indexed token0, 1424 | address indexed token1, 1425 | address pair, 1426 | uint256 1427 | ); 1428 | 1429 | function owner() external view returns (address); 1430 | 1431 | function feePercentOwner() external view returns (address); 1432 | 1433 | function setStableOwner() external view returns (address); 1434 | 1435 | function feeTo() external view returns (address); 1436 | 1437 | function ownerFeeShare() external view returns (uint256); 1438 | 1439 | function referrersFeeShare(address) external view returns (uint256); 1440 | 1441 | function getPair( 1442 | address tokenA, 1443 | address tokenB 1444 | ) external view returns (address pair); 1445 | 1446 | function allPairs(uint256) external view returns (address pair); 1447 | 1448 | function allPairsLength() external view returns (uint256); 1449 | 1450 | function createPair( 1451 | address tokenA, 1452 | address tokenB 1453 | ) external returns (address pair); 1454 | 1455 | function setFeeTo(address) external; 1456 | 1457 | function feeInfo() 1458 | external 1459 | view 1460 | returns (uint _ownerFeeShare, address _feeTo); 1461 | } 1462 | 1463 | // File: contracts/interfaces/IUniswapV2Router01.sol 1464 | 1465 | 1466 | pragma solidity >=0.6.2; 1467 | 1468 | interface IUniswapV2Router01 { 1469 | function factory() external pure returns (address); 1470 | 1471 | function WETH() external pure returns (address); 1472 | 1473 | function addLiquidity( 1474 | address tokenA, 1475 | address tokenB, 1476 | uint amountADesired, 1477 | uint amountBDesired, 1478 | uint amountAMin, 1479 | uint amountBMin, 1480 | address to, 1481 | uint deadline 1482 | ) external returns (uint amountA, uint amountB, uint liquidity); 1483 | 1484 | function addLiquidityETH( 1485 | address token, 1486 | uint amountTokenDesired, 1487 | uint amountTokenMin, 1488 | uint amountETHMin, 1489 | address to, 1490 | uint deadline 1491 | ) 1492 | external 1493 | payable 1494 | returns (uint amountToken, uint amountETH, uint liquidity); 1495 | 1496 | function removeLiquidity( 1497 | address tokenA, 1498 | address tokenB, 1499 | uint liquidity, 1500 | uint amountAMin, 1501 | uint amountBMin, 1502 | address to, 1503 | uint deadline 1504 | ) external returns (uint amountA, uint amountB); 1505 | 1506 | function removeLiquidityETH( 1507 | address token, 1508 | uint liquidity, 1509 | uint amountTokenMin, 1510 | uint amountETHMin, 1511 | address to, 1512 | uint deadline 1513 | ) external returns (uint amountToken, uint amountETH); 1514 | 1515 | function removeLiquidityWithPermit( 1516 | address tokenA, 1517 | address tokenB, 1518 | uint liquidity, 1519 | uint amountAMin, 1520 | uint amountBMin, 1521 | address to, 1522 | uint deadline, 1523 | bool approveMax, 1524 | uint8 v, 1525 | bytes32 r, 1526 | bytes32 s 1527 | ) external returns (uint amountA, uint amountB); 1528 | 1529 | function removeLiquidityETHWithPermit( 1530 | address token, 1531 | uint liquidity, 1532 | uint amountTokenMin, 1533 | uint amountETHMin, 1534 | address to, 1535 | uint deadline, 1536 | bool approveMax, 1537 | uint8 v, 1538 | bytes32 r, 1539 | bytes32 s 1540 | ) external returns (uint amountToken, uint amountETH); 1541 | 1542 | function quote( 1543 | uint amountA, 1544 | uint reserveA, 1545 | uint reserveB 1546 | ) external pure returns (uint amountB); 1547 | 1548 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 1549 | uint256 amountIn, 1550 | uint256 amountOutMin, 1551 | address[] calldata path, 1552 | address to, 1553 | uint256 deadline 1554 | ) external; 1555 | 1556 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 1557 | uint amountIn, 1558 | uint amountOutMin, 1559 | address[] calldata path, 1560 | address to, 1561 | uint deadline 1562 | ) external; 1563 | } 1564 | 1565 | // File: contracts/interfaces/ICamelotRouter.sol 1566 | 1567 | 1568 | pragma solidity >=0.6.2; 1569 | 1570 | interface ICamelotRouter is IUniswapV2Router01 { 1571 | function removeLiquidityETHSupportingFeeOnTransferTokens( 1572 | address token, 1573 | uint liquidity, 1574 | uint amountTokenMin, 1575 | uint amountETHMin, 1576 | address to, 1577 | uint deadline 1578 | ) external returns (uint amountETH); 1579 | 1580 | function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( 1581 | address token, 1582 | uint liquidity, 1583 | uint amountTokenMin, 1584 | uint amountETHMin, 1585 | address to, 1586 | uint deadline, 1587 | bool approveMax, 1588 | uint8 v, 1589 | bytes32 r, 1590 | bytes32 s 1591 | ) external returns (uint amountETH); 1592 | 1593 | function swapExactTokensForTokensSupportingFeeOnTransferTokens( 1594 | uint amountIn, 1595 | uint amountOutMin, 1596 | address[] calldata path, 1597 | address to, 1598 | address referrer, 1599 | uint deadline 1600 | ) external; 1601 | 1602 | function swapExactETHForTokensSupportingFeeOnTransferTokens( 1603 | uint amountOutMin, 1604 | address[] calldata path, 1605 | address to, 1606 | address referrer, 1607 | uint deadline 1608 | ) external payable; 1609 | 1610 | function swapExactTokensForETHSupportingFeeOnTransferTokens( 1611 | uint amountIn, 1612 | uint amountOutMin, 1613 | address[] calldata path, 1614 | address to, 1615 | address referrer, 1616 | uint deadline 1617 | ) external; 1618 | 1619 | function getAmountsOut( 1620 | uint amountIn, 1621 | address[] calldata path 1622 | ) external view returns (uint[] memory amounts); 1623 | } 1624 | 1625 | // File: contracts/interfaces/IWETH.sol 1626 | 1627 | 1628 | pragma solidity >=0.5.0; 1629 | 1630 | interface IWETH { 1631 | function totalSupply() external view returns (uint256); 1632 | 1633 | function balanceOf(address account) external view returns (uint256); 1634 | 1635 | function allowance(address owner, address spender) external view returns (uint256); 1636 | 1637 | function approve(address spender, uint256 amount) external returns (bool); 1638 | 1639 | function deposit() external payable; 1640 | 1641 | function transfer(address to, uint256 value) external returns (bool); 1642 | 1643 | function withdraw(uint256) external; 1644 | } 1645 | 1646 | 1647 | pragma solidity =0.8.19; 1648 | 1649 | contract AFFILIQUIDITYTREASURY is Ownable { 1650 | using SafeERC20 for IERC20; 1651 | using EnumerableSet for EnumerableSet.AddressSet; 1652 | 1653 | event SwapBack(uint256 burn, uint256 liquidity, uint256 jackpot, uint256 bonus, uint256 dev, uint timestamp); 1654 | event Trade(address user, address pair, uint256 amount, uint side, uint256 circulatingSupply, uint timestamp); 1655 | event AddLiquidity(uint256 tokenAmount, uint256 ethAmount, uint256 timestamp); 1656 | event BuyBack(uint256 ethAmount, uint256 timestamp); 1657 | 1658 | 1659 | bool public inSwap; 1660 | modifier swapping() { 1661 | inSwap = true; 1662 | _; 1663 | inSwap = false; 1664 | } 1665 | 1666 | ICamelotRouter private immutable swapRouter; 1667 | IERC20 public USDT; 1668 | IERC20 public swappingToken; 1669 | EnumerableSet.AddressSet private _callers; 1670 | 1671 | modifier onlyCaller() { 1672 | require(_callers.contains(_msgSender()), "onlyCaller"); 1673 | _; 1674 | } 1675 | 1676 | constructor( 1677 | address _swapRouter, 1678 | address _USDT 1679 | ) { 1680 | swapRouter = ICamelotRouter(_swapRouter); 1681 | USDT = IERC20(_USDT); 1682 | } 1683 | 1684 | function autoAddLiquidity(address contractA, address contractB, uint256 tokenAmountA) external onlyCaller() { 1685 | uint256 USDTAmount = USDT.balanceOf(address(this)); 1686 | USDT.approve(address(swapRouter), USDTAmount); //approve tokenAmountB USDT 1687 | try swapRouter.addLiquidity(contractA, contractB, tokenAmountA, USDTAmount, 0, 0, address(0), block.timestamp) { 1688 | emit AddLiquidity(tokenAmountA, USDTAmount, block.timestamp); 1689 | } catch {} 1690 | } 1691 | 1692 | function addCaller(address val) external onlyOwner() { 1693 | require(val != address(0), "LIQUIDITYADDER: val is the zero address"); 1694 | _callers.add(val); 1695 | } 1696 | 1697 | function delCaller(address caller) external onlyOwner returns (bool) { 1698 | require(caller != address(0), "LIQUIDITYADDER: caller is the zero address"); 1699 | return _callers.remove(caller); 1700 | } 1701 | 1702 | function getCallers() external view returns (address[] memory ret) { 1703 | return _callers.values(); 1704 | } 1705 | 1706 | function rescueToken(address tokenAddress) external onlyOwner { 1707 | //can withdraw stuck tokens in contract 1708 | IERC20(tokenAddress).safeTransfer(msg.sender,IERC20(tokenAddress).balanceOf(address(this))); 1709 | } 1710 | 1711 | function clearStuckEthBalance() external onlyOwner { 1712 | //can withdraw stuck eth in contract 1713 | uint256 amountETH = address(this).balance; 1714 | (bool success, ) = payable(_msgSender()).call{value: amountETH}(new bytes(0)); 1715 | require(success, 'ETH_TRANSFER_FAILED'); 1716 | } 1717 | 1718 | 1719 | } -------------------------------------------------------------------------------- /LUCKYDROP-CONTRACT.sol: -------------------------------------------------------------------------------- 1 | /* 2 | ██████╗░██╗░░░██╗██╗░░░██╗  ░█████╗░███████╗███████╗██╗ 3 | ██╔══██╗██║░░░██║╚██╗░██╔╝  ██╔══██╗██╔════╝██╔════╝██║ 4 | ██████╦╝██║░░░██║░╚████╔╝░  ███████║█████╗░░█████╗░░██║ 5 | ██╔══██╗██║░░░██║░░╚██╔╝░░  ██╔══██║██╔══╝░░██╔══╝░░██║ 6 | ██████╦╝╚██████╔╝░░░██║░░░  ██║░░██║██║░░░░░██║░░░░░██║ 7 | ╚═════╝░░╚═════╝░░░░╚═╝░░░  ╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚═╝ 8 | 9 | ███████╗░█████╗░██████╗░███╗░░██╗  ██╗░░░██╗░██████╗██████╗░░█████╗░ 10 | ██╔════╝██╔══██╗██╔══██╗████╗░██║  ██║░░░██║██╔════╝██╔══██╗██╔══██╗ 11 | █████╗░░███████║██████╔╝██╔██╗██║  ██║░░░██║╚█████╗░██║░░██║██║░░╚═╝ 12 | ██╔══╝░░██╔══██║██╔══██╗██║╚████║  ██║░░░██║░╚═══██╗██║░░██║██║░░██╗ 13 | ███████╗██║░░██║██║░░██║██║░╚███║  ╚██████╔╝██████╔╝██████╔╝╚█████╔╝ 14 | 15 | **Rewarding the highest buyer every 30minutes with $USDC 16 | **Lets trade $AFFI shall we!!! 17 | */ 18 | 19 | // SPDX-License-Identifier: MIT 20 | 21 | pragma solidity 0.6.12; 22 | 23 | /** 24 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 25 | * checks. 26 | * 27 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 28 | * in bugs, because programmers usually assume that an overflow raises an 29 | * error, which is the standard behavior in high level programming languages. 30 | * `SafeMath` restores this intuition by reverting the transaction when an 31 | * operation overflows. 32 | * 33 | * Using this library instead of the unchecked operations eliminates an entire 34 | * class of bugs, so it's recommended to use it always. 35 | */ 36 | library SafeMath { 37 | /** 38 | * @dev Returns the addition of two unsigned integers, reverting on 39 | * overflow. 40 | * 41 | * Counterpart to Solidity's `+` operator. 42 | * 43 | * Requirements: 44 | * - Addition cannot overflow. 45 | */ 46 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 47 | uint256 c = a + b; 48 | require(c >= a, 'SafeMath: addition overflow'); 49 | 50 | return c; 51 | } 52 | 53 | /** 54 | * @dev Returns the subtraction of two unsigned integers, reverting on 55 | * overflow (when the result is negative). 56 | * 57 | * Counterpart to Solidity's `-` operator. 58 | * 59 | * Requirements: 60 | * - Subtraction cannot overflow. 61 | */ 62 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 63 | return sub(a, b, 'SafeMath: subtraction overflow'); 64 | } 65 | 66 | /** 67 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 68 | * overflow (when the result is negative). 69 | * 70 | * Counterpart to Solidity's `-` operator. 71 | * 72 | * Requirements: 73 | * - Subtraction cannot overflow. 74 | */ 75 | function sub( 76 | uint256 a, 77 | uint256 b, 78 | string memory errorMessage 79 | ) internal pure returns (uint256) { 80 | require(b <= a, errorMessage); 81 | uint256 c = a - b; 82 | 83 | return c; 84 | } 85 | 86 | /** 87 | * @dev Returns the multiplication of two unsigned integers, reverting on 88 | * overflow. 89 | * 90 | * Counterpart to Solidity's `*` operator. 91 | * 92 | * Requirements: 93 | * - Multiplication cannot overflow. 94 | */ 95 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 96 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 97 | // benefit is lost if 'b' is also tested. 98 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 99 | if (a == 0) { 100 | return 0; 101 | } 102 | 103 | uint256 c = a * b; 104 | require(c / a == b, 'SafeMath: multiplication overflow'); 105 | 106 | return c; 107 | } 108 | 109 | /** 110 | * @dev Returns the integer division of two unsigned integers. Reverts on 111 | * division by zero. The result is rounded towards zero. 112 | * 113 | * Counterpart to Solidity's `/` operator. Note: this function uses a 114 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 115 | * uses an invalid opcode to revert (consuming all remaining gas). 116 | * 117 | * Requirements: 118 | * - The divisor cannot be zero. 119 | */ 120 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 121 | return div(a, b, 'SafeMath: division by zero'); 122 | } 123 | 124 | /** 125 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 126 | * division by zero. The result is rounded towards zero. 127 | * 128 | * Counterpart to Solidity's `/` operator. Note: this function uses a 129 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 130 | * uses an invalid opcode to revert (consuming all remaining gas). 131 | * 132 | * Requirements: 133 | * - The divisor cannot be zero. 134 | */ 135 | function div( 136 | uint256 a, 137 | uint256 b, 138 | string memory errorMessage 139 | ) internal pure returns (uint256) { 140 | // Solidity only automatically asserts when dividing by 0 141 | require(b > 0, errorMessage); 142 | uint256 c = a / b; 143 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 144 | 145 | return c; 146 | } 147 | 148 | /** 149 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 150 | * Reverts when dividing by zero. 151 | * 152 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 153 | * opcode (which leaves remaining gas untouched) while Solidity uses an 154 | * invalid opcode to revert (consuming all remaining gas). 155 | * 156 | * Requirements: 157 | * - The divisor cannot be zero. 158 | */ 159 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 160 | return mod(a, b, 'SafeMath: modulo by zero'); 161 | } 162 | 163 | /** 164 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 165 | * Reverts with custom message when dividing by zero. 166 | * 167 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 168 | * opcode (which leaves remaining gas untouched) while Solidity uses an 169 | * invalid opcode to revert (consuming all remaining gas). 170 | * 171 | * Requirements: 172 | * - The divisor cannot be zero. 173 | */ 174 | function mod( 175 | uint256 a, 176 | uint256 b, 177 | string memory errorMessage 178 | ) internal pure returns (uint256) { 179 | require(b != 0, errorMessage); 180 | return a % b; 181 | } 182 | } 183 | 184 | 185 | pragma solidity 0.6.12; 186 | 187 | /** 188 | * @dev Interface of the ERC20 standard as defined in the EIP. 189 | * From https://github.com/OpenZeppelin/openzeppelin-contracts 190 | */ 191 | interface IERC20 { 192 | /** 193 | * @dev Returns the amount of tokens in existence. 194 | */ 195 | function totalSupply() external view returns (uint256); 196 | 197 | /** 198 | * @dev Returns the amount of tokens owned by `account`. 199 | */ 200 | function balanceOf(address account) external view returns (uint256); 201 | 202 | /** 203 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 204 | * 205 | * Returns a boolean value indicating whether the operation succeeded. 206 | * 207 | * Emits a {Transfer} event. 208 | */ 209 | function transfer(address recipient, uint256 amount) external returns (bool); 210 | 211 | /** 212 | * @dev Returns the remaining number of tokens that `spender` will be 213 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 214 | * zero by default. 215 | * 216 | * This value changes when {approve} or {transferFrom} are called. 217 | */ 218 | function allowance(address owner, address spender) external view returns (uint256); 219 | 220 | /** 221 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 222 | * 223 | * Returns a boolean value indicating whether the operation succeeded. 224 | * 225 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 226 | * that someone may use both the old and the new allowance by unfortunate 227 | * transaction ordering. One possible solution to mitigate this race 228 | * condition is to first reduce the spender's allowance to 0 and set the 229 | * desired value afterwards: 230 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 231 | * 232 | * Emits an {Approval} event. 233 | */ 234 | function approve(address spender, uint256 amount) external returns (bool); 235 | 236 | /** 237 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 238 | * allowance mechanism. `amount` is then deducted from the caller's 239 | * allowance. 240 | * 241 | * Returns a boolean value indicating whether the operation succeeded. 242 | * 243 | * Emits a {Transfer} event. 244 | */ 245 | function transferFrom( 246 | address sender, 247 | address recipient, 248 | uint256 amount 249 | ) external returns (bool); 250 | 251 | /** 252 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 253 | * another (`to`). 254 | * 255 | * Note that `value` may be zero. 256 | */ 257 | event Transfer(address indexed from, address indexed to, uint256 value); 258 | 259 | /** 260 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 261 | * a call to {approve}. `value` is the new allowance. 262 | */ 263 | event Approval(address indexed owner, address indexed spender, uint256 value); 264 | } 265 | 266 | 267 | pragma solidity >=0.6.2 <0.8.0; 268 | 269 | /** 270 | * @dev Collection of functions related to the address type 271 | */ 272 | library Address { 273 | function isContract(address account) internal view returns (bool) { 274 | // This method relies on extcodesize, which returns 0 for contracts in 275 | // construction, since the code is only stored at the end of the 276 | // constructor execution. 277 | 278 | uint256 size; 279 | // solhint-disable-next-line no-inline-assembly 280 | assembly { size := extcodesize(account) } 281 | return size > 0; 282 | } 283 | 284 | function sendValue(address payable recipient, uint256 amount) internal { 285 | require(address(this).balance >= amount, "Address: insufficient balance"); 286 | 287 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 288 | (bool success, ) = recipient.call{ value: amount }(""); 289 | require(success, "Address: unable to send value, recipient may have reverted"); 290 | } 291 | 292 | } 293 | 294 | pragma solidity 0.6.12; 295 | 296 | /** 297 | * @dev Interface of the SellToken standard as defined in the EIP. 298 | * From https://github.com/OpenZeppelin/openzeppelin-contracts 299 | */ 300 | interface ISellToken { 301 | /** 302 | * @dev Returns the amount of tokens in existence. 303 | */ 304 | function receivedAmount(address recipient) external view returns (uint256); 305 | function balanceOf(address recipient) external view returns (uint256); 306 | 307 | } 308 | 309 | 310 | // solhint-disable-next-line compiler-version 311 | pragma solidity >=0.4.24 <0.8.0; 312 | 313 | //import "../utils/Address.sol"; 314 | 315 | /** 316 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 317 | * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an 318 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 319 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 320 | * 321 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 322 | * possible by providing the encoded function call as the `_data` argument to {UpgradeableProxy-constructor}. 323 | * 324 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 325 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 326 | */ 327 | abstract contract Initializable { 328 | 329 | /** 330 | * @dev Indicates that the contract has been initialized. 331 | */ 332 | bool private _initialized; 333 | 334 | /** 335 | * @dev Indicates that the contract is in the process of being initialized. 336 | */ 337 | bool private _initializing; 338 | 339 | /** 340 | * @dev Modifier to protect an initializer function from being invoked twice. 341 | */ 342 | modifier initializer() { 343 | require(_initializing || _isConstructor() || !_initialized, "Initializable: contract is already initialized"); 344 | 345 | bool isTopLevelCall = !_initializing; 346 | if (isTopLevelCall) { 347 | _initializing = true; 348 | _initialized = true; 349 | } 350 | 351 | _; 352 | 353 | if (isTopLevelCall) { 354 | _initializing = false; 355 | } 356 | } 357 | 358 | /// @dev Returns true if and only if the function is running in the constructor 359 | function _isConstructor() private view returns (bool) { 360 | return !Address.isContract(address(this)); 361 | } 362 | } 363 | 364 | 365 | 366 | pragma solidity 0.6.12; 367 | 368 | 369 | contract AFFILuckydrop is Initializable { 370 | using SafeMath for uint256; 371 | // Todo : Update when deploy to production 372 | 373 | address public ADMIN; //deployer of this contract; 374 | address public AUTHORIZED_CALLER; //official token contract 375 | address public REWARD_TOKEN; //busd or usdt or token for reward 376 | mapping (uint => address) private playeraddr; 377 | mapping (uint => uint256) private playeramount; 378 | mapping (address => uint256) public totalWalletWon; 379 | uint private playersavedlevel = 1; 380 | uint public limit = 5; 381 | bool public jackpotsystem = true; 382 | address private constant DEAD = 0x000000000000000000000000000000000000dEaD; 383 | address private constant ZERO = 0x0000000000000000000000000000000000000000; 384 | 385 | address private currleaderwallet; 386 | uint256 private currleadertokenpurchased; 387 | 388 | address private lastleaderwallet; 389 | uint256 private lastleaderamountwon; 390 | 391 | uint256 public nextdistributetime; 392 | uint256 public timedifference; 393 | uint public currentround; 394 | uint public totalplayers; 395 | 396 | uint256 public totalusdtwon; 397 | uint256 public lastusdtwon; 398 | 399 | modifier onlyAdmin() { 400 | require(msg.sender == ADMIN, 'INVALID ADMIN'); 401 | _; 402 | } 403 | 404 | modifier onlyAuthorizedCaller() { 405 | require(msg.sender == AUTHORIZED_CALLER, 'INVALID AUTHORIZED CALLER'); 406 | _; 407 | } 408 | 409 | event Winner(address winner, uint256 amountwon, uint timestamp); 410 | 411 | constructor() public {} 412 | 413 | function Bootup( 414 | address _Admin, 415 | address _RewardToken, 416 | address _AuthorizedCaller, 417 | uint256 _timedifference 418 | ) public initializer { 419 | ADMIN = _Admin; 420 | AUTHORIZED_CALLER = _AuthorizedCaller; 421 | REWARD_TOKEN = _RewardToken; 422 | timedifference = _timedifference; 423 | } 424 | 425 | 426 | function lottery(address wallet, uint256 amountpurchased) public onlyAuthorizedCaller { 427 | //a players wallet is recorded as a player, and a leader if no body else exceeds his buy amount. 428 | if (amountpurchased > currleadertokenpurchased && wallet != ZERO && jackpotsystem == true) { 429 | //new leader detected, push winner updards and replace the currleadertokenpurchased. 430 | currleaderwallet = wallet; 431 | currleadertokenpurchased = amountpurchased; 432 | totalplayers ++; 433 | } 434 | 435 | //update playersavedlevel 436 | playeraddr[playersavedlevel] = wallet; 437 | playeramount[playersavedlevel] = amountpurchased; 438 | if (playersavedlevel < limit) { 439 | playersavedlevel ++; 440 | } 441 | 442 | 443 | //if time has exceeded, pay current leader and reset all values 444 | if (jackpotsystem == true && block.timestamp > nextdistributetime) { 445 | //time has exceeded, pay current leader 446 | uint256 initialtimestamp = block.timestamp; 447 | uint256 tokensincontract = IERC20(REWARD_TOKEN).balanceOf(address(this)); 448 | address winnerswallet = currleaderwallet; 449 | currleaderwallet = ZERO; //address(0) 450 | nextdistributetime = initialtimestamp + timedifference; 451 | lastleaderwallet = winnerswallet; //save last winner wallet 452 | lastleaderamountwon = currleadertokenpurchased; //save last leader usdt 453 | currleadertokenpurchased = 0; 454 | playersavedlevel = 1; 455 | currentround ++; 456 | 457 | if (tokensincontract > 0) { 458 | IERC20(REWARD_TOKEN).transfer(winnerswallet, tokensincontract); 459 | totalusdtwon += tokensincontract; 460 | lastusdtwon = tokensincontract; 461 | totalWalletWon[winnerswallet] += tokensincontract; 462 | emit Winner(winnerswallet, tokensincontract, initialtimestamp); 463 | } 464 | } 465 | } 466 | 467 | 468 | function erasetotalenteries() public onlyAdmin { 469 | playersavedlevel = 1; 470 | } 471 | function updatejackpotsystem(bool _status) public onlyAdmin { 472 | jackpotsystem = _status; //enables or disables jackpot 473 | } 474 | 475 | function updateCurrLimit(uint _limit) public onlyAdmin { 476 | limit = _limit; 477 | } 478 | 479 | function updateAuthorizedCaller(address authorized_caller) public onlyAdmin { 480 | AUTHORIZED_CALLER = authorized_caller; 481 | } 482 | 483 | function updateTimedifference(uint _timedifference) public onlyAdmin { 484 | timedifference = _timedifference; //increase or decrease next pay time 485 | } 486 | 487 | function getplayer(uint rowtofetch) external view returns(address, uint256) { 488 | return (playeraddr[rowtofetch], playeramount[rowtofetch]); 489 | } 490 | 491 | function getLastwinner() external view returns(address, uint256) { 492 | return (lastleaderwallet, lastleaderamountwon); 493 | } 494 | 495 | function getCurrwinner() external view returns(address, uint256) { 496 | return (currleaderwallet, currleadertokenpurchased); 497 | } 498 | 499 | function currentrow() external view returns(uint) { 500 | return playersavedlevel; 501 | } 502 | 503 | function currentcontractrewardbal() external view returns(uint256) { 504 | return IERC20(REWARD_TOKEN).balanceOf(address(this)); 505 | } 506 | 507 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Hi there Welcome to our official github👋 2 | 3 | 17 | --------------------------------------------------------------------------------