Advertisement
VNDL_Kapper

KarmaV3

May 5th, 2021
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.98 KB | None | 0 0
  1. /**
  2. *Submitted for verification at Etherscan.io on 2021-05-05
  3. */
  4.  
  5. // Copyright [2021] - [2021], [Shaun Reed] and [Karma] contributors
  6. // SPDX-License-Identifier: MIT
  7.  
  8. pragma solidity >= 0.8.0;
  9.  
  10. // ----------------------------------------------------------------------------
  11. // Import ERC Token Standard #20 Interface
  12. // ETH EIP repo: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
  13. // ----------------------------------------------------------------------------
  14. pragma solidity ^0.8.0;
  15.  
  16. /**
  17. * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
  18. * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
  19. * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
  20. * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
  21. *
  22. * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
  23. * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
  24. *
  25. * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
  26. * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
  27. */
  28. abstract contract Initializable {
  29.  
  30. /**
  31. * @dev Indicates that the contract has been initialized.
  32. */
  33. bool private _initialized;
  34.  
  35. /**
  36. * @dev Indicates that the contract is in the process of being initialized.
  37. */
  38. bool private _initializing;
  39.  
  40. /**
  41. * @dev Modifier to protect an initializer function from being invoked twice.
  42. */
  43. modifier initializer() {
  44. require(_initializing || !_initialized, "Initializable: contract is already initialized");
  45.  
  46. bool isTopLevelCall = !_initializing;
  47. if (isTopLevelCall) {
  48. _initializing = true;
  49. _initialized = true;
  50. }
  51.  
  52. _;
  53.  
  54. if (isTopLevelCall) {
  55. _initializing = false;
  56. }
  57. }
  58. }
  59.  
  60.  
  61. /**
  62. * @dev Interface of the ERC20 standard as defined in the EIP.
  63. */
  64. interface IERC20Upgradeable {
  65. /**
  66. * @dev Returns the amount of tokens in existence.
  67. */
  68. function totalSupply() external view returns (uint256);
  69.  
  70. /**
  71. * @dev Returns the amount of tokens owned by `account`.
  72. */
  73. function balanceOf(address account) external view returns (uint256);
  74.  
  75. /**
  76. * @dev Moves `amount` tokens from the caller's account to `recipient`.
  77. *
  78. * Returns a boolean value indicating whether the operation succeeded.
  79. *
  80. * Emits a {Transfer} event.
  81. */
  82. function transfer(address recipient, uint256 amount) external returns (bool);
  83.  
  84. /**
  85. * @dev Returns the remaining number of tokens that `spender` will be
  86. * allowed to spend on behalf of `owner` through {transferFrom}. This is
  87. * zero by default.
  88. *
  89. * This value changes when {approve} or {transferFrom} are called.
  90. */
  91. function allowance(address owner, address spender) external view returns (uint256);
  92.  
  93. /**
  94. * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
  95. *
  96. * Returns a boolean value indicating whether the operation succeeded.
  97. *
  98. * IMPORTANT: Beware that changing an allowance with this method brings the risk
  99. * that someone may use both the old and the new allowance by unfortunate
  100. * transaction ordering. One possible solution to mitigate this race
  101. * condition is to first reduce the spender's allowance to 0 and set the
  102. * desired value afterwards:
  103. * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  104. *
  105. * Emits an {Approval} event.
  106. */
  107. function approve(address spender, uint256 amount) external returns (bool);
  108.  
  109. /**
  110. * @dev Moves `amount` tokens from `sender` to `recipient` using the
  111. * allowance mechanism. `amount` is then deducted from the caller's
  112. * allowance.
  113. *
  114. * Returns a boolean value indicating whether the operation succeeded.
  115. *
  116. * Emits a {Transfer} event.
  117. */
  118. function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
  119.  
  120. /**
  121. * @dev Emitted when `value` tokens are moved from one account (`from`) to
  122. * another (`to`).
  123. *
  124. * Note that `value` may be zero.
  125. */
  126. event Transfer(address indexed from, address indexed to, uint256 value);
  127.  
  128. /**
  129. * @dev Emitted when the allowance of a `spender` for an `owner` is set by
  130. * a call to {approve}. `value` is the new allowance.
  131. */
  132. event Approval(address indexed owner, address indexed spender, uint256 value);
  133. }
  134.  
  135. /**
  136. * @dev Interface for the optional metadata functions from the ERC20 standard.
  137. *
  138. * _Available since v4.1._
  139. */
  140. interface IERC20MetadataUpgradeable is IERC20Upgradeable {
  141. /**
  142. * @dev Returns the name of the token.
  143. */
  144. function name() external view returns (string memory);
  145.  
  146. /**
  147. * @dev Returns the symbol of the token.
  148. */
  149. function symbol() external view returns (string memory);
  150.  
  151. /**
  152. * @dev Returns the decimals places of the token.
  153. */
  154. function decimals() external view returns (uint8);
  155. }
  156.  
  157. pragma solidity ^0.8.0;
  158. /*
  159. * @dev Provides information about the current execution context, including the
  160. * sender of the transaction and its data. While these are generally available
  161. * via msg.sender and msg.data, they should not be accessed in such a direct
  162. * manner, since when dealing with meta-transactions the account sending and
  163. * paying for execution may not be the actual sender (as far as an application
  164. * is concerned).
  165. *
  166. * This contract is only required for intermediate, library-like contracts.
  167. */
  168. abstract contract ContextUpgradeable is Initializable {
  169. function __Context_init() internal initializer {
  170. __Context_init_unchained();
  171. }
  172.  
  173. function __Context_init_unchained() internal initializer {
  174. }
  175. function _msgSender() internal view virtual returns (address) {
  176. return msg.sender;
  177. }
  178.  
  179. function _msgData() internal view virtual returns (bytes calldata) {
  180. this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
  181. return msg.data;
  182. }
  183. uint256[50] private __gap;
  184. }
  185.  
  186. pragma solidity ^0.8.0;
  187. /**
  188. * @dev Implementation of the {IERC20} interface.
  189. *
  190. * This implementation is agnostic to the way tokens are created. This means
  191. * that a supply mechanism has to be added in a derived contract using {_mint}.
  192. * For a generic mechanism see {ERC20PresetMinterPauser}.
  193. *
  194. * TIP: For a detailed writeup see our guide
  195. * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
  196. * to implement supply mechanisms].
  197. *
  198. * We have followed general OpenZeppelin guidelines: functions revert instead
  199. * of returning `false` on failure. This behavior is nonetheless conventional
  200. * and does not conflict with the expectations of ERC20 applications.
  201. *
  202. * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
  203. * This allows applications to reconstruct the allowance for all accounts just
  204. * by listening to said events. Other implementations of the EIP may not emit
  205. * these events, as it isn't required by the specification.
  206. *
  207. * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
  208. * functions have been added to mitigate the well-known issues around setting
  209. * allowances. See {IERC20-approve}.
  210. */
  211. contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable {
  212. mapping (address => uint256) private _balances;
  213.  
  214. mapping (address => mapping (address => uint256)) private _allowances;
  215.  
  216. uint256 private _totalSupply;
  217.  
  218. string private _name;
  219. string private _symbol;
  220.  
  221. /**
  222. * @dev Sets the values for {name} and {symbol}.
  223. *
  224. * The defaut value of {decimals} is 18. To select a different value for
  225. * {decimals} you should overload it.
  226. *
  227. * All two of these values are immutable: they can only be set once during
  228. * construction.
  229. */
  230. function __ERC20_init(string memory name_, string memory symbol_) internal initializer {
  231. __Context_init_unchained();
  232. __ERC20_init_unchained(name_, symbol_);
  233. }
  234.  
  235. function __ERC20_init_unchained(string memory name_, string memory symbol_) internal initializer {
  236. _name = name_;
  237. _symbol = symbol_;
  238. }
  239.  
  240. /**
  241. * @dev Returns the name of the token.
  242. */
  243. function name() public view virtual override returns (string memory) {
  244. return _name;
  245. }
  246.  
  247. /**
  248. * @dev Returns the symbol of the token, usually a shorter version of the
  249. * name.
  250. */
  251. function symbol() public view virtual override returns (string memory) {
  252. return _symbol;
  253. }
  254.  
  255. /**
  256. * @dev Returns the number of decimals used to get its user representation.
  257. * For example, if `decimals` equals `2`, a balance of `505` tokens should
  258. * be displayed to a user as `5,05` (`505 / 10 ** 2`).
  259. *
  260. * Tokens usually opt for a value of 18, imitating the relationship between
  261. * Ether and Wei. This is the value {ERC20} uses, unless this function is
  262. * overridden;
  263. *
  264. * NOTE: This information is only used for _display_ purposes: it in
  265. * no way affects any of the arithmetic of the contract, including
  266. * {IERC20-balanceOf} and {IERC20-transfer}.
  267. */
  268. function decimals() public view virtual override returns (uint8) {
  269. return 18;
  270. }
  271.  
  272. /**
  273. * @dev See {IERC20-totalSupply}.
  274. */
  275. function totalSupply() public view virtual override returns (uint256) {
  276. return _totalSupply;
  277. }
  278.  
  279. /**
  280. * @dev See {IERC20-balanceOf}.
  281. */
  282. function balanceOf(address account) public view virtual override returns (uint256) {
  283. return _balances[account];
  284. }
  285.  
  286. /**
  287. * @dev See {IERC20-transfer}.
  288. *
  289. * Requirements:
  290. *
  291. * - `recipient` cannot be the zero address.
  292. * - the caller must have a balance of at least `amount`.
  293. */
  294. function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
  295. _transfer(_msgSender(), recipient, amount);
  296. return true;
  297. }
  298.  
  299. /**
  300. * @dev See {IERC20-allowance}.
  301. */
  302. function allowance(address owner, address spender) public view virtual override returns (uint256) {
  303. return _allowances[owner][spender];
  304. }
  305.  
  306. /**
  307. * @dev See {IERC20-approve}.
  308. *
  309. * Requirements:
  310. *
  311. * - `spender` cannot be the zero address.
  312. */
  313. function approve(address spender, uint256 amount) public virtual override returns (bool) {
  314. _approve(_msgSender(), spender, amount);
  315. return true;
  316. }
  317.  
  318. /**
  319. * @dev See {IERC20-transferFrom}.
  320. *
  321. * Emits an {Approval} event indicating the updated allowance. This is not
  322. * required by the EIP. See the note at the beginning of {ERC20}.
  323. *
  324. * Requirements:
  325. *
  326. * - `sender` and `recipient` cannot be the zero address.
  327. * - `sender` must have a balance of at least `amount`.
  328. * - the caller must have allowance for ``sender``'s tokens of at least
  329. * `amount`.
  330. */
  331. function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
  332. _transfer(sender, recipient, amount);
  333.  
  334. uint256 currentAllowance = _allowances[sender][_msgSender()];
  335. require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
  336. _approve(sender, _msgSender(), currentAllowance - amount);
  337.  
  338. return true;
  339. }
  340.  
  341. /**
  342. * @dev Atomically increases the allowance granted to `spender` by the caller.
  343. *
  344. * This is an alternative to {approve} that can be used as a mitigation for
  345. * problems described in {IERC20-approve}.
  346. *
  347. * Emits an {Approval} event indicating the updated allowance.
  348. *
  349. * Requirements:
  350. *
  351. * - `spender` cannot be the zero address.
  352. */
  353. function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
  354. _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);
  355. return true;
  356. }
  357.  
  358. /**
  359. * @dev Atomically decreases the allowance granted to `spender` by the caller.
  360. *
  361. * This is an alternative to {approve} that can be used as a mitigation for
  362. * problems described in {IERC20-approve}.
  363. *
  364. * Emits an {Approval} event indicating the updated allowance.
  365. *
  366. * Requirements:
  367. *
  368. * - `spender` cannot be the zero address.
  369. * - `spender` must have allowance for the caller of at least
  370. * `subtractedValue`.
  371. */
  372. function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
  373. uint256 currentAllowance = _allowances[_msgSender()][spender];
  374. require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
  375. _approve(_msgSender(), spender, currentAllowance - subtractedValue);
  376.  
  377. return true;
  378. }
  379.  
  380. /**
  381. * @dev Moves tokens `amount` from `sender` to `recipient`.
  382. *
  383. * This is internal function is equivalent to {transfer}, and can be used to
  384. * e.g. implement automatic token fees, slashing mechanisms, etc.
  385. *
  386. * Emits a {Transfer} event.
  387. *
  388. * Requirements:
  389. *
  390. * - `sender` cannot be the zero address.
  391. * - `recipient` cannot be the zero address.
  392. * - `sender` must have a balance of at least `amount`.
  393. */
  394. function _transfer(address sender, address recipient, uint256 amount) internal virtual {
  395. require(sender != address(0), "ERC20: transfer from the zero address");
  396. require(recipient != address(0), "ERC20: transfer to the zero address");
  397.  
  398. _beforeTokenTransfer(sender, recipient, amount);
  399.  
  400. uint256 senderBalance = _balances[sender];
  401. require(senderBalance >= amount, "ERC20: transfer amount exceeds balance");
  402. _balances[sender] = senderBalance - amount;
  403. _balances[recipient] += amount;
  404.  
  405. emit Transfer(sender, recipient, amount);
  406. }
  407.  
  408. /** @dev Creates `amount` tokens and assigns them to `account`, increasing
  409. * the total supply.
  410. *
  411. * Emits a {Transfer} event with `from` set to the zero address.
  412. *
  413. * Requirements:
  414. *
  415. * - `to` cannot be the zero address.
  416. */
  417. function _mint(address account, uint256 amount) internal virtual {
  418. require(account != address(0), "ERC20: mint to the zero address");
  419.  
  420. _beforeTokenTransfer(address(0), account, amount);
  421.  
  422. _totalSupply += amount;
  423. _balances[account] += amount;
  424. emit Transfer(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. _balances[account] = accountBalance - amount;
  446. _totalSupply -= amount;
  447.  
  448. emit Transfer(account, address(0), amount);
  449. }
  450.  
  451. /**
  452. * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
  453. *
  454. * This internal function is equivalent to `approve`, and can be used to
  455. * e.g. set automatic allowances for certain subsystems, etc.
  456. *
  457. * Emits an {Approval} event.
  458. *
  459. * Requirements:
  460. *
  461. * - `owner` cannot be the zero address.
  462. * - `spender` cannot be the zero address.
  463. */
  464. function _approve(address owner, address spender, uint256 amount) internal virtual {
  465. require(owner != address(0), "ERC20: approve from the zero address");
  466. require(spender != address(0), "ERC20: approve to the zero address");
  467.  
  468. _allowances[owner][spender] = amount;
  469. emit Approval(owner, spender, amount);
  470. }
  471.  
  472. /**
  473. * @dev Hook that is called before any transfer of tokens. This includes
  474. * minting and burning.
  475. *
  476. * Calling conditions:
  477. *
  478. * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
  479. * will be to transferred to `to`.
  480. * - when `from` is zero, `amount` tokens will be minted for `to`.
  481. * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
  482. * - `from` and `to` are never both zero.
  483. *
  484. * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
  485. */
  486. function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
  487. uint256[45] private __gap;
  488. }
  489.  
  490. // ----------------------------------------------------------------------------
  491. // Karma Contract
  492. // ----------------------------------------------------------------------------
  493.  
  494. contract KarmaV3 is Initializable, ERC20Upgradeable
  495. {
  496. function initialize(string memory name, string memory symbol, uint256 initialSupply) public virtual initializer {
  497. __ERC20_init(name, symbol);
  498. _mint(_msgSender(), initialSupply);
  499. }
  500.  
  501. function isToken() public pure returns (bool)
  502. {
  503. return true;
  504. }
  505.  
  506. function getAddress() public view returns (address)
  507. {
  508. return address(this);
  509. }
  510.  
  511. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement