1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.22;
3
4import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
5import { OFTCore } from "./OFTCore.sol";
6
7contract OFT is OFTCore, ERC20 {
8 constructor(
9 string memory _name,
10 string memory _symbol,
11 address _lzEndpoint,
12 address _owner
13 ) ERC20(_name, _symbol) OFTCore(decimals(), _lzEndpoint, _owner) {}
14
15 // @dev major indicates they shared a compatible msg payload format and CAN communicate between one another
16 // @dev minor indicates a varying version, eg. OFTAdapter vs. OFT
17 function oftVersion() external pure returns (uint64 major, uint64 minor) {
18 return (1, 1);
19 }
20
21 function token() external view virtual returns (address) {
22 return address(this);
23 }
24
25 // @dev burn the tokens from the users specified balance
26 function _debitSender(
27 uint256 _amountToSendLD,
28 uint256 _minAmountToReceiveLD,
29 uint32 _dstEid
30 ) internal virtual override returns (uint256 amountDebitedLD, uint256 amountToCreditLD) {
31 (amountDebitedLD, amountToCreditLD) = _debitView(_amountToSendLD, _minAmountToReceiveLD, _dstEid);
32
33 _burn(msg.sender, amountDebitedLD);
34 }
35
36 // @dev burn the tokens that someone has sent into this contract in a push method
37 // @dev allows anyone to send tokens that have been sent to this contract
38 // @dev similar to how you can push tokens to the endpoint to pay the msg fee, vs the endpoint needing approval
39 function _debitThis(
40 uint256 _minAmountToReceiveLD,
41 uint32 _dstEid
42 ) internal virtual override returns (uint256 amountDebitedLD, uint256 amountToCreditLD) {
43 (amountDebitedLD, amountToCreditLD) = _debitView(balanceOf(address(this)), _minAmountToReceiveLD, _dstEid);
44
45 _burn(address(this), amountDebitedLD);
46 }
47
48 function _credit(
49 address _to,
50 uint256 _amountToCreditLD,
51 uint32 /*_srcEid*/
52 ) internal virtual override returns (uint256 amountReceivedLD) {
53 _mint(_to, _amountToCreditLD);
54 return _amountToCreditLD;
55 }
56}
57