-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDifferentDecimalsAdapter.sol
63 lines (53 loc) · 2.1 KB
/
DifferentDecimalsAdapter.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
// 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/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./interfaces/ISynth.sol";
abstract contract IERC20Extented is IERC20 {
function decimals() public virtual view returns (uint8);
}
contract DifferentDecimalsAdapter is ISynthAdapter, Ownable {
address public originalToken;
uint64 public chainIdFrom;
string public chainSymbolFrom;
uint8 public synthType;
uint256 public cap;
address public synthToken;
uint8 public decimals; // decimals of originalToken
constructor(
address originalToken_,
address synthToken_,
uint64 chainIdFrom_,
string memory chainSymbolFrom_,
uint8 decimals_
) {
originalToken = originalToken_;
synthToken = synthToken_;
chainIdFrom = chainIdFrom_;
chainSymbolFrom = chainSymbolFrom_;
synthType = uint8(SynthType.ThirdPartySynth);
decimals = decimals_;
cap = 2 ** 256 - 1;
}
function setCap(uint256 cap_) external onlyOwner {
cap = cap_;
}
function mint(address account, uint256 amount) external onlyOwner {
uint256 balance = ISynthERC20(synthToken).balanceOf(address(this));
if (decimals > IERC20Extented(synthToken).decimals()) {
amount /= 10 ** (decimals - IERC20Extented(synthToken).decimals());
} else {
amount *= 10 ** (IERC20Extented(synthToken).decimals() - decimals);
}
require(balance >= amount, "DifferentDecimalsAdapter: wrong amount");
SafeERC20.safeTransfer(ISynthERC20(synthToken), account, amount);
}
function burn(address account, uint256 amount) external onlyOwner {
SafeERC20.safeTransferFrom(ISynthERC20(synthToken), account, address(this), amount);
}
function withdraw(uint256 amount) external onlyOwner {
SafeERC20.safeTransfer(ISynthERC20(synthToken), owner(), amount);
}
}