-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLPTokenMaster.sol
94 lines (73 loc) · 3.17 KB
/
LPTokenMaster.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
// SPDX-License-Identifier: UNLICENSED
// Copyright (c) 2021 0xdev0 - All rights reserved
// https://twitter.com/0xdev0
pragma solidity 0.8.6;
import './interfaces/IERC20.sol';
import './interfaces/ILPTokenMaster.sol';
import './interfaces/ILendingPair.sol';
import './interfaces/ILendingController.sol';
import './external/Ownable.sol';
contract LPTokenMaster is ILPTokenMaster, Ownable {
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
mapping (address => mapping (address => uint)) public override allowance;
bool private initialized;
address public override underlying;
address public lendingController;
string public name;
string public symbol;
uint8 public constant override decimals = 18;
modifier onlyOperator() {
require(msg.sender == ILendingController(lendingController).owner(), "LPToken: caller is not an operator");
_;
}
function initialize(address _underlying, address _lendingController) external override {
require(initialized != true, "LPToken: already intialized");
owner = msg.sender;
underlying = _underlying;
lendingController = _lendingController;
name = "WILD-LP";
symbol = "WILD-LP";
initialized = true;
}
// LP tokens can be created by anyone. Some tokens are not suitable for automated naming.
// This function allow the operator to set a unique name for each LP token.
function updateName(string memory _name, string memory _symbol) external onlyOperator {
name = _name;
symbol = _symbol;
}
function transfer(address _recipient, uint _amount) external override returns(bool) {
_transfer(msg.sender, _recipient, _amount);
return true;
}
function approve(address _spender, uint _amount) external override returns(bool) {
_approve(msg.sender, _spender, _amount);
return true;
}
function transferFrom(address _sender, address _recipient, uint _amount) external override returns(bool) {
_approve(_sender, msg.sender, allowance[_sender][msg.sender] - _amount);
_transfer(_sender, _recipient, _amount);
return true;
}
function lendingPair() external view override returns(address) {
return owner;
}
function balanceOf(address _account) external view override returns(uint) {
return ILendingPair(owner).supplySharesOf(underlying, _account);
}
function totalSupply() external view override returns(uint) {
return ILendingPair(owner).totalSupplyShares(underlying);
}
function _transfer(address _sender, address _recipient, uint _amount) internal {
require(_sender != address(0), "ERC20: transfer from the zero address");
require(_recipient != address(0), "ERC20: transfer to the zero address");
ILendingPair(owner).transferLp(underlying, _sender, _recipient, _amount);
emit Transfer(_sender, _recipient, _amount);
}
function _approve(address _owner, address _spender, uint _amount) internal {
require(_owner != address(0), "ERC20: approve from the zero address");
require(_spender != address(0), "ERC20: approve to the zero address");
allowance[_owner][_spender] = _amount;
emit Approval(_owner, _spender, _amount);
}
}