1
+ /*
2
+ Copyright 2021 Index Coop
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ SPDX-License-Identifier: Apache License, Version 2.0
17
+ */
18
+
19
+ pragma solidity 0.6.10 ;
20
+
21
+ import { BaseExtension } from "../lib/BaseExtension.sol " ;
22
+ import { IBaseManager } from "../interfaces/IBaseManager.sol " ;
23
+ import { ISetToken } from "../interfaces/ISetToken.sol " ;
24
+ import { IWrapModule } from "../interfaces/IWrapModule.sol " ;
25
+
26
+ /**
27
+ * @title WrapExtension
28
+ * @author Index Coop
29
+ *
30
+ * Manager extension for interacting with WrapModule
31
+ */
32
+ contract WrapExtension is BaseExtension {
33
+
34
+ /* ========== State Variables ========= */
35
+
36
+ // Address of Set Token
37
+ ISetToken public immutable setToken;
38
+
39
+ // Address of WrapModule
40
+ IWrapModule public immutable wrapModule;
41
+
42
+ /* ============ Constructor ============ */
43
+
44
+ /**
45
+ * Sets state variables
46
+ *
47
+ * @param _manager Manager contract
48
+ * @param _wrapModule Set Protocol WrapModule
49
+ */
50
+ constructor (IBaseManager _manager , IWrapModule _wrapModule ) public BaseExtension (_manager) {
51
+ manager = _manager;
52
+ setToken = manager.setToken ();
53
+ wrapModule = _wrapModule;
54
+ }
55
+
56
+ /* ========== External Functions ========== */
57
+
58
+ /**
59
+ * OPERATOR ONLY: Initializes the Set Token on the Wrap Module.
60
+ */
61
+ function initialize () external onlyOperator {
62
+ bytes memory data = abi.encodeWithSelector (wrapModule.initialize.selector , setToken);
63
+ invokeManager (address (wrapModule), data);
64
+ }
65
+
66
+ /**
67
+ * OPERATOR ONLY: Calls wrap on the WrapModule.
68
+ *
69
+ * @param _underlyingToken address of underlying token
70
+ * @param _wrappedToken address of wrapped token
71
+ * @param _underlyingUnits units of underlying to wrap
72
+ * @param _integrationName Set Protocol integreation name for the wrap adapter
73
+ */
74
+ function wrap (
75
+ address _underlyingToken ,
76
+ address _wrappedToken ,
77
+ uint256 _underlyingUnits ,
78
+ string calldata _integrationName
79
+ )
80
+ external
81
+ onlyOperator
82
+ {
83
+ bytes memory data = abi.encodeWithSelector (
84
+ wrapModule.wrap.selector ,
85
+ setToken,
86
+ _underlyingToken,
87
+ _wrappedToken,
88
+ _underlyingUnits,
89
+ _integrationName
90
+ );
91
+ invokeManager (address (wrapModule), data);
92
+ }
93
+
94
+ /**
95
+ * OPERATOR ONLY: Calls wrapWithEther on the WrapModule.
96
+ *
97
+ * @param _wrappedToken address of wrapped token
98
+ * @param _underlyingUnits units of weth to wrap
99
+ * @param _integrationName Set Protocol integreation name for the wrap adapter
100
+ */
101
+ function wrapWithEther (
102
+ address _wrappedToken ,
103
+ uint256 _underlyingUnits ,
104
+ string calldata _integrationName
105
+ )
106
+ external
107
+ onlyOperator
108
+ {
109
+ bytes memory data = abi.encodeWithSelector (
110
+ wrapModule.wrapWithEther.selector ,
111
+ setToken,
112
+ _wrappedToken,
113
+ _underlyingUnits,
114
+ _integrationName
115
+ );
116
+ invokeManager (address (wrapModule), data);
117
+ }
118
+
119
+ /**
120
+ * OPERATOR ONLY: Calls unwrap on the WrapModule.
121
+ *
122
+ * @param _underlyingToken address of underlying token
123
+ * @param _wrappedToken address of wrapped token
124
+ * @param _wrappedUnits units of wrapped token to unwrap
125
+ * @param _integrationName Set Protocol integreation name for the wrap adapter
126
+ */
127
+ function unwrap (
128
+ address _underlyingToken ,
129
+ address _wrappedToken ,
130
+ uint256 _wrappedUnits ,
131
+ string calldata _integrationName
132
+ )
133
+ external
134
+ onlyOperator
135
+ {
136
+ bytes memory data = abi.encodeWithSelector (
137
+ wrapModule.unwrap.selector ,
138
+ setToken,
139
+ _underlyingToken,
140
+ _wrappedToken,
141
+ _wrappedUnits,
142
+ _integrationName
143
+ );
144
+ invokeManager (address (wrapModule), data);
145
+ }
146
+
147
+ /**
148
+ * OPERATOR ONLY: Calls unwrapWithEther on the WrapModule.
149
+ *
150
+ * @param _wrappedToken address of wrapped token
151
+ * @param _wrappedUnits units of wrapped token to unwrap
152
+ * @param _integrationName Set Protocol integreation name for the wrap adapter
153
+ */
154
+ function unwrapWithEther (
155
+ address _wrappedToken ,
156
+ uint256 _wrappedUnits ,
157
+ string calldata _integrationName
158
+ )
159
+ external
160
+ onlyOperator
161
+ {
162
+ bytes memory data = abi.encodeWithSelector (
163
+ wrapModule.unwrapWithEther.selector ,
164
+ setToken,
165
+ _wrappedToken,
166
+ _wrappedUnits,
167
+ _integrationName
168
+ );
169
+ invokeManager (address (wrapModule), data);
170
+ }
171
+ }
0 commit comments