forked from LayerZero-Labs/endpoint-v1-solidity-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OFTV2.sol
72 lines (62 loc) · 2.2 KB
/
OFTV2.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./BaseOFTV2.sol";
contract OFTV2 is BaseOFTV2, ERC20 {
uint internal immutable ld2sdRate;
constructor(
string memory _name,
string memory _symbol,
uint8 _sharedDecimals,
address _lzEndpoint
) ERC20(_name, _symbol) BaseOFTV2(_sharedDecimals, _lzEndpoint) {
uint8 decimals = decimals();
require(_sharedDecimals <= decimals, "OFT: sharedDecimals must be <= decimals");
ld2sdRate = 10**(decimals - _sharedDecimals);
}
/************************************************************************
* public functions
************************************************************************/
function circulatingSupply() public view virtual override returns (uint) {
return totalSupply();
}
function token() public view virtual override returns (address) {
return address(this);
}
/************************************************************************
* internal functions
************************************************************************/
function _debitFrom(
address _from,
uint16,
bytes32,
uint _amount
) internal virtual override returns (uint) {
address spender = _msgSender();
if (_from != spender) _spendAllowance(_from, spender, _amount);
_burn(_from, _amount);
return _amount;
}
function _creditTo(
uint16,
address _toAddress,
uint _amount
) internal virtual override returns (uint) {
_mint(_toAddress, _amount);
return _amount;
}
function _transferFrom(
address _from,
address _to,
uint _amount
) internal virtual override returns (uint) {
address spender = _msgSender();
// if transfer from this contract, no need to check allowance
if (_from != address(this) && _from != spender) _spendAllowance(_from, spender, _amount);
_transfer(_from, _to, _amount);
return _amount;
}
function _ld2sdRate() internal view virtual override returns (uint) {
return ld2sdRate;
}
}