1+ /*
2+ Copyright 2021 Set Labs Inc.
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+ /**
22+ * @title SushiBarWrapAdapter
23+ * @author Yam Finance, Set Protocol
24+ *
25+ * Wrap adapter for depositing/withdrawing Sushi to/from SushiBar (xSushi)
26+ */
27+ contract SushiBarWrapAdapter {
28+
29+ /* ============ State Variables ============ */
30+
31+ // Address of SUSHI token
32+ address public immutable sushiToken;
33+
34+ // Address of xSUSHI token
35+ address public immutable xSushiToken;
36+
37+ /* ============ Constructor ============ */
38+
39+ /**
40+ * Set state variables
41+ *
42+ * @param _sushiToken Address of SUSHI token
43+ * @param _xSushiToken Address of xSUSHI token
44+ */
45+ constructor (address _sushiToken , address _xSushiToken ) public {
46+ sushiToken = _sushiToken;
47+ xSushiToken = _xSushiToken;
48+ }
49+
50+ /* ============ External Functions ============ */
51+
52+ /**
53+ * Generates the calldata to wrap Sushi into xSushi.
54+ *
55+ * @param _underlyingToken Address of SUSHI token
56+ * @param _wrappedToken Address of xSUSHI token
57+ * @param _underlyingUnits Total quantity of SUSHI units to wrap
58+ *
59+ * @return address Target contract address
60+ * @return uint256 Unused, always 0
61+ * @return bytes Wrap calldata
62+ */
63+ function getWrapCallData (
64+ address _underlyingToken ,
65+ address _wrappedToken ,
66+ uint256 _underlyingUnits
67+ )
68+ external
69+ view
70+ returns (address , uint256 , bytes memory )
71+ {
72+ _validateWrapInputs (_underlyingToken, _wrappedToken);
73+
74+ // Signature for wrapping in xSUSHI is enter(uint256 _amount)
75+ bytes memory callData = abi.encodeWithSignature ("enter(uint256) " , _underlyingUnits);
76+
77+ return (xSushiToken, 0 , callData);
78+ }
79+
80+ /**
81+ * Generates the calldata to unwrap xSushi to Sushi
82+ *
83+ * @param _underlyingToken Address of SUSHI token
84+ * @param _wrappedToken Address of xSUSHI token
85+ * @param _wrappedTokenUnits Total quantity of xSUSHI units to unwrap
86+ *
87+ * @return address Target contract address
88+ * @return uint256 Unused, always 0
89+ * @return bytes Unwrap calldata
90+ */
91+ function getUnwrapCallData (
92+ address _underlyingToken ,
93+ address _wrappedToken ,
94+ uint256 _wrappedTokenUnits
95+ )
96+ external
97+ view
98+ returns (address , uint256 , bytes memory )
99+ {
100+ _validateWrapInputs (_underlyingToken, _wrappedToken);
101+
102+ // Signature for unwrapping in xSUSHI is leave(uint256 _amount)
103+ bytes memory callData = abi.encodeWithSignature ("leave(uint256) " , _wrappedTokenUnits);
104+
105+ return (xSushiToken, 0 , callData);
106+
107+ }
108+
109+ /**
110+ * Returns the address to approve source tokens for wrapping.
111+ *
112+ * @return address Address of the contract to approve tokens to. This is the SushiBar (xSushi) contract.
113+ */
114+ function getSpenderAddress (address /*_underlyingToken*/ , address /*_wrappedToken*/ ) external view returns (address ) {
115+ return address (xSushiToken);
116+ }
117+
118+ /* ============ Internal Functions ============ */
119+
120+ /**
121+ * Validate inputs prior to getting wrap and unwrap calldata.
122+ *
123+ * @param _underlyingToken Address of SUSHI token
124+ * @param _wrappedToken Address of xSUSHI token
125+ */
126+ function _validateWrapInputs (address _underlyingToken , address _wrappedToken ) internal view {
127+ require (_underlyingToken == sushiToken, "Underlying token must be SUSHI " );
128+ require (_wrappedToken == xSushiToken, "Wrapped token must be xSUSHI " );
129+ }
130+ }
0 commit comments