-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSynthERC20.sol
97 lines (84 loc) · 2.92 KB
/
SynthERC20.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) Eywa.Fi, 2021-2023 - all rights reserved
pragma solidity 0.8.17;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "./interfaces/ISynth.sol";
/**
* @dev Synthesis must be owner of this contract.
*/
contract SynthERC20 is ISynthERC20, Ownable, ERC20Permit {
/// @dev original token address
address public originalToken;
/// @dev original token chain id
uint64 public chainIdFrom;
/// @dev original chain symbol
string public chainSymbolFrom;
/// @dev synth type
uint8 public synthType;
/// @dev cap (max possible supply)
uint256 public cap;
/// @dev synth token address for backward compatibility with ISynthAdapter (which may has backed third-party synth)
address public synthToken;
/// @dev synth decimals
uint8 private _decimals;
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_,
address originalToken_,
uint64 chainIdFrom_,
string memory chainSymbolFrom_,
SynthType synthType_
) ERC20Permit("EYWA") ERC20(name_, symbol_) {
originalToken = originalToken_;
chainIdFrom = chainIdFrom_;
chainSymbolFrom = chainSymbolFrom_;
_decimals = decimals_;
synthType = uint8(synthType_);
cap = 2 ** 256 - 1;
synthToken = address(this);
}
/**
* @dev Returns the cap on the token's total supply.
*/
function setCap(uint256 cap_) external onlyOwner {
require(ERC20.totalSupply() <= cap_, "SynthERC20: cap exceeded");
cap = cap_;
emit CapSet(cap);
}
function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}
function mintWithAllowanceIncrease(
address account,
address spender,
uint256 amount
) external onlyOwner {
_mint(account, amount);
_approve(account, spender, allowance(account, spender) + amount);
}
function burn(address account, uint256 amount) external onlyOwner {
_burn(account, amount);
}
function burnWithAllowanceDecrease(
address account,
address spender,
uint256 amount
) external onlyOwner {
uint256 currentAllowance = allowance(account, spender);
require(currentAllowance >= amount, "ERC20: decreased allowance below zero");
_approve(account, spender, currentAllowance - amount);
_burn(account, amount);
}
function decimals() public view override (ISynthAdapter, ERC20) returns (uint8) {
return _decimals;
}
/**
* @dev See {ERC20-_mint}.
*/
function _mint(address account, uint256 amount) internal virtual override {
require(ERC20.totalSupply() + amount <= cap, "ERC20Capped: cap exceeded");
super._mint(account, amount);
}
}