|
| 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 KyberMigrationAdapter |
| 23 | + * @author Set Protocol |
| 24 | + * |
| 25 | + * Wrap adapter for one time token migration that returns data for wrapping KNC Legacy into KNC. |
| 26 | + * Note: KNC can not be unwrapped into KNC Legacy, because migration can not be reversed. |
| 27 | + */ |
| 28 | +contract KyberMigrationWrapAdapter { |
| 29 | + |
| 30 | + /* ============ State Variables ============ */ |
| 31 | + |
| 32 | + address public immutable kncLegacyToken; |
| 33 | + address public immutable kncToken; |
| 34 | + |
| 35 | + /* ============ Constructor ============ */ |
| 36 | + |
| 37 | + /** |
| 38 | + * Set state variables |
| 39 | + * |
| 40 | + * @param _kncLegacyToken Address of KNC Legacy token |
| 41 | + * @param _kncToken Address of KNC token |
| 42 | + */ |
| 43 | + constructor( |
| 44 | + address _kncLegacyToken, |
| 45 | + address _kncToken |
| 46 | + ) |
| 47 | + public |
| 48 | + { |
| 49 | + kncLegacyToken = _kncLegacyToken; |
| 50 | + kncToken = _kncToken; |
| 51 | + } |
| 52 | + |
| 53 | + /* ============ External Getter Functions ============ */ |
| 54 | + |
| 55 | + /** |
| 56 | + * Generates the calldata to migrate KNC Legacy to KNC. |
| 57 | + * |
| 58 | + * @param _underlyingToken Address of the component to be wrapped |
| 59 | + * @param _wrappedToken Address of the wrapped component |
| 60 | + * @param _underlyingUnits Total quantity of underlying units to wrap |
| 61 | + * |
| 62 | + * @return address Target contract address |
| 63 | + * @return uint256 Total quantity of underlying units (if underlying is ETH) |
| 64 | + * @return bytes Wrap calldata |
| 65 | + */ |
| 66 | + function getWrapCallData( |
| 67 | + address _underlyingToken, |
| 68 | + address _wrappedToken, |
| 69 | + uint256 _underlyingUnits |
| 70 | + ) |
| 71 | + external |
| 72 | + view |
| 73 | + returns (address, uint256, bytes memory) |
| 74 | + { |
| 75 | + require(_underlyingToken == kncLegacyToken, "Must be KNC Legacy token"); |
| 76 | + require(_wrappedToken == kncToken, "Must be KNC token"); |
| 77 | + |
| 78 | + // mintWithOldKnc(uint256 amount) |
| 79 | + bytes memory callData = abi.encodeWithSignature("mintWithOldKnc(uint256)", _underlyingUnits); |
| 80 | + |
| 81 | + return (kncToken, 0, callData); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * This function will revert, since migration cannot be reversed. |
| 86 | + */ |
| 87 | + function getUnwrapCallData( |
| 88 | + address /* _underlyingToken */, |
| 89 | + address /* _wrappedToken */, |
| 90 | + uint256 /* _wrappedTokenUnits */ |
| 91 | + ) |
| 92 | + external |
| 93 | + pure |
| 94 | + returns (address, uint256, bytes memory) |
| 95 | + { |
| 96 | + revert("KNC migration cannot be reversed"); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Returns the address to approve source tokens for wrapping. |
| 101 | + * |
| 102 | + * @return address Address of the contract to approve tokens to |
| 103 | + */ |
| 104 | + function getSpenderAddress(address /* _underlyingToken */, address /* _wrappedToken */) external view returns(address) { |
| 105 | + return kncToken; |
| 106 | + } |
| 107 | +} |
0 commit comments