forked from nerve-finance/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLPToken.sol
64 lines (57 loc) · 2.14 KB
/
LPToken.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
// SPDX-License-Identifier: MIT
pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "./interfaces/ISwap.sol";
/**
* @title Liquidity Provider Token
* @notice This token is an ERC20 detailed token with added capability to be minted by the owner.
* It is used to represent user's shares when providing liquidity to swap contracts.
*/
contract LPToken is ERC20Burnable, Ownable {
using SafeMath for uint256;
// Address of the swap contract that owns this LP token. When a user adds liquidity to the swap contract,
// they receive a proportionate amount of this LPToken.
ISwap public immutable swap;
/**
* @notice Deploys LPToken contract with given name, symbol, and decimals
* @dev the caller of this constructor will become the owner of this contract
* @param name_ name of this token
* @param symbol_ symbol of this token
* @param decimals_ number of decimals this token will be based on
*/
constructor(
string memory name_,
string memory symbol_,
uint8 decimals_
) public ERC20(name_, symbol_) {
_setupDecimals(decimals_);
swap = ISwap(_msgSender());
}
/**
* @notice Mints the given amount of LPToken to the recipient.
* @dev only owner can call this mint function
* @param recipient address of account to receive the tokens
* @param amount amount of tokens to mint
*/
function mint(
address recipient,
uint256 amount
) external onlyOwner {
require(amount != 0, "amount == 0");
_mint(recipient, amount);
}
/**
* @dev Overrides ERC20._beforeTokenTransfer() which get called on every transfers including
* minting and burning. This ensures that swap.updateUserWithdrawFees are called everytime.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal override(ERC20) {
super._beforeTokenTransfer(from, to, amount);
swap.updateUserWithdrawFee(to, amount);
}
}