-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLiquidityWrapper.sol
94 lines (83 loc) · 2.57 KB
/
LiquidityWrapper.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: GPL-3.0-only
pragma solidity 0.8.6;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@primitivefi/rmm-manager/contracts/interfaces/IERC1155Permit.sol";
import "@primitivefi/rmm-manager/contracts/base/Multicall.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import "./ILiquidityWrapper.sol";
/// @title Liquidity Wrapper contract
/// @notice Allows users to wrap specific PrimitiveManager liquidity pool tokens
/// (ERC1155) into ERC20 tokens
/// @author Primitive
contract LiquidityWrapper is
ILiquidityWrapper,
ERC20,
ERC1155Holder,
Multicall
{
/// STORAGE VARIABLES ///
/// @inheritdoc ILiquidityWrapper
address public override manager;
/// @inheritdoc ILiquidityWrapper
uint256 public override poolId;
/// @dev Null variable to pass to `safeTransferFrom`
bytes private empty;
/// EFFECT FUNCTIONS ///
/// @param name_ Name of the wrapped token
/// @param symbol_ Symbol of the wrapped token
/// @param manager_ Address of the PrimitiveManager associated with this wrapper
/// @param poolId_ Id of the PrimitiveManager liquidity pool token associated with this wrapper
constructor(
string memory name_,
string memory symbol_,
address manager_,
uint256 poolId_
) ERC20(name_, symbol_) {
manager = manager_;
poolId = poolId_;
}
/// @inheritdoc ILiquidityWrapper
function selfPermit(
address owner,
bool approved,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external override {
IERC1155Permit(manager).permit(
owner,
address(this),
approved,
deadline,
v,
r,
s
);
}
/// @inheritdoc ILiquidityWrapper
function wrap(address to, uint256 amount) external override {
IERC1155(manager).safeTransferFrom(
msg.sender,
address(this),
poolId,
amount,
empty
);
_mint(to, amount);
emit Wrap(msg.sender, to, amount);
}
/// @inheritdoc ILiquidityWrapper
function unwrap(address to, uint256 amount) external override {
_burn(msg.sender, amount);
IERC1155(manager).safeTransferFrom(
address(this),
to,
poolId,
amount,
empty
);
emit Unwrap(msg.sender, to, amount);
}
}